Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

sycl: publish the doorbell with the uncached write hint

duncanmcqueen9c790e3dde83
diff --git a/sycl/include/strata/sycl_doorbell.hpp b/sycl/include/strata/sycl_doorbell.hpp
index 3ad9f1c89..6522d0ed7 100644
--- a/sycl/include/strata/sycl_doorbell.hpp
+++ b/sycl/include/strata/sycl_doorbell.hpp
@@ -39,10 +39,30 @@ inline uint32_t sys_load(const volatile uint32_t* p) {
return sys_atomic_u32(*const_cast<uint32_t*>(p)).load();
}
#endif
+// The store side of the handshake (device -> host) needs the same hint. A system-scope atomic store, even followed by
+// a release fence, is served from the GPU's cache on an Arc (xe) and reaches the host only when the kernel ends
+// (measured on an A770: 482 ms into a 482 ms kernel), so a host that polls the ring mid-window never sees it; that is
+// why the decode window had to wait for the whole graph (STRATA_VERIFY_NO_HOST) and every expert had to be
+// device-resident. The uncached L1+L3 write hint reaches memory at once (44 ms, the launch latency).
+// -DSTRATA_DOORBELL_ATOMIC_STORE restores the atomic store.
+#ifndef STRATA_DOORBELL_ATOMIC_STORE
+using doorbell_uncached_write = decltype(sycl::ext::oneapi::experimental::properties(
+ sycl::ext::intel::experimental::write_hint<sycl::ext::intel::experimental::cache_control<
+ sycl::ext::intel::experimental::cache_mode::uncached,
+ sycl::ext::oneapi::experimental::cache_level::L1, sycl::ext::oneapi::experimental::cache_level::L3>>));
+inline void sys_store(volatile uint32_t* p, uint32_t v) {
+ sycl::ext::oneapi::experimental::annotated_ptr<uint32_t, doorbell_uncached_write> u(const_cast<uint32_t*>(p));
+ u[0] = v;
+ // Ordering, not visibility: the value is already in memory. The release fence keeps a later payload store (the
+ // experts' ids the host reads after the ring) after the ring, the same contract the atomic store had.
+ sycl::atomic_fence(sycl::memory_order::release, sycl::memory_scope::system);
+}
+#else
inline void sys_store(volatile uint32_t* p, uint32_t v) {
sys_atomic_u32(*const_cast<uint32_t*>(p)).store(v);
sycl::atomic_fence(sycl::memory_order::release, sycl::memory_scope::system);
}
+#endif
// Every device spin is bounded. An unbounded spin that never sees its flag is not a hang of one process: the
// xe driver times the queue out, resets the GT node by node (a window graph has 2,366 of them), and the card
diff --git a/sycl/probe/doorbell_store.cpp b/sycl/probe/doorbell_store.cpp
new file mode 100644
index 000000000..433e74fae
--- /dev/null
+++ b/sycl/probe/doorbell_store.cpp
@@ -0,0 +1,43 @@
+// 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
+}