Files
strata/sycl/probe/doorbell_store.cpp
duncanmcqueen 9c790e3dde sycl: publish the doorbell with the uncached write hint
The decode handshake publishes a ring sequence the host polls while the
window graph still runs. On an Arc (xe) a system-scope atomic store, even
with a release fence, is served from the GPU's cache and reaches the host
only when the kernel ends, so a host polling mid-window never sees the
ring. That is why the verify window had to wait for the whole graph
(STRATA_VERIFY_NO_HOST) and every expert had to be device-resident or in
the pinned mirror.

STRATA_DOORBELL_ATOMIC_LOAD already fixes the load side the same way; this
does the store side with the Intel uncached L1+L3 write hint. The release
fence stays (ordering only: a later payload store follows the ring).

Measured with sycl/probe/doorbell_store.cpp on an Arc A770: the host sees
the store at 230 ms with the kernel running to 2030 ms; with the old atomic
store it sees it at 2038 ms, exactly when the kernel ends (exit code 3).
-DSTRATA_DOORBELL_ATOMIC_STORE restores the atomic store.

This is a prerequisite for running with the CPU expert pool on xe (the
per-layer handshake); it does not by itself fix longer-prompt prefill.
2026-10-09 03:06:31 +02:00

44 lines
2.3 KiB
C++

// doorbell_store: does the host see a device's store to host USM while the kernel is still running? This is the
// ring publish of Strata's decode handshake (the GPU rings a sequence number the host polls, and the host answers a
// flag the GPU spins on). A `volatile`/atomic store is served from the GPU's cache on an Arc (xe) and reaches the
// host only when the kernel ends; the uncached L1+L3 write hint (strata::sys_store, sycl_doorbell.hpp) reaches memory
// at once. Build twice and compare:
// icpx -fsycl -I sycl/include sycl/probe/doorbell_store.cpp -o /tmp/db # uncached write (the fix)
// icpx -fsycl -DSTRATA_DOORBELL_ATOMIC_STORE -I sycl/include ... -o /tmp/db_atomic # old atomic store
// On an Arc A770 (xe) the first prints "SAW ... at ~0.2 s" with the kernel running to ~2 s; the second prints
// "NEVER SAW" and the value appears only at the kernel's end. Exit 0 when the store was seen mid-kernel.
#include <sycl/sycl.hpp>
#include <cstdio>
#include <chrono>
#include "strata/sycl_doorbell.hpp"
int main() {
sycl::queue q{sycl::gpu_selector_v};
uint32_t* flag = (uint32_t*) sycl::malloc_host(sizeof(uint32_t), q);
*flag = 0;
const auto t0 = std::chrono::steady_clock::now();
q.submit([&](sycl::handler& h) {
h.single_task([=]() {
for (volatile long i = 0; i < 1000000; i++) {} // ~0.2 s before the publish
strata::sys_store(flag, 12345u);
for (volatile long i = 0; i < 10000000; i++) {} // ~2 s more running after the publish
});
});
uint32_t v = 0;
double seen_ms = -1.0;
while (std::chrono::steady_clock::now() - t0 < std::chrono::seconds(6)) {
v = *flag;
if (v == 12345u) { seen_ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count(); break; }
}
q.wait();
const double end_ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count();
#ifdef STRATA_DOORBELL_ATOMIC_STORE
const char* label = "ATOMIC_STORE ";
#else
const char* label = "UNCACHED_WRITE";
#endif
std::printf("%s: host %s flag=%u at %.1f ms; kernel ended at %.1f ms\n", label,
seen_ms >= 0 ? "SAW" : "NEVER SAW", v, seen_ms, end_ms);
return (seen_ms >= 0 && seen_ms < end_ms - 100.0) ? 0 : 3; // seen well before the kernel ended
}