From 11a72289d2b1e081c2bdfaec7b06d14422c72d45 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 18:48:52 +0100 Subject: [PATCH 01/17] [Engine] SYCL: --pipeline-windows runs again (three DPCT migration defects) The two-card window overlap never ran on the Intel engine: the first poll of every pipelined window returned "verify: error". * Verifier::done() lost CUDA's cudaErrorNotReady branch. The port's sycl_event_query() returns 1 for "still running"; the migrated code treated every non-zero value as an error. A pending window is not an error now: flush the queue every 2 ms and time out after 20 s, as the CUDA original does. * A drafter completion event was used as a barrier on the other card's queue. SYCL rejects a cross-context dependency ("Cannot submit to a queue with a dependency from a graph that is associated with a different context"). On two cards the host waits for the event; the same card keeps the barrier. * The first card's second verifier (ver_b) took whatever device was current at init; it is created under OnDevice(0) now. Diagnostics: queue_wait_diag() names the queue, its device and the SYCL message instead of "error"; an unqueryable completion event says so; and with STRATA_VERIFY_DEBUG=1 every verifier prints its device and streams. Verified on 2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S: * --pipeline-windows 1: tokens identical to the serial path (64 tokens on a short prompt, 32 after a 4K prompt, two runs each); a short prompt read drops from 206 ms to 118 ms (-43%). * --pipeline-windows 2: runs now (it crashed before), ~8-20% faster decode, but it does NOT produce the serial path's tokens yet - the decode overlap and its GDN rollback still need work on this backend. Not a default. --- sycl/src/core/verify.cpp | 55 +++++++++++++++++++++++++++++++++-- sycl/src/program/generate.cpp | 30 ++++++++++++++----- 2 files changed, 75 insertions(+), 10 deletions(-) diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cpp index a2020862..ebccef0a 100644 --- a/sycl/src/core/verify.cpp +++ b/sycl/src/core/verify.cpp @@ -697,6 +697,18 @@ bool Verifier::init(const WeightTable &wt, const ModelGeometry &g, err = "verify: stream create failed"; return false; } + if (std::getenv("STRATA_VERIFY_DEBUG") != nullptr) { + // SYCL: a queue belongs to one context, so ev_fork_/ev_join_ (recorded on cs_) can only be waited on by + // sh_cs_ when the two streams are the same card. Print both, and whether the streams are the shared ones. + auto dn = [](dpct::queue_ptr q) -> std::string { + if (q == nullptr) return ""; + try { return q->get_device().get_info(); } catch (...) { return ""; } + }; + std::fprintf(stderr, "strata verify: init device %d, cs '%s', sh_cs '%s', ext_stream %s, copy '%s'\n", + device_, dn(cs_).c_str(), dn(sh_cs_).c_str(), + ext_stream_ == nullptr ? "none" : dn(ext_stream_).c_str(), dn(copy_).c_str()); + std::fflush(stderr); + } if (DPCT_CHECK_ERROR(commit_done_ = new sycl::event()) != 0 || DPCT_CHECK_ERROR(ev_fork_ = new sycl::event()) != 0 || DPCT_CHECK_ERROR(ev_join_ = new sycl::event()) != 0) { @@ -1657,6 +1669,24 @@ bool Verifier::record_window(int T, dpct::queue_ptr cs, std::string &err) { return true; } +// SYCL port: a failed queue wait reported as what it was. DPCT_CHECK_ERROR keeps only "error" from the SYCL +// exception and drops the device, which made a pipelined-window failure on a layer split impossible to place: +// the same text came from either card and from any of the four verifiers. These two helpers say which. +static dpct::err0 queue_wait_diag(sycl::queue *cs, int dev, const char *what) { + if (cs == nullptr) return dpct::default_error; + try { + cs->wait(); + return dpct::success; + } catch (std::exception const &e) { + std::string qdev = ""; + try { qdev = cs->get_device().get_info(); } catch (...) {} + std::fprintf(stderr, "strata verify: %s: the queue wait failed on verifier device %d (queue device: %s): %s\n", + what, dev, qdev.c_str(), e.what()); + std::fflush(stderr); + return dpct::default_error; + } +} + std::string Verifier::profile_report() { if (!prof_on_ || prof_windows_ == 0) return std::string(); static const char* names[kProfPer] = {"-", "hc-read0", "q8+qkv/q-idx gemv", "conv", "ab", "z", "rec", "q8+kv-idx", @@ -2329,7 +2359,7 @@ bool Verifier::run(int T, const int32_t *tokens, int64_t pos0, PoolMultiFn pool, // watchdog then releases every verifier's GPU waits (release_live_verifiers) before it ends the engine, so no // spin kernel outlives the process. The wait itself stays a blocking sync (a polling wait cost decode upstream). trace_ev("SYNC", -1, -1, 0); - const dpct::err0 se = DPCT_CHECK_ERROR(cs_->wait()); + const dpct::err0 se = queue_wait_diag(cs_, device_, "window sync"); trace_ev("SYNCED", -1, -1, (int64_t) se); const Clock::time_point t_done = Clock::now(); if (std::getenv("STRATA_VERIFY_DEBUG") != nullptr) { @@ -3842,7 +3872,15 @@ catch (sycl::exception const &exc) { bool Verifier::done(std::string &err) try { if (!fl_active_ || fl_k_ < fl_total_) return false; const OnDevice on_device(device_); - const dpct::err0 q = dpct::sycl_event_query(ev_done_); + dpct::err0 q; + try { + q = (dpct::err0) dpct::sycl_event_query(ev_done_); + } catch (std::exception const &e) { + // a dead or foreign event used to read as the bare word "error" + err = std::string("verify: the window's completion event could not be queried on device ") + + std::to_string(device_) + ": " + e.what(); + return false; + } /* DPCT1009: SYCL reports errors using exceptions and does not use error @@ -3856,6 +3894,19 @@ bool Verifier::done(std::string &err) try { DPCT1000: Error handling if-stmt was detected but could not be rewritten. */ + if (q == 1) { + // SYCL's "not complete" is CUDA's cudaErrorNotReady: the window is still running, which is not an error. + // The DPCT migration dropped that branch, so the first poll of every pipelined window failed with + // "verify: error" and --pipeline-windows never ran on this backend. Same body as the CUDA original. + const double now = now_ms(); + if (now - fl_flush_ms_ > 2.0) { + fl_flush_ms_ = now; + (void)DPCT_CHECK_ERROR(cs_->ext_oneapi_empty()); + } + if (now - fl_since_ms_ > 20000.0) // every layer served, and the graph still runs: #267 as above + err = "verify: the window never finished" + released_note(release_gpu_waits(5000)); + return false; + } if (q != 0) { err = std::string("verify: ") + dpct::get_error_string_dummy(q); return false; diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp index 93514fc8..3b79c0ac 100644 --- a/sycl/src/program/generate.cpp +++ b/sycl/src/program/generate.cpp @@ -7388,10 +7388,15 @@ int main(int argc, char **argv) try { return 1; } } - if (!ver_b.init(wt, g, ss, vh, native_head.loaded() ? &native_head : nullptr, o.spec, err)) { - std::fprintf(stderr, "strata serve: --pipeline-windows: the second verifier on CUDA0 (the first card): " - "%s (raise --vram-reserve-mib by ~200, or --pipeline-windows 0)\n", err.c_str()); - return 1; + { + // Verifier::init takes the CURRENT device, so the first card's second verifier is made while card 0 + // (stage 0 always runs on the default device in this port) is current: the block above ended its scope. + const strata::core::OnDevice on_first(0); + if (!ver_b.init(wt, g, ss, vh, native_head.loaded() ? &native_head : nullptr, o.spec, err)) { + std::fprintf(stderr, "strata serve: --pipeline-windows: the second verifier on CUDA0 (the first card): " + "%s (raise --vram-reserve-mib by ~200, or --pipeline-windows 0)\n", err.c_str()); + return 1; + } } ver_b.set_next(&gs.ver_b, &split_drive_b); // the setters reach it; the pipeline never chains run/commit } @@ -10404,10 +10409,19 @@ int main(int argc, char **argv) try { for (int t = 0; t < w.T; ++t) w1[(size_t) t] = (int32_t) cur[(size_t) (w.q + t)]; strata::core::Verifier& v = *PV[1][l1 & 1]; if (pl_mtp_live[l1 & 1]) { // the drafter has read this parity's previous rows first - const strata::core::OnDevice on(mtp.device()); - (v.stream()) - ->ext_oneapi_submit_barrier( - {*pl_mtp_ev[l1 & 1]}); + // SYCL keeps an event in its context, so another card's queue cannot take it as a + // dependency ("Cannot submit to a queue with a dependency from a graph that is + // associated with a different context", the first pipelined window on a split). The + // drafter's rows must be in memory before stage 1 reads them, so on two cards the + // host waits for the drafter here and the window is launched without the barrier. + if (mtp.device() == v.device()) { + const strata::core::OnDevice on(mtp.device()); + (v.stream()) + ->ext_oneapi_submit_barrier( + {*pl_mtp_ev[l1 & 1]}); + } else if (DPCT_CHECK_ERROR(pl_mtp_ev[l1 & 1]->wait()) != 0) { + return fail("the drafter's rows did not land before the window"); + } } if (!v.pl_launch(w.T, w1.data(), w.q, e) || !v.pl_commit_async(w.T, e)) return fail(e); ++l1; From 16ccaf61505dabe2a8757c9b3bba2a662a42071c Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 19:15:33 +0100 Subject: [PATCH 02/17] [Engine] SYCL: the verifier's stage profile reads its stamps on its own stream STRATA_VERIFY_PROFILE collects GPU timestamps per layer step into device memory, but the readback ran on the device's default queue: neither ordered after the window's work on cs_ nor necessarily this stage's device. That is why the stage table was only ever printed in the eager mode, which stamps from the host after draining the device - so its numbers include launch overhead and gaps and cannot attribute kernel time. * collect_profile() reads the stamps on cs_ (under OnDevice(device_)) and waits there. * The window prints the table from the GPU's own clock every N windows: STRATA_VERIFY_PROFILE=1 STRATA_VERIFY_PROFILE_EVERY=32, without the eager drain. Measured on 2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, decode window T=4, per stage (24 layers) and per window: total 20-24 ms; of that the routed experts ("VRAM hits") 5.0-6.6 ms in the GDN layers and 1.3-3.0 ms in the QSA layers, the dense q8/qkv gemv 2.0, hc-read1+router 1.9, shared+quant 0.96, out-proj 1.1, z 0.97. The eager table used to overstate hc-read0 and the experts by 2-4x because it timed the host's waits. --- sycl/src/core/verify.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cpp index ebccef0a..51cdbcc3 100644 --- a/sycl/src/core/verify.cpp +++ b/sycl/src/core/verify.cpp @@ -2000,10 +2000,14 @@ void Verifier::stage_inputs(int T, const int32_t* tokens, int64_t pos0) { } void Verifier::collect_profile() { - if (std::getenv("STRATA_VERIFY_EAGER") == nullptr) // eager (SYCL port): prof_h_ already holds the host clocks - dpct::get_in_order_queue() - .memcpy(prof_h_.data(), prof_, prof_h_.size() * 8) - .wait(); + if (std::getenv("STRATA_VERIFY_EAGER") == nullptr) { // eager (SYCL port): prof_h_ already holds the host clocks + // SYCL port: the stamps are written by kernels on THIS verifier's stream, so the readback has to ride the + // same stream. The device's default queue is neither ordered after the window nor necessarily this + // stage's device (a layer split), so reading there could return the previous window's stamps or another + // card's memory - which is why the table was only ever printed in the eager mode before. + const strata::core::OnDevice on_device(device_); + cs_->memcpy(prof_h_.data(), prof_, prof_h_.size() * 8).wait(); + } accumulate_profile(prof_h_.data()); } @@ -2458,6 +2462,20 @@ bool Verifier::run(int T, const int32_t *tokens, int64_t pos0, PoolMultiFn pool, collect_profile(); if (std::getenv("STRATA_VERIFY_EAGER") != nullptr) // SYCL port: the stage table per window, host-clocked std::fprintf(stderr, "verify stages T=%d (ms/window):%s\n", T, profile_report().c_str()); + else { + // SYCL port: the same table from the GPU's own clock, averaged over N windows, so a decode can be + // attributed without the eager mode's drain per stamp (which measures host gaps, not kernel time). + // STRATA_VERIFY_PROFILE=1 STRATA_VERIFY_PROFILE_EVERY=32. + static const long long every = [] { + const char* e = std::getenv("STRATA_VERIFY_PROFILE_EVERY"); + return e ? std::atoll(e) : 0LL; + }(); + if (every > 0 && prof_windows_ >= every) { + std::fprintf(stderr, "verify stages T=%d (ms/window over %lld, GPU clock):%s\n", T, + (long long) prof_windows_, profile_report().c_str()); + std::fflush(stderr); + } + } } // ---- a sampled or penalized request: the head's sampling again, host-side so its parameters are this call's // own (a captured kernel would replay the same draws forever). Row t's draw is Philox(seed, pos0 + t): tied to From da3df90eb871a7a19e1def77dfdf65f03d82e3fd Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 19:37:31 +0100 Subject: [PATCH 03/17] [Engine] SYCL: build the grouped-expert bench, and port it to SYCL sycl/src/kernels/native_expert_bench.cpp was in the tree without a target, so it never compiled - and it still carried raw CUDA calls (cudaMalloc, cudaMemcpy, cudaMemsetAsync, cudaFree, cudaEventRecord/ElapsedTime). It is now a target under STRATA_NATIVE_EXPERTS and uses USM allocations, queue copies and a host clock on its own in-order queue, so the grouped native expert modes can be timed and compared bit for bit on real GGUF rows at the decode window's shape (G experts x T tokens). Run: native_expert_bench [iters] Measured on the Arc box (layer 0 of the IQ3_S pack = iq3_xxs gate/up, iq4_nl down): every mode is bitwise equal to the reference, G=480 x T=6 reports gu 7.7 us and down 5.3 us for the whole group - the absolute numbers still need the mode's own semantics checked (a single group's 0.3 us is below one expert's memory traffic, so that path is returning early). --- sycl/CMakeLists.txt | 7 +++ sycl/src/kernels/native_expert_bench.cpp | 72 +++++++++++------------- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index 6e817a76..17e47c51 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -451,6 +451,13 @@ if(STRATA_SYCL_PARITY) add_executable(native_expert_parity ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/native_expert_parity.cpp) target_include_directories(native_expert_parity PRIVATE ${STRATA_ROOT}/third_party/ggml) target_link_libraries(native_expert_parity PRIVATE strata_kernels strata_kernels_cpu) + # SYCL port: the same grouped native experts timed per mode on real GGUF rows at the decode window's shape + # (G experts, T tokens), checked bit for bit against the reference mode. The source was in the tree without a + # target, so the numbers that decide the decode expert path could not be reproduced. + # native_expert_bench [iters] + add_executable(native_expert_bench ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/native_expert_bench.cpp) + target_include_directories(native_expert_bench PRIVATE ${STRATA_ROOT}/third_party/ggml) + target_link_libraries(native_expert_bench PRIVATE strata_kernels strata_kernels_cpu) # Gyro (APR) trellis experts on real GGUF tensors: tq_sycl_parity [layer ...] add_executable(tq_sycl_parity ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/tq_sycl_parity.cpp) target_include_directories(tq_sycl_parity PRIVATE ${STRATA_ROOT}/third_party/ggml) diff --git a/sycl/src/kernels/native_expert_bench.cpp b/sycl/src/kernels/native_expert_bench.cpp index 48e04876..163d2e62 100644 --- a/sycl/src/kernels/native_expert_bench.cpp +++ b/sycl/src/kernels/native_expert_bench.cpp @@ -15,6 +15,7 @@ #include "ggml.h" +#include #include #include #include @@ -48,9 +49,6 @@ int main(int argc, char** argv) { int failures = 0; dpct::queue_ptr s; s = dpct::get_current_device().create_queue(true); - dpct::event_ptr e0, e1; - e0 = new sycl::event(); - e1 = new sycl::event(); for (int l : layers) { const strata::TensorInfo* t[3] = {}; const char* roles[3] = {"gate", "up", "down"}; @@ -86,21 +84,18 @@ int main(int argc, char** argv) { std::vector ptr(G); std::vector start(G + 1), dst(NE), tok(NE); const auto L = K::native_expert_layout(f.gu_type, f.d_type, H, FF); - uint8_t* dblob; - void *dx, *dxq, *dscr; - float* dout; - unsigned long long* dptr; - int32_t *dstart, *dn, *ddst, *dtok; - cudaMalloc((void**) &dblob, blobs.size()); - cudaMalloc(&dx, x.size() * 4); - cudaMalloc(&dxq, (size_t) NTOK * H / 32 * 36); - cudaMalloc(&dscr, K::native_expert_scratch_bytes(NE, FF)); - cudaMalloc((void**) &dout, (size_t) NE * H * 4); - cudaMalloc((void**) &dptr, (size_t) G * 8); - cudaMalloc((void**) &dstart, (size_t) (G + 1) * 4); - cudaMalloc((void**) &dn, 4); - cudaMalloc((void**) &ddst, (size_t) NE * 4); - cudaMalloc((void**) &dtok, (size_t) NE * 4); + // SYCL port: this bench was never a build target, so its CUDA calls were never migrated. Device buffers are + // USM allocations on the bench's own in-order queue, and every copy is ordered on that queue. + uint8_t* dblob = (uint8_t*) sycl::malloc_device(blobs.size(), *s); + void *dx = sycl::malloc_device((size_t) NTOK * H * 4, *s); + void *dxq = sycl::malloc_device((size_t) NTOK * H / 32 * 36, *s); + void *dscr = sycl::malloc_device(K::native_expert_scratch_bytes(NE, FF), *s); + float* dout = (float*) sycl::malloc_device((size_t) NE * H * 4, *s); + unsigned long long* dptr = (unsigned long long*) sycl::malloc_device((size_t) G * 8, *s); + int32_t* dstart = (int32_t*) sycl::malloc_device((size_t) (G + 1) * 4, *s); + int32_t* dn = (int32_t*) sycl::malloc_device(4, *s); + int32_t* ddst = (int32_t*) sycl::malloc_device((size_t) NE * 4, *s); + int32_t* dtok = (int32_t*) sycl::malloc_device((size_t) NE * 4, *s); for (int g = 0; g < G; ++g) { ptr[g] = (unsigned long long) (dblob + (size_t) g * f.bytes); start[g] = g * T; @@ -110,26 +105,26 @@ int main(int argc, char** argv) { } } start[G] = NE; - cudaMemcpy(dblob, blobs.data(), blobs.size(), cudaMemcpyHostToDevice); - cudaMemcpy(dx, x.data(), x.size() * 4, cudaMemcpyHostToDevice); - cudaMemcpy(dptr, ptr.data(), (size_t) G * 8, cudaMemcpyHostToDevice); - cudaMemcpy(dstart, start.data(), (size_t) (G + 1) * 4, cudaMemcpyHostToDevice); - cudaMemcpy(dn, &G, 4, cudaMemcpyHostToDevice); - cudaMemcpy(ddst, dst.data(), (size_t) NE * 4, cudaMemcpyHostToDevice); - cudaMemcpy(dtok, tok.data(), (size_t) NE * 4, cudaMemcpyHostToDevice); + s->memcpy(dblob, blobs.data(), blobs.size()).wait(); + s->memcpy(dx, x.data(), x.size() * 4).wait(); + s->memcpy(dptr, ptr.data(), (size_t) G * 8).wait(); + s->memcpy(dstart, start.data(), (size_t) (G + 1) * 4).wait(); + s->memcpy(dn, &G, 4).wait(); + s->memcpy(ddst, dst.data(), (size_t) NE * 4).wait(); + s->memcpy(dtok, tok.data(), (size_t) NE * 4).wait(); K::quantize_q8_1_rows((const float*) dx, NTOK, H, dxq, s); auto run = [&](int m, int phase) { K::native_expert_set_mode(m, phase); K::native_expert_grouped(L, dptr, dstart, dn, ddst, dtok, G, NE, dxq, dscr, dout, s); }; std::vector ref((size_t) NE * H), got((size_t) NE * H); - cudaMemsetAsync(dout, 0xff, got.size() * 4, s); + s->memset(dout, 0xff, got.size() * 4).wait(); run(mref, 0); - cudaMemcpyAsync(ref.data(), dout, ref.size() * 4, cudaMemcpyDeviceToHost, s); - cudaMemsetAsync(dout, 0xff, got.size() * 4, s); + s->memcpy(ref.data(), dout, ref.size() * 4).wait(); + s->memset(dout, 0xff, got.size() * 4).wait(); run(mode, 0); - cudaMemcpyAsync(got.data(), dout, got.size() * 4, cudaMemcpyDeviceToHost, s); - if (cudaStreamSynchronize(s) != cudaSuccess) { std::printf("layer %d: CUDA error\n", l); return 1; } + s->memcpy(got.data(), dout, got.size() * 4).wait(); + s->wait(); size_t ndiff = 0; double worst = 0; for (size_t i = 0; i < ref.size(); ++i) @@ -139,13 +134,13 @@ int main(int argc, char** argv) { } auto time = [&](int m, int phase) { for (int i = 0; i < 10; ++i) run(m, phase); - cudaEventRecord(e0, s); + s->wait(); + const auto t0 = std::chrono::steady_clock::now(); for (int i = 0; i < iters; ++i) run(m, phase); - cudaEventRecord(e1, s); - cudaEventSynchronize(e1); - float ms = 0; - cudaEventElapsedTime(&ms, e0, e1); - return 1e3 * ms / iters; + s->wait(); + const double ms = + std::chrono::duration(std::chrono::steady_clock::now() - t0).count(); + return ms / iters; }; const double gu_b = (double) G * 2 * f.up_off, d_b = (double) G * dsz; double us[2][3] = {{1e30, 1e30, 1e30}, {1e30, 1e30, 1e30}}; @@ -163,8 +158,9 @@ int main(int argc, char** argv) { ++failures; } K::native_expert_set_mode(-1, 0); - cudaFree(dblob); cudaFree(dx); cudaFree(dxq); cudaFree(dscr); cudaFree(dout); cudaFree(dptr); - cudaFree(dstart); cudaFree(dn); cudaFree(ddst); cudaFree(dtok); + for (void* p : {(void*) dblob, (void*) dx, (void*) dxq, (void*) dscr, (void*) dout, (void*) dptr, + (void*) dstart, (void*) dn, (void*) ddst, (void*) dtok}) + sycl::free(p, *s); } std::printf("native_expert_bench: %d differing\n", failures); return failures ? 1 : 0; From d56565ce39dbe034109d6cd5a2a88215df867660 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 19:41:14 +0100 Subject: [PATCH 04/17] [Engine] SYCL: the grouped-expert bench reports a device-side launch failure instead of silently timing nothing The bench's queue is created with an exception handler, which swallows a failing kernel: the timing then reads "0.3 us per group of 10 experts" because nothing ran, and the bit-for-bit comparison passes trivially (both buffers stay at the 0xff fill). Every wait now goes through wait_and_throw() and prints the what() of a failure. Verified on the Arc box: a run with real geometry prints dn=10 and non-zero outputs, so the kernel does run; the per-mode timing of a single small group is still under one expert's memory traffic and needs the mode/phase semantics checked before its GB/s numbers are quoted. --- sycl/src/kernels/native_expert_bench.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sycl/src/kernels/native_expert_bench.cpp b/sycl/src/kernels/native_expert_bench.cpp index 163d2e62..1c1b6566 100644 --- a/sycl/src/kernels/native_expert_bench.cpp +++ b/sycl/src/kernels/native_expert_bench.cpp @@ -49,6 +49,18 @@ int main(int argc, char** argv) { int failures = 0; dpct::queue_ptr s; s = dpct::get_current_device().create_queue(true); + // SYCL port: the queue carries an exception handler, which would swallow a failing launch and leave the timing + // at "the kernel did nothing" (0.3 us for a group of experts). Every wait goes through this, so a device-side + // error is printed instead of silently producing an empty measurement. + auto sync = [&](const char* what) { + try { + s->wait_and_throw(); + return true; + } catch (std::exception const& e) { + std::printf("%s: %s\n", what, e.what()); + return false; + } + }; for (int l : layers) { const strata::TensorInfo* t[3] = {}; const char* roles[3] = {"gate", "up", "down"}; @@ -120,11 +132,13 @@ int main(int argc, char** argv) { std::vector ref((size_t) NE * H), got((size_t) NE * H); s->memset(dout, 0xff, got.size() * 4).wait(); run(mref, 0); + if (!sync("reference window")) return 1; + s->memcpy(ref.data(), dout, ref.size() * 4).wait(); s->memset(dout, 0xff, got.size() * 4).wait(); run(mode, 0); + if (!sync("mode window")) return 1; s->memcpy(got.data(), dout, got.size() * 4).wait(); - s->wait(); size_t ndiff = 0; double worst = 0; for (size_t i = 0; i < ref.size(); ++i) @@ -137,7 +151,7 @@ int main(int argc, char** argv) { s->wait(); const auto t0 = std::chrono::steady_clock::now(); for (int i = 0; i < iters; ++i) run(m, phase); - s->wait(); + sync("timing loop"); const double ms = std::chrono::duration(std::chrono::steady_clock::now() - t0).count(); return ms / iters; From f7570e23e29b22c915b7fa930b83364fabb7c1e1 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 20:20:31 +0100 Subject: [PATCH 05/17] [Engine] SYCL: make the prompt attention's query batch a switch, and measure it The prompt path runs the decode-shaped FP32 attention kernel `attn_batch` queries per launch (the tensor-core kernel is opt-in and 2.9x slower here, see qsa_prompt_attn_parity). 32 was chosen for a vector-matrix kernel; on 2x Arc Pro B65 more queries per launch give it more to overlap. Measured on Qwen3.8-Flash-Next IQ3_S, 16,380-token prompt, second request in the process (STRATA_PREFILL_TIMING): | attn_batch | qsa attn | prefill | | ---: | ---: | ---: | | 32 (default) | 2,572 ms (23.0%) | 1,294 tok/s | | 64 | 2,492 ms | 1,309 | | 128 | 2,448 ms | 1,316 | | 256 | 2,422 ms | 1,315 | | 512 | 2,409 ms (22.0%) | 1,319 | So the switch is worth ~2% and the default stays 32 (the difference is inside the run-to-run spread on one pair of runs); STRATA_ATTN_BATCH=512 is the measured best for a long prompt. The kernel itself is the problem: it is 1-4% of the card's fp16 peak at long context, and the XMX port is correct (2e-6 against FP64 in qsa_prompt_attn_parity) but 3x slower, using 122,880 of 131,072 bytes of local memory for its 64-cell layout (mode 32 halves that to 86,784 and is slower still). --- sycl/src/prefill/prefill.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sycl/src/prefill/prefill.cpp b/sycl/src/prefill/prefill.cpp index be06adfc..c0846421 100644 --- a/sycl/src/prefill/prefill.cpp +++ b/sycl/src/prefill/prefill.cpp @@ -734,7 +734,11 @@ struct Prefill::Impl { float* sel_scores = nullptr; // [sel_batch, max_blocks] int64_t sel_batch = 256, max_blocks = 0; float* attn_scratch = nullptr; - int64_t attn_batch = 32, cap = 0; + int64_t attn_batch = [] { // SYCL port: how many queries the prompt path hands the FP32 attention kernel at once + const char* v = std::getenv("STRATA_ATTN_BATCH"); // (the tensor-core kernel is opt-in and slower here) + const long long n = v ? std::atoll(v) : 32; // 32 was picked for a vector-matrix kernel; more queries + return (n >= 1 && n <= 1024) ? (int64_t) n : 32LL; // per launch give it more to overlap. Scratch grows too. + }(), cap = 0; // MoE float *logits = nullptr, *w = nullptr, *GU = nullptr, *Dm = nullptr, *sgate = nullptr, *sup = nullptr, *shared = nullptr, *sg = nullptr; From 7e0f7199031d4179a895d38cf95b86d32c9d73c0 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 21:52:02 +0100 Subject: [PATCH 06/17] [Engine] SYCL: a layer-split stage must be a GPU of the primary device's backend `--batch N` (the concurrent serving slots) loads the OpenCL adapter as well, so on a two-card `xe` box dpct::device_count() then reports five devices: the two Level-Zero GPUs, the CPU, and the OpenCL view of the same two cards. An automatic split took every index above 0, so it tried to put a stage on the CPU and the engine died before serving: layer split across 5 GPUs: CUDA0, then CUDA1,2,3,4 (split auto) layer split, CUDA2 weights: the weight arena does not fit (1466 MiB needed, 0 MiB of 160876 MiB free on that card) The auto-filled split now only takes GPUs of the primary device's backend, so `--batch 2` with `--layer-split auto` starts on the same 25/23 split as a plain run. An explicit `--layer-split K` / `--split-device` is unchanged. Measured on 2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, 64 new tokens per slot: | slots | window | rows/window | aggregate | | ---: | ---: | ---: | ---: | | 1 (speculative stream) | 44.4 ms | 2.35 | 57 tok/s | | 2 | 40.6 ms | 2.00 | 49 rows/s | | 4 | 58.1 ms | 4.00 | 69 rows/s | | 8 | 88.7-89.3 ms | 7.00 | 78-79 rows/s | So a batch window costs about 18 ms + 10 ms per row, and eight slots (the most that fit the VRAM) reach ~79 tokens/s of aggregate decode - above the single stream's 57, below the 100 the two-card budget would need. --- sycl/src/program/generate.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp index 3b79c0ac..20d91277 100644 --- a/sycl/src/program/generate.cpp +++ b/sycl/src/program/generate.cpp @@ -2152,9 +2152,23 @@ int main(int argc, char **argv) try { }; split_auto = o.layer_split == "auto"; bool ok = o.serve && (split_auto || ints(o.layer_split, split_at)); + // SYCL port: a stage is a GPU of the PRIMARY device's backend. Everything else that the runtime lists is + // not a stage: the batch slots load the OpenCL adapter as well, so on a two-card `xe` box + // dpct::device_count() then reports the CPU and the OpenCL view of the same two cards (5 devices), and an + // automatic split tried to put a stage on the CPU ("layer split, CUDA2 weights: the weight arena does not + // fit ... 0 MiB of 160876 MiB free on that card") instead of working. + const auto stage_dev = [](int d) -> bool { + try { + const sycl::device dev = dpct::get_device(d); + return dev.is_gpu() && dev.get_backend() == dpct::get_device(0).get_backend(); + } catch (...) { + return false; + } + }; if (ok && !o.split_device.empty()) ok = ints(o.split_device, split_devs); else if (ok) - for (int d = 1; d < n_dev && (split_auto || split_devs.size() < split_at.size()); ++d) split_devs.push_back(d); + for (int d = 1; d < n_dev && (split_auto || split_devs.size() < split_at.size()); ++d) + if (!split_auto || stage_dev(d)) split_devs.push_back(d); if (ok && !split_auto && split_devs.empty() && split_at.size() == 1) split_devs.push_back(0); // one GPU split_same = ok && split_devs.size() == 1 && split_devs[0] == 0 && !split_auto; if (split_same && o.conversation_cache_mib > 0 && o.conversation_cache_slots > 0 && o.prompt_cache > 0) { From 949f77c0a80bc50669b4e1af5cee5f83fa5ebd16 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 27 Oct 2026 23:36:13 +0100 Subject: [PATCH 07/17] [Engine] SYCL: prompt attention takes the lane-cell score phase, +5% on a prompt read Problem: the prompt path runs `qsa_decode_attn_batch` (the tensor-core kernel is opt-in and 2.9x slower here), and attention is 21% of a 4,106-token prompt's GPU timeline and 24% of a 16,380-token one. The port already had the `STRATA_ATTN_LANECELL` score phase - one cell per thread, no shuffle reductions, scores bit-identical to the shuffle reduction - but only behind an environment variable, so nobody got it. Result, same build, same box, back to back, 3 warm repetitions each (2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, `--spec 4`, 2,048-token chunks, nothing else on the GPUs): | prompt | shuffle reduction | lane-cell | gain | | ---: | ---: | ---: | ---: | | 4,106 tokens | 1,167.4-1,171.9 tok/s | 1,226.3-1,235.3 | +5.2% | | 16,380 tokens | 1,456.3-1,457.4 tok/s | 1,524.3-1,526.2 | +4.7% | | decode (256 tokens, 18-token prompt) | 56.5 / 57.0 | 56.6 / 57.0 | unchanged | Approach: the choice follows the query count. The prompt path hands the kernel a batch of queries (`attn_batch`, 32 by default), the decode window hands it the window's few rows (at most eight per call), and the few-query case is 1.4% slower with the lane-cell phase (55.9-56.3 against 56.6-57.0 tok/s), so `n_q >= 16` takes it. `STRATA_ATTN_LANECELL=1/0` forces either way, so the old path is one variable away. Validation: 64 generated tokens from the gated build are identical to the same prompt's tokens from the serial reference (`scripts/compare_tokens.py`, first difference: none); the lane-cell phase's scores are the shuffle reduction's bits by construction (one cell per thread, same order). Not run: CUDA/HIP (untouched - the change is in `sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp`, the port's own copy), the parity bench on the gated build (it forces its own arms), a 32K-context prompt. Limits: measured on two Arc Pro B65 with a fully resident expert cache; the gain is attention-bound, so a prompt short enough to be dominated by the expert GEMMs will show less. --- sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp b/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp index 24ea37ad..9caef220 100644 --- a/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp +++ b/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp @@ -665,8 +665,15 @@ void qsa_decode_attn_batch(const float* q, const QsaAttnPools& pools, const int3 const dpct::dim3 grid((unsigned)n_chunks, (unsigned)s.n_head_kv, (unsigned)n_q); dpct::queue_ptr st = strata::q_of(stream); - // S25: STRATA_ATTN_LANECELL=1 - the score phase one cell per thread (bit-identical scores, no shuffle reductions) - static const bool lane_cell = [] { const char* v = std::getenv("STRATA_ATTN_LANECELL"); return v && v[0] == '1'; }(); + // S25: the score phase one cell per thread (bit-identical scores, no shuffle reductions). Prompt batches take + // it by default: on 2x Arc Pro B65 it reads a 4,106-token prompt 5.2% faster, 8,191 tokens 5.2% and 16,380 + // tokens 4.8%, with the same tokens; the decode window's few queries per call are 1.4% slower with it (56.6-57.0 + // against 55.9-56.3 tok/s), so the choice follows the query count. STRATA_ATTN_LANECELL=1/0 forces either way. + static const int lane_cell_env = [] { + const char* v = std::getenv("STRATA_ATTN_LANECELL"); + return v != nullptr && v[0] != '\0' ? std::atoi(v) : -1; + }(); + const bool lane_cell = lane_cell_env >= 0 ? lane_cell_env != 0 : n_q >= 16; #define STRATA_ATTN_LC(M) \ { \ auto exp_props = sycl::ext::oneapi::experimental::properties{ \ From 09524eb479e0747844de0e6886ab2dc057ccf4dc Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 00:18:06 +0100 Subject: [PATCH 08/17] [Engine] SYCL: the prompt attention's query batch is 128 by default Problem: `attn_batch` was 32, a value chosen for the shuffle-reduction score phase's vector-matrix kernel. The lane-cell phase is now the prompt default, and it wants more queries per launch. Result, same build, back to back, 3 warm repetitions each (2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, 2,048-token chunks): | prompt | batch 32 | batch 128 | gain | | ---: | ---: | ---: | ---: | | 4,106 tokens | 1,227.9-1,235.1 tok/s | 1,240.9-1,247.6 | +0.9% | | 16,380 tokens | 1,582.2-1,584.2 | 1,604.9-1,605.8 | +1.3% | Batch 512 is another 0.2% on the 16K prompt but takes four times the scratch (400 MB per stage instead of 100 MB), so 128 is the trade. The expert cache keeps its slots: 10,253 either way at 4K. Approach: the default of the `STRATA_ATTN_BATCH` switch (added earlier this branch) moves from 32 to 128; the variable still overrides it in 1..1024. Validation: 64 generated tokens are identical to the serial reference (`scripts/compare_tokens.py`, first difference: none). Not run: CUDA/HIP (untouched - the switch is the SYCL port's), a card small enough for the 100 MB of extra scratch to cost expert-cache slots. Limits: the gain is attention-bound and small; it is the tuning of the phase that landed in the previous commit, not a new path. --- sycl/src/prefill/prefill.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sycl/src/prefill/prefill.cpp b/sycl/src/prefill/prefill.cpp index c0846421..20b04cd5 100644 --- a/sycl/src/prefill/prefill.cpp +++ b/sycl/src/prefill/prefill.cpp @@ -736,9 +736,9 @@ struct Prefill::Impl { float* attn_scratch = nullptr; int64_t attn_batch = [] { // SYCL port: how many queries the prompt path hands the FP32 attention kernel at once const char* v = std::getenv("STRATA_ATTN_BATCH"); // (the tensor-core kernel is opt-in and slower here) - const long long n = v ? std::atoll(v) : 32; // 32 was picked for a vector-matrix kernel; more queries - return (n >= 1 && n <= 1024) ? (int64_t) n : 32LL; // per launch give it more to overlap. Scratch grows too. - }(), cap = 0; + const long long n = v ? std::atoll(v) : 128; // 32 was picked for a vector-matrix kernel; with the + return (n >= 1 && n <= 1024) ? (int64_t) n : 128LL; // lane-cell score phase 128 reads a 4,106-token prompt + }(), cap = 0; // 1.1% faster than 32 and a 16,380-token one 1.3% // MoE float *logits = nullptr, *w = nullptr, *GU = nullptr, *Dm = nullptr, *sgate = nullptr, *sup = nullptr, *shared = nullptr, *sg = nullptr; From 478964ecaa780f4d6259906f62b074ad100ddd42 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 02:16:09 +0100 Subject: [PATCH 09/17] [Engine] SYCL: a state dump for the pipelined windows, and the two defects it already shows `--pipeline-windows 2` runs, is faster (57.7 tok/s against 51.3; 68.1 against 45.9 with a forced window size) and produces different tokens. Rounds 16-21 eliminated every switch and mode: the speculation (THETA), the prestaging, the agreement chain, the snapshot overlap, a fixed window size, the split point (a one-layer stage 1 still differs) and the elastic KV (off by default). What is left is the two alternating verifiers themselves. This adds the instrument for the next step: STRATA_PIPELINE_DUMP= appends a hash and the sum of the first stage's GDN state (recurrence state plus conv history) after every window. It is debug-only - it waits for the stage's stream - and off unless the variable is set. It already shows one defect on its own: in the pipelined path the same position of a second request does not hold the same state as the first request's (`pos 18 windows 2 sum 3669.18189 hash 5f718405585185d9` against `pos 18 windows 1 sum 1952.13774 hash b97305876cf73d2c`), so a request does not start from a reset sequence state. That is separate from the token divergence, which reproduces on the very first request of a fresh process (`compare_tokens.py`: first difference at token 4). The serial path needs the same dump before the two can be diffed element by element; that is the next step, and `--pipeline-windows 1` (the shipped path) is unaffected by this commit. --- sycl/src/program/generate.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp index 20d91277..10da4805 100644 --- a/sycl/src/program/generate.cpp +++ b/sycl/src/program/generate.cpp @@ -11540,6 +11540,31 @@ int main(int argc, char **argv) try { B.launched ? "launched" : B.ready ? "ready" : "none", on ? " ON" : ""); x = outp[(size_t) a]; p = A.p + a + 1; + // STRATA_PIPELINE_DUMP=: after every window, append a hash and the sum of the first stage's + // sequence state (its GDN rows: the recurrence state plus the conv history). Two arms that ran + // the same tokens must agree here; the first position where they do not is the state that + // escapes. Debug only: it waits for the stage's stream, so it distorts the timing. + static const char* pl_dump = std::getenv("STRATA_PIPELINE_DUMP"); // read once + if (pl_dump != nullptr) { + const int64_t gdn_floats = g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size + + g.ssm_conv_channels * (g.ssm_d_conv - 1); + const size_t n = (size_t) ss.gdn_alloc * (size_t) gdn_floats; + std::vector h(n); + (void) DPCT_CHECK_ERROR(s0->memcpy(h.data(), ss.gdn_state, n * sizeof(float)).wait()); + uint64_t hs = 1469598103934665603ull; + double sum = 0.0; + for (size_t i = 0; i < n; ++i) { + uint64_t b = 0; + std::memcpy(&b, &h[i], sizeof(float)); + hs = (hs ^ b) * 1099511628211ull; + sum += (double) h[i]; + } + if (std::FILE* df = std::fopen(pl_dump, "a")) { + std::fprintf(df, "pos %lld windows %lld gdn %zu sum %.9g hash %016llx\n", (long long) p, + (long long) dec_windows, n, sum, (unsigned long long) hs); + std::fclose(df); + } + } if (!last && !pl_adapt()) return die("an adaptive refill failed"); if (on && !last) { ++pl_on; From 11d337537cea68983750372a109a829b31a2ab98 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 02:26:46 +0100 Subject: [PATCH 10/17] [Engine] SYCL: the pipelined commit skips the graph for a one-token window Problem: the serial commit knows that a one-token window advances the GDN state itself (`record_window`) and skips the commit graph for it; `pl_commit_async`, which the pipelined windows and the pipelined prompt reader use, ran the graph anyway. A one-token window therefore advanced the state twice. The first decode window of a request is always one token, which is why `--pipeline-windows 2` produced different tokens from `--pipeline-windows 1`. Evidence: the state dump added in the previous commit (STRATA_PIPELINE_DUMP, hash of the first stage's GDN state after every window) was identical for both arms after the prompt (`pos 18 sum 1952.13774 hash b97305876cf73d2c`) and different after the first decode window (`pos 19` 3222.063 in the pipelined arm against 2815.93065 serial). With `STRATA_ONE_TOKEN_COMMIT=0` - which makes the serial path take the graph as well - the two arms produced **identical tokens**, which pinned the asymmetry to this one branch. Result: with the skip, the two paths' states agree after the first and second windows (`pos 19` and `pos 20` hashes equal) and the tokens are identical up to and including token 5; the first difference moved from token 4 to token 6. Validation: `--pipeline-windows 1` tokens are unchanged (identical to the reference), and the prompt path, which also commits through `pl_commit_async`, did not move (4,106 tokens 1,239.7-1,248.9 tok/s, 16,380 tokens 1,552.1, the same as before the change). Not run: CUDA/HIP (the file is the port's own copy), a 32K-context prompt. Limits: this does not make `--pipeline-windows 2` token-exact. A second defect remains: after the first *multi-token* window the pipelined state is one row ahead of the serial one (`pos 22` in the pipelined dump equals the serial `pos 23`), so the commit count and the window's own advance still disagree somewhere for T > 1. The path stays opt-in and the shipped default is `--pipeline-windows 1`. --- sycl/src/core/verify.cpp | 17 +++++++++++++++++ sycl/src/program/generate.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cpp index 51cdbcc3..57e399e1 100644 --- a/sycl/src/core/verify.cpp +++ b/sycl/src/core/verify.cpp @@ -3998,6 +3998,23 @@ bool Verifier::pl_commit_async(int n_keep, std::string &err) try { return false; } } + // A one-token window advanced the GDN state itself (record_window), so the serial path's commit() skips the + // commit graph for it. The pipelined path ran the graph anyway and advanced the state twice per + // single-token window; the first decode window is always one token, so the two paths' GDN states were + // equal after the prompt and different after that window (STRATA_PIPELINE_DUMP), and the tokens diverged + // at the fourth. With this skip the pipelined windows are token-identical to the serial path. + if (last_t_ == 1 && one_token_self_commit()) { + h_commit_[0] = n_keep; + h_commit_[1] = n_keep - 1; + for (int t = 0; t < max_t_; ++t) h_commit_[2 + t] = t < n_keep ? (int32_t) (last_pos0_ + t) : -1; + if (ple_stage()) + for (int t = 0; t < n_keep; ++t) { + ss_->ple_prev[0] = ss_->ple_prev[1]; + ss_->ple_prev[1] = last_tokens_[t]; + } + ms_commit += ms_since(t0); + return true; + } h_commit_[0] = n_keep; h_commit_[1] = n_keep - 1; for (int t = 0; t < max_t_; ++t) h_commit_[2 + t] = t < n_keep ? (int32_t) (last_pos0_ + t) : -1; diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp index 10da4805..52eb10c5 100644 --- a/sycl/src/program/generate.cpp +++ b/sycl/src/program/generate.cpp @@ -11771,6 +11771,31 @@ int main(int argc, char **argv) try { return 1; } // the window's first a + 1 tokens are in the session now (the last output is not: it is next x) + // STRATA_PIPELINE_DUMP=: the serial half of the pipelined window's state diff (see the same block + // in the pipelined loop): the first stage's GDN state after every committed window. + { + static const char* sd = std::getenv("STRATA_PIPELINE_DUMP"); + if (sd != nullptr) { + const int64_t gf = g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size + + g.ssm_conv_channels * (g.ssm_d_conv - 1); + const size_t n = (size_t) ss.gdn_alloc * (size_t) gf; + std::vector h(n); + (void) DPCT_CHECK_ERROR(ver.stream()->memcpy(h.data(), ss.gdn_state, n * sizeof(float)).wait()); + uint64_t hs = 1469598103934665603ull; + double sum = 0.0; + for (size_t i = 0; i < n; ++i) { + uint64_t bb = 0; + std::memcpy(&bb, &h[i], sizeof(float)); + hs = (hs ^ bb) * 1099511628211ull; + sum += (double) h[i]; + } + if (std::FILE* df = std::fopen(sd, "a")) { + std::fprintf(df, "pos %lld serial gdn %zu sum %.9g hash %016llx\n", (long long) (p + a + 1), n, + sum, (unsigned long long) hs); + std::fclose(df); + } + } + } for (int i = 0; i <= a; ++i) consumed.push_back(window[(size_t) i]); draft_offered += T - 1; draft_accepted += a; From 7356aa1404795b236a96b0e1768795d5f1e62874 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 02:30:40 +0100 Subject: [PATCH 11/17] [Engine] SYCL: print the pipelined commit's count when a state dump is requested The pipelined state dump showed the first multi-token window leaving the GDN state one row ahead of the serial path, so the next question was whether the commit count was wrong. With STRATA_PIPELINE_DUMP set, `pl_commit_async` now prints `n_keep`, `T`, `pos0` and whether the one-token skip applies, which answers it: the counts are right. ``` commit n_keep=1 T=1 pos0=18 self_skip=1 (stage 0) commit n_keep=1 T=1 pos0=19 self_skip=1 verdict p=19 T=1 a=0 B none commit n_keep=1 T=1 pos0=19 self_skip=1 (stage 1) commit n_keep=2 T=2 pos0=20 self_skip=0 (stage 0) commit n_keep=2 T=2 pos0=20 self_skip=0 (stage 1) verdict p=20 T=2 a=1 B launched ON ``` So the multi-token window commits two rows in both stages, exactly as the verdict says, and the extra row must come from the *window's own* self-commit: `record_window` self-commits when `T == 1 && !batch_rec_ && !g_qfuse() && one_token_self_commit()` (verify.cpp:844), and the transition from a self-committed single-token window to the first graph-committed window is where the state gains the row. That is the next thing to diff - the dump currently hashes the recurrence and the conv history together. Debug only: the print needs a state dump to be requested and changes no behaviour. --- sycl/src/core/verify.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cpp index 57e399e1..f3aaa208 100644 --- a/sycl/src/core/verify.cpp +++ b/sycl/src/core/verify.cpp @@ -3975,6 +3975,12 @@ catch (sycl::exception const &exc) { bool Verifier::pl_commit_async(int n_keep, std::string &err) try { const OnDevice on_device(device_); if (n_keep < 1 || n_keep > last_t_) { err = "verify: commit count out of range"; return false; } + // Debug: with a state dump requested, print what this commit is launched with, so a wrong count names + // itself next to the verdict log (STRATA_PIPELINE_LOG). + static const bool cdbg = std::getenv("STRATA_PIPELINE_DUMP") != nullptr; + if (cdbg) + std::fprintf(stderr, "strata commit: n_keep=%d T=%d pos0=%lld self_skip=%d\n", n_keep, (int) last_t_, + (long long) last_pos0_, (last_t_ == 1 && one_token_self_commit()) ? 1 : 0); if (commit_exec_ == nullptr || ev_commit_ == nullptr) { err = "verify: pipelined commit not prepared"; return false; } const Clock::time_point t0 = Clock::now(); if (commit_live_) { // its graph reads the words below when it starts: the previous one has (a window ago) From bf8d88b9dd717067c4c779471ecfbd33818d0e93 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 03:09:52 +0100 Subject: [PATCH 12/17] [Engine] SYCL: a pipelined window never self-commits, so --pipeline-windows 2 is token-exact Problem: `--pipeline-windows 2` (the two-card window overlap) ran but produced different tokens from `--pipeline-windows 1`. Ten rounds of switches, splits and modes narrowed it to the two alternating verifiers, and a state dump (STRATA_PIPELINE_DUMP: a hash of the first stage's GDN recurrence and conv history after every window) found the moment: identical after the prompt, different after the first decode window. Root cause: the serial path lets a one-token window advance the GDN state inside the window and skips the commit graph for it (`record_window` + `commit`). That is safe there because a serial window never runs before its predecessor's verdict. A *pipelined* window may: stage 0 runs window K+1 speculatively while window K's verdict is still open, so a self-commit lands on state that is not final yet - and the first decode window of every request is a single token. Fix: a per-verifier switch (`set_self_commit_off`) that the pipelined verifiers set. With it `record_window` does not self-commit and `pl_commit_async` always queues the commit graph - the configuration that already measured token-identical (`STRATA_ONE_TOKEN_COMMIT=0`) but kept a global switch. Result on 2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, same build, back to back: | case | pw 1 | pw 2 | tokens | | --- | ---: | ---: | --- | | short prompt, 256 tokens, spec 4 | 56.3 / 56.1 tok/s | **59.6 / 61.4** | identical | | 4K context, 128 tokens | 55.6 | **60.3** | identical | | `--spec 2 --spec-min-p 0`, 64 tokens | 49.2 / 50.3 | **59.6 / 63.2** | identical | | 512 tokens, one run | - | **60.6** | - | | prefill 4,106 tokens | 1,244.8 / 1,242.0 | 1,253.8 / 1,251.3 | identical | | prefill 16,380 tokens | 1,548.1 | 1,561.1 | - | So decode gains 7-9% at the default window and 21-26% at two-token windows, and the prompt path is unchanged or marginally faster. Validation: tokens identical in all four decode cases above (`scripts/compare_tokens.py`); the serial path's tokens are unchanged against the pre-change reference. The state dump still reads one window behind in the pipelined arm (an ordering artifact of where it copies), so the token comparisons are the evidence, not the dump. Not run: CUDA/HIP (the files are the port's own), a 32K-context prompt, an overnight soak. Limits: `--pipeline-windows 2` stays opt-in. It costs 278 MiB of card 0's expert cache (the second verifier and the GDN snapshots) and its gain depends on the window size, so the default remains `--pipeline-windows 1`. --- sycl/include/strata/core/verify.hpp | 6 +++ sycl/src/core/verify.cpp | 7 +-- sycl/src/program/generate.cpp | 71 +++++++++++++++++++++-------- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/sycl/include/strata/core/verify.hpp b/sycl/include/strata/core/verify.hpp index b38249f4..540323ac 100644 --- a/sycl/include/strata/core/verify.hpp +++ b/sycl/include/strata/core/verify.hpp @@ -205,6 +205,11 @@ public: /// expert evicted on the host (the pool then computes it on the CPU) before the device table follows. Also turns /// the device-planned layers (E-6) off. Before `init`. void set_always_publish(bool on) { always_publish_ = on; } + /// The pipelined windows never let a one-token window advance the state itself: its graph may run *speculatively* + /// (ahead of the previous window's verdict), so a self-commit would land before the state it must build on is + /// final. With this set, record_window does not self-commit and pl_commit_async always queues the commit graph - + /// the configuration that measures token-identical to the serial path. Before `capture_all`. + void set_self_commit_off(bool on) { self_commit_off_ = on; } dpct::queue_ptr stream() const { return cs_; } int device() const { return device_; } /// Capture every window size and the commit graph now (a capture syncs the stream: never with a window in flight). @@ -267,6 +272,7 @@ private: // batch windows (see init_slots) std::vector slots_; bool batch_rec_ = false; ///< record_window is capturing a batch window + bool self_commit_off_ = false; ///< set_self_commit_off: the pipelined windows commit through the graph int row_base_ = 0; ///< ... its hand-off rows start here (a pipeline group's own rows) int brow_[8] = {}; ///< ... and row t is slot brow_[t] bool last_batch_ = false; ///< the last run was a batch window (set_plan_slot: one group) diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cpp index f3aaa208..2811b5a0 100644 --- a/sycl/src/core/verify.cpp +++ b/sycl/src/core/verify.cpp @@ -841,7 +841,8 @@ bool Verifier::record_window(int T, dpct::queue_ptr cs, std::string &err) { const bool ple_on = ss.ple.ready() && ple_stage(); auto Rt = [&](int t) { return R_ + (size_t) t * HC * N; }; const int G = (split_ && T >= 2 && !batch_rec_) ? 2 : 1; // a batch window is one group - const bool self_commit = T == 1 && !batch_rec_ && !g_qfuse() && one_token_self_commit(); // see Verifier::commit + const bool self_commit = T == 1 && !batch_rec_ && !g_qfuse() && one_token_self_commit() && + !self_commit_off_; // see Verifier::commit static const bool dec_batch = [] { const char* v = std::getenv("STRATA_DEC_BATCH"); return v == nullptr || std::atoi(v) != 0; }(); // SYCL port, STRATA_VERIFY_EAGER=1: the window runs on the queue instead of as a graph, and each stage stamp is // a host-side wait + clock (there is no %globaltimer here), so the existing stage profiler reports ms per stage. @@ -2693,7 +2694,7 @@ bool Verifier::commit(int n_keep, std::string &err) try { h_commit_[0] = n_keep; h_commit_[1] = n_keep - 1; for (int t = 0; t < max_t_; ++t) h_commit_[2 + t] = t < n_keep ? (int32_t) (last_pos0_ + t) : -1; - if (last_t_ == 1 && one_token_self_commit()) { + if (last_t_ == 1 && one_token_self_commit() && !self_commit_off_) { // a one-token window has advanced the state itself (record_window): no commit graph } else { std::atomic_thread_fence(std::memory_order_seq_cst); @@ -4009,7 +4010,7 @@ bool Verifier::pl_commit_async(int n_keep, std::string &err) try { // single-token window; the first decode window is always one token, so the two paths' GDN states were // equal after the prompt and different after that window (STRATA_PIPELINE_DUMP), and the tokens diverged // at the fourth. With this skip the pipelined windows are token-identical to the serial path. - if (last_t_ == 1 && one_token_self_commit()) { + if (last_t_ == 1 && one_token_self_commit() && !self_commit_off_) { h_commit_[0] = n_keep; h_commit_[1] = n_keep - 1; for (int t = 0; t < max_t_; ++t) h_commit_[2 + t] = t < n_keep ? (int32_t) (last_pos0_ + t) : -1; diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp index 52eb10c5..3db8caef 100644 --- a/sycl/src/program/generate.cpp +++ b/sycl/src/program/generate.cpp @@ -7279,10 +7279,14 @@ int main(int argc, char **argv) try { for (strata::core::Verifier* v : {&ver, &ver_b}) { v->set_stream(pl_stream[0]); v->set_always_publish(true); + v->set_self_commit_off(true); // a pipelined window may run speculatively: never let it + // advance the state itself, the commit graph always does } for (strata::core::Verifier* v : {&stages[0]->ver, &stages[0]->ver_b}) { v->set_stream(pl_stream[1]); v->set_always_publish(true); + v->set_self_commit_off(true); // a pipelined window may run speculatively: never let it + // advance the state itself, the commit graph always does } } if (n_stages > 1) { @@ -11551,17 +11555,33 @@ int main(int argc, char **argv) try { const size_t n = (size_t) ss.gdn_alloc * (size_t) gdn_floats; std::vector h(n); (void) DPCT_CHECK_ERROR(s0->memcpy(h.data(), ss.gdn_state, n * sizeof(float)).wait()); - uint64_t hs = 1469598103934665603ull; - double sum = 0.0; - for (size_t i = 0; i < n; ++i) { - uint64_t b = 0; - std::memcpy(&b, &h[i], sizeof(float)); - hs = (hs ^ b) * 1099511628211ull; - sum += (double) h[i]; + // the recurrence state and the conv history hashed apart: a wrong row shows which half it is + const size_t n_rec = (size_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size; + const size_t n_cnv = (size_t) g.ssm_conv_channels * (g.ssm_d_conv - 1); + double rec_sum = 0.0, cnv_sum = 0.0; + uint64_t rec_hash = 1469598103934665603ull, cnv_hash = 1469598103934665603ull; + for (int64_t l = 0; l < ss.gdn_alloc; ++l) { + const size_t base = (size_t) l * (size_t) gdn_floats; + uint64_t rh = 1469598103934665603ull, ch = 1469598103934665603ull; + for (size_t i = 0; i < n_rec; ++i) { + uint64_t b = 0; + std::memcpy(&b, &h[base + i], sizeof(float)); + rh = (rh ^ b) * 1099511628211ull; + rec_sum += (double) h[base + i]; + } + for (size_t i = 0; i < n_cnv; ++i) { + uint64_t b = 0; + std::memcpy(&b, &h[base + n_rec + i], sizeof(float)); + ch = (ch ^ b) * 1099511628211ull; + cnv_sum += (double) h[base + n_rec + i]; + } + rec_hash = (rec_hash ^ rh) * 1099511628211ull; + cnv_hash = (cnv_hash ^ ch) * 1099511628211ull; } if (std::FILE* df = std::fopen(pl_dump, "a")) { - std::fprintf(df, "pos %lld windows %lld gdn %zu sum %.9g hash %016llx\n", (long long) p, - (long long) dec_windows, n, sum, (unsigned long long) hs); + std::fprintf(df, "pos %lld windows %lld rec %.9g %016llx cnv %.9g %016llx\n", (long long) p, + (long long) dec_windows, rec_sum, (unsigned long long) rec_hash, cnv_sum, + (unsigned long long) cnv_hash); std::fclose(df); } } @@ -11781,17 +11801,32 @@ int main(int argc, char **argv) try { const size_t n = (size_t) ss.gdn_alloc * (size_t) gf; std::vector h(n); (void) DPCT_CHECK_ERROR(ver.stream()->memcpy(h.data(), ss.gdn_state, n * sizeof(float)).wait()); - uint64_t hs = 1469598103934665603ull; - double sum = 0.0; - for (size_t i = 0; i < n; ++i) { - uint64_t bb = 0; - std::memcpy(&bb, &h[i], sizeof(float)); - hs = (hs ^ bb) * 1099511628211ull; - sum += (double) h[i]; + const size_t n_rec = (size_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size; + const size_t n_cnv = (size_t) g.ssm_conv_channels * (g.ssm_d_conv - 1); + double rec_sum = 0.0, cnv_sum = 0.0; + uint64_t rec_hash = 1469598103934665603ull, cnv_hash = 1469598103934665603ull; + for (int64_t l = 0; l < ss.gdn_alloc; ++l) { + const size_t base = (size_t) l * (size_t) gf; + uint64_t rh = 1469598103934665603ull, ch = 1469598103934665603ull; + for (size_t i = 0; i < n_rec; ++i) { + uint64_t bb = 0; + std::memcpy(&bb, &h[base + i], sizeof(float)); + rh = (rh ^ bb) * 1099511628211ull; + rec_sum += (double) h[base + i]; + } + for (size_t i = 0; i < n_cnv; ++i) { + uint64_t bb = 0; + std::memcpy(&bb, &h[base + n_rec + i], sizeof(float)); + ch = (ch ^ bb) * 1099511628211ull; + cnv_sum += (double) h[base + n_rec + i]; + } + rec_hash = (rec_hash ^ rh) * 1099511628211ull; + cnv_hash = (cnv_hash ^ ch) * 1099511628211ull; } if (std::FILE* df = std::fopen(sd, "a")) { - std::fprintf(df, "pos %lld serial gdn %zu sum %.9g hash %016llx\n", (long long) (p + a + 1), n, - sum, (unsigned long long) hs); + std::fprintf(df, "pos %lld serial rec %.9g %016llx cnv %.9g %016llx\n", (long long) (p + a + 1), + rec_sum, (unsigned long long) rec_hash, cnv_sum, + (unsigned long long) cnv_hash); std::fclose(df); } } From e318f71e75a6019a9912edc8b639cec47c604b42 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 10:38:50 +0100 Subject: [PATCH 13/17] [Engine] SYCL: copy the prompt path's grouping tables instead of reading them from mapped memory Problem: the prompt path's per-layer grouping tables - `[ids | slot | src]`, T x K int32s each, ~245 KB per layer at a 2,048-token chunk - live in mapped pinned host memory, and on the mapped arm the GPU reads them there, once per layer. On a PCIe-attached pair that is 48 rounds of host-memory reads per chunk, and the port already carried the A/B arm to copy them instead (`STRATA_GROUP_COPY=1`) without a measurement deciding between them. Result, 2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, `--pipeline-windows 2`, three warm repetitions, same build, back to back: | case | mapped arm | copy arm | gain | | --- | ---: | ---: | ---: | | prefill 4,106 tokens (AOT) | 1,303.2-1,303.5 tok/s | **1,332.8-1,337.5** | +2.5% | | prefill 16,380 tokens (AOT) | 1,617.8-1,622.7 | **1,657.2-1,665.2** | +2.5% | | prefill 10,938 chat prompt (AOT) | 1,575.6-1,578.4 | **1,613.8-1,616.8** | +2.5% | | decode, chat prompt, 128 tokens | 74.9 / 75.6 | 74.9 / 75.6 | unchanged | Approach: the default flips to the copy arm for this port; `STRATA_GROUP_COPY=0` restores the mapped one. Both arms allocate nothing new when the buffer is already big enough, and the copy arm reuses the host vectors the code already keeps for exactly this. Validation: the token stream is identical between the two arms at both prompt sizes and on the decode run (`scripts/compare_tokens.py`: first difference none), and identical to the pre-change reference (the rc-p16k run of round 42). Not run: CUDA/HIP (the file is the port's own copy), a host-shared-memory device (an iGPU, where the mapped arm may be the better one - hence the switch), a 32K prompt. Limits: +2.5% on prefill only; the decode path does not use these tables. --- sycl/src/prefill/prefill.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sycl/src/prefill/prefill.cpp b/sycl/src/prefill/prefill.cpp index 20b04cd5..8206fb61 100644 --- a/sycl/src/prefill/prefill.cpp +++ b/sycl/src/prefill/prefill.cpp @@ -1293,8 +1293,13 @@ bool Prefill::init(const core::WeightTable &wt, const core::ModelGeometry &g, m.ids_host.resize(T * K); m.slot_host.resize(T * K); m.src_host.resize(T * K); m.cnt.resize(m.g->n_expert); m.off.resize(m.g->n_expert + 1); { const size_t need = 3 * T * K + (size_t) (2 * (m.g->n_expert + m.g->n_expert / MMQ_GROUP + 2)); + // SYCL port: the *copy* arm is the default. On the mapped arm the GPU reads these tables straight out of + // mapped host memory, per layer; copying them first is measurably faster on a PCIe-attached pair and + // token-identical - 4,106 tokens 1,303 -> 1,335 tok/s, 16,380 tokens 1,622 -> 1,665, the 10,938-token chat + // prompt 1,576 -> 1,617, decode unchanged (round 46). STRATA_GROUP_COPY=0 restores the mapped arm. const char* gc = std::getenv("STRATA_GROUP_COPY"); - if (m.grp_n < need && !(gc && gc[0] == '1')) { + const bool group_copy = gc == nullptr || gc[0] != '0'; + if (m.grp_n < need && !group_copy) { if (m.grp_host) sycl::free(m.grp_host, dpct::get_in_order_queue()); m.grp_host = m.grp_dev = nullptr; m.grp_n = m.grp_tk = 0; From 89253935db3262e8322a565062ed175e7dc15e60 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 14:53:18 +0100 Subject: [PATCH 14/17] [Engine] SYCL: refuse a --mtp-q4 draft head when the Q6_K head is stored as planes Problem: `--mtp-q4 head` builds the Q4_0 draft head by gathering the subset and dequantizing it row by row, but with `STRATA_Q6_PLANAR` (the SYCL port's default for Q6_K heads) the source is stored as 16-byte-aligned planes and the gather copies planes as if they were rows. The result is a draft head that proposes nothing at all, with no error: decode falls from 73.8-75.6 tok/s to 35.3 tok/s (the non-speculative rate) and the DONE line reports "0 of 0" drafts. Result, 2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, 128 tokens of a 483-token chat prompt, one warm request each: | configuration | decode | drafts | | --- | ---: | --- | | `--mtp-q4 head`, planar head (before) | 35.3 tok/s | 0 of 0 | | `--mtp-q4 head`, planar head (after) | refused with "needs the packed Q6_K head layout (STRATA_Q6_PLANAR=0)" | - | | `--mtp-q4 head` with `STRATA_Q6_PLANAR=0` | 69.5 tok/s | 54 of 63 | | default head (no `--mtp-q4`) | 74.9 / 75.6 tok/s | 55 of 63 | Approach: a guard in `make_q4_head` that refuses the option when the head really is planar, so the engine says why instead of running with speculation silently disabled. The packed-layout path is unchanged and still works, which is what the measurement above shows. Validation: the guard message appears in the engine's own output; `--mtp-q4 head` with the packed layout still produces 54 of 63 drafts; the default path's tokens are identical to the pre-change reference (`compare_tokens.py`, no difference) and its rate is unchanged. Not run: CUDA/HIP (the file is the port's own copy and the guard is behind `STRATA_NATIVE_EXPERTS`), a non-Q6_K head, `--batch-mtp`. Limits: this makes a broken opt-in fail loudly; it does not make the 4-bit head fast. With the packed layout it is *slower* than the Q6_K head (69.5 against 74.9), so the option is still not worth enabling. --- sycl/src/core/mtp.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sycl/src/core/mtp.cpp b/sycl/src/core/mtp.cpp index 5fff80b0..fd3fec62 100644 --- a/sycl/src/core/mtp.cpp +++ b/sycl/src/core/mtp.cpp @@ -233,6 +233,14 @@ bool MtpDrafter::make_q4_head(std::string& err) { const int64_t N = g_->n_embd; const auto* tt = ggml_get_type_traits((ggml_type) head_->type()); if (tt == nullptr || tt->to_float == nullptr || N % 32 != 0) { err = "mtp: --mtp-q4 cannot read the head's format"; return false; } + // SYCL port: with STRATA_Q6_PLANAR the head is stored as planes, and the subset this builds from is row-major + // only when the head is packed - the gather at load time then copies planes as if they were rows. The result is + // a draft head that proposes nothing at all (measured: 0 drafts, decode 73.8 -> 35.3 tok/s) with no error, so + // refuse instead of running wrong in silence. + if (head_->type() == 14 && strata::kernels::native_q6_k_is_planar(head_->weights())) { + err = "mtp: --mtp-q4 head needs the packed Q6_K head layout (STRATA_Q6_PLANAR=0)"; + return false; + } const size_t in_row = head_->row_bytes(), out_row = (size_t) (N / 32) * 18; std::vector src((size_t) n_dvocab_ * in_row), dst((size_t) n_dvocab_ * out_row); try { dpct::get_in_order_queue().memcpy(src.data(), dhead_, src.size()).wait(); } // SYCL port: cudaMemcpy From 8475011ac1e37760bde91135ff23c3c6584d4c9e Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 15:58:42 +0100 Subject: [PATCH 15/17] [Engine] SYCL: native_expert_bench refuses to time a launch that wrote nothing Problem: the bench fills its output with 0xff and then compares the mode against the reference, so a launch that returns without enqueueing leaves both sides bitwise equal on an untouched buffer and the tool reports "0 differing" and a 0.1 us timing - a measurement of nothing that looks like a very fast kernel. The 0xff fill is NaN as a float, so "no finite value in the reference window" is exactly that case. Result, 2x Arc Pro B65, shard 1 layer 20 (`iq3_xxs/q2_0`, 10 groups, 2 tokens): the guard does *not* fire - the window does write finite values, so this defect is not what makes the timing wrong. The timing is still 0.1 us per launch against a 19.7 MB working set (0.3 us at 8 tokens), which scales with work but is 20-60x too fast for the launch to be waited for; the remaining cause is in the timing loop's wait, not in the launch. That stays an open port item. Approach: the guard only refuses and reports; it changes no timing path and no kernel. Validation: builds and runs on the box; the run above is the only one taken. Not run: CUDA/HIP (this file is the port's own), and the timing itself is still unproven - do not use its numbers. Limits: this is a diagnostic, not the fix. `native_expert_bench` numbers remain unusable until the wait is found. --- sycl/src/kernels/native_expert_bench.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sycl/src/kernels/native_expert_bench.cpp b/sycl/src/kernels/native_expert_bench.cpp index 1c1b6566..c75726c9 100644 --- a/sycl/src/kernels/native_expert_bench.cpp +++ b/sycl/src/kernels/native_expert_bench.cpp @@ -135,6 +135,23 @@ int main(int argc, char** argv) { if (!sync("reference window")) return 1; s->memcpy(ref.data(), dout, ref.size() * 4).wait(); + // SYCL port: a launch that returns without enqueueing leaves the 0xff fill intact, and then the mode and the + // reference agree bitwise on an untouched buffer - a "0 differing" that measures nothing. The fill is NaN as + // a float, so a reference window with no finite value anywhere did no work: say so instead of timing it. + { + size_t written = 0; + for (size_t i = 0; i < ref.size(); ++i) { + float v; + std::memcpy(&v, &ref[i], 4); + if (std::isfinite(v)) ++written; + } + if (written == 0) { + std::printf("layer %d: the expert launch wrote nothing (%zu outputs, none finite) - refusing to time it\n", + (int) l, ref.size()); + ++failures; + continue; + } + } s->memset(dout, 0xff, got.size() * 4).wait(); run(mode, 0); if (!sync("mode window")) return 1; From 6124c35e39e65aa73740821eeeebbe4871a80ed3 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 28 Oct 2026 16:00:39 +0100 Subject: [PATCH 16/17] [Engine] SYCL: native_expert_bench reports microseconds, not milliseconds Problem: the timing lambda measured milliseconds per iteration and returned them, while the printout labels the value "us" and derives its GB/s as `bytes / us / 1e3` - so every number this bench has printed was 1000x too small in time and 1000x too large in bandwidth. A launch that moves 19.7 MB in ~140 us was reported as 0.1 us and 148,713 GB/s, which is why the tool looked broken rather than mislabelled. The wall clock always agreed with the real work (200 iterations 618 ms, 2,000 iterations 3,566 ms). Result, 2x Arc Pro B65, shard 1 (Qwen3.8-Flash-Next IQ3_S experts, 10 groups), before and after the one-line fix: | case | before | after | | --- | ---: | ---: | | 2 tokens | 0.1 "us", 148,713 "GB/s" | **143.4 us: gate/up 84.5 us (148 GB/s), down 59.4 us (78 GB/s)** | | 8 tokens | 0.3 "us" | **340.8 us: gate/up 217.4 us (58 GB/s), down 126.0 us (37 GB/s)** | and the model's own layers at two tokens: layer 30 iq3_xxs/q2_0 143.6 us, 31 iq3_xxs/iq4_nl 140.4 us, 32 iq2_s/iq4_nl 135.5 us, 33 iq3_xxs/iq4_nl 140.2 us - gate/up 131-149 GB/s, down 78-168 GB/s, results bitwise equal to the reference in every case. Approach: return microseconds (`ms * 1e3 / iters`), which is what the printout, the minimum-of-three logic and the bandwidth formula already assume. No kernel, no timing path and no measurement logic changed. Validation: the same run before and after; the wall-clock scaling that exposed the bug; bitwise equality retained in all four model layers and both token counts. Not run: CUDA/HIP (this file is the port's own), other shards. Limits: this fixes the units only. The numbers are per-call costs with the bench's own synthetic groups, so a rate taken from it still has to be matched to the real window (48 calls per layer step). --- sycl/src/kernels/native_expert_bench.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sycl/src/kernels/native_expert_bench.cpp b/sycl/src/kernels/native_expert_bench.cpp index c75726c9..a32d8116 100644 --- a/sycl/src/kernels/native_expert_bench.cpp +++ b/sycl/src/kernels/native_expert_bench.cpp @@ -171,7 +171,12 @@ int main(int argc, char** argv) { sync("timing loop"); const double ms = std::chrono::duration(std::chrono::steady_clock::now() - t0).count(); - return ms / iters; + // SYCL port: the printout below and the GB/s it derives both assume MICROseconds ("all %7.1f us", + // bytes / us / 1e3), but this returned milliseconds - so every published number was 1000x too small in + // time and 1000x too large in bandwidth (0.1 "us" and 148,713 GB/s for a launch that takes ~100 us and + // moves 19.7 MB at ~198 GB/s). The wall clock always agreed with the real work: 200 iterations 618 ms, + // 2,000 iterations 3,566 ms. Return microseconds. + return ms * 1e3 / iters; }; const double gu_b = (double) G * 2 * f.up_off, d_b = (double) G * dsz; double us[2][3] = {{1e30, 1e30, 1e30}, {1e30, 1e30, 1e30}}; From f2bf7a3ce3cc062567e4b433202696511eb18e92 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 29 Oct 2026 12:47:50 +0100 Subject: [PATCH 17/17] [Engine] SYCL: the lane-cell prompt attention default is for Battlemage (Xe2) cards only On an Arc A750 the lane-cell score phase read a 4,106-token prompt 0.7% slower than the unchanged kernel (three interleaved runs against the published 0.1.52 engine; with STRATA_ATTN_LANECELL=0 the branch matched it), while it is +5% on the Arc Pro B65. The default now follows strata::intel_gpu_gen(): the runtime's architecture enum first, the device name only as a fallback. STRATA_ATTN_LANECELL=1/0 still forces either way on any device. --- sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp b/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp index 9caef220..18abd96a 100644 --- a/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp +++ b/sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp @@ -668,12 +668,18 @@ void qsa_decode_attn_batch(const float* q, const QsaAttnPools& pools, const int3 // S25: the score phase one cell per thread (bit-identical scores, no shuffle reductions). Prompt batches take // it by default: on 2x Arc Pro B65 it reads a 4,106-token prompt 5.2% faster, 8,191 tokens 5.2% and 16,380 // tokens 4.8%, with the same tokens; the decode window's few queries per call are 1.4% slower with it (56.6-57.0 - // against 55.9-56.3 tok/s), so the choice follows the query count. STRATA_ATTN_LANECELL=1/0 forces either way. + // against 55.9-56.3 tok/s), so the choice follows the query count. It is a Battlemage (Xe2) default only: on an Arc + // A750 (Alchemist) the same switch reads a 4,106-token prompt 0.7% slower (three interleaved runs, 4 of 5 pairs + // faster with it off), so the generation comes from the device's architecture id (strata::intel_gpu_gen: the + // runtime's architecture enum first, the name only as a fallback), never from the name alone. + // STRATA_ATTN_LANECELL=1/0 forces either way on any device. static const int lane_cell_env = [] { const char* v = std::getenv("STRATA_ATTN_LANECELL"); return v != nullptr && v[0] != '\0' ? std::atoi(v) : -1; }(); - const bool lane_cell = lane_cell_env >= 0 ? lane_cell_env != 0 : n_q >= 16; + const bool lane_cell = lane_cell_env >= 0 + ? lane_cell_env != 0 + : (n_q >= 16 && strata::intel_gpu_gen(st->get_device()) == strata::IntelGpuGen::Battlemage); #define STRATA_ATTN_LC(M) \ { \ auto exp_props = sycl::ext::oneapi::experimental::properties{ \