Files
Strata/engine/sycl/probe/payload_pairs.cpp
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

62 lines
3.3 KiB
C++

// Test paired mapped transfers, odd tails, unaligned scalar fallback, and
// the checksum contracts of all three publish variants over repeated rings.
#include <sycl/sycl.hpp>
#include <dpct/dpct.hpp>
#include "strata/sycl_queue.hpp"
#include "strata/kernels/elementwise.hpp"
#include <cstdio>
#include <cstring>
#include <vector>
int main() {
auto& q = *strata::q_of(nullptr);
using namespace strata::kernels;
constexpr int capacity = 2560, k = 10, experts = 64;
auto* hx = (float*)strata::host_malloc_polled((capacity + 4)*sizeof(float), q);
auto* hi = (int32_t*)strata::host_malloc_polled(k*sizeof(int32_t), q);
auto* hw = (float*)strata::host_malloc_polled(k*sizeof(float), q);
auto* seq = (uint32_t*)strata::host_malloc_polled(64, q);
auto* dx = sycl::malloc_device<float>(capacity, q);
auto* di = sycl::malloc_device<int32_t>(k, q);
auto* dw = sycl::malloc_device<float>(k, q);
auto* dr = sycl::malloc_device<int32_t>(experts, q);
std::vector<float> x(capacity), weights(k), copied(capacity);
std::vector<int32_t> ids(k);
for (int j = 0; j < capacity; ++j) x[j] = (j % 123 - 61)*0.25f;
for (int j = 0; j < k; ++j) { ids[j] = j*3; weights[j] = (j + 1)*0.03125f; }
q.memcpy(dx, x.data(), x.size()*sizeof(float));
q.memcpy(di, ids.data(), k*sizeof(int32_t));
q.memcpy(dw, weights.data(), k*sizeof(float));
q.memset(dr, 0, experts*sizeof(int32_t));
q.wait_and_throw();
int failed = 0;
for (int n : {1, 3, 17, 2559, 2560})
for (int offset : {0, 1})
for (int variant = 0; variant < 3; ++variant) {
std::memset(seq, 0, 64);
for (uint32_t ring = 1; ring <= 12; ++ring) {
std::memset(hx, 0x7f, (capacity + 4)*sizeof(float));
std::memset(hi, 0, k*sizeof(int32_t));
std::memset(hw, 0, k*sizeof(float));
if (variant == 0) doorbell_publish(dx, di, dw, n, k, hx+offset, hi, hw, seq, &q);
else if (variant == 1) doorbell_publish_res(dx, di, dr, experts, n, k, hx+offset, hi, seq, &q);
else doorbell_publish_value(dx, di, dw, n, k, hx+offset, hi, hw, seq, ring, &q);
q.wait_and_throw();
bool ok = seq[0] == ring && !std::memcmp(hx+offset, x.data(), n*sizeof(float)) &&
!std::memcmp(hi, ids.data(), k*sizeof(int32_t)) &&
doorbell_payload_ready(seq, hx+offset, n, hi, hw, k, ring);
if (variant != 1) ok = ok && !std::memcmp(hw, weights.data(), k*sizeof(float));
if (!ok) { ++failed; std::printf("FAIL n=%d offset=%d variant=%d ring=%u\n", n, offset, variant, ring); }
}
}
std::memcpy(hx, x.data(), x.size()*sizeof(float));
copy_from_mapped(dx, hx, capacity, &q);
q.memcpy(copied.data(), dx, capacity*sizeof(float)).wait();
if (std::memcmp(copied.data(), x.data(), capacity*sizeof(float))) ++failed;
for (void* p : {static_cast<void*>(hx), static_cast<void*>(hi), static_cast<void*>(hw), static_cast<void*>(seq)})
strata::host_free_polled(p, q);
for (void* p : {static_cast<void*>(dx), static_cast<void*>(di), static_cast<void*>(dw), static_cast<void*>(dr)}) sycl::free(p, q);
std::printf("paired payload and mapped read: %d failures\n", failed);
return failed != 0;
}