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: fill big device arenas with chunked kernels, not one queue.memset
Niko12216d1cb3a65727
diff --git a/sycl/include/strata/sycl_queue.hpp b/sycl/include/strata/sycl_queue.hppindex 6df9898a8..b272efb77 100644--- a/sycl/include/strata/sycl_queue.hpp+++ b/sycl/include/strata/sycl_queue.hpp@@ -12,3 +12,26 @@ inline sycl::queue* q_of(const void* stream) {return stream ? (sycl::queue*) stream : &dpct::get_in_order_queue();}} // namespace strata++namespace strata {+// A large device fill as compute kernels of at most `chunk` bytes, each waited for. On the Arc Pro B70 (xe driver) one+// queue.memset of many GiB runs on the blitter engine and times out ("Engine memory CAT error", GT reset); kernels do not.+// Small fills (<= chunk) and non-multiple-of-8 tails fall back to memset.+inline void big_fill_zero(sycl::queue& q, void* p, size_t bytes, size_t chunk = (size_t)256 << 20) {+ uint8_t* b = (uint8_t*)p;+ size_t off = 0;+ while (off < bytes) {+ size_t n = bytes - off < chunk ? bytes - off : chunk;+ if (n >= (1u << 20) && ((uintptr_t)(b + off) & 7) == 0) {+ size_t w = n / 8;+ uint64_t* d = (uint64_t*)(b + off);+ q.parallel_for(sycl::range<1>(w), [=](sycl::id<1> i) { d[i] = 0; });+ if (n & 7) q.memset(b + off + w * 8, 0, n & 7);+ } else {+ q.memset(b + off, 0, n);+ }+ q.wait();+ off += n;+ }+}+} // namespace stratadiff --git a/sycl/src/core/expert_cache.cpp b/sycl/src/core/expert_cache.cppindex fe5c7d0a4..cd1d50dbc 100644--- a/sycl/src/core/expert_cache.cpp+++ b/sycl/src/core/expert_cache.cpp@@ -618,7 +618,7 @@ bool ExpertCache::open(int64_t n_slots, int64_t n_layers, int64_t n_expert, int6// Zeroed so a slot read before it is filled is a DETERMINISTIC wrong answer rather than whatever the// allocator handed back. A stale block of a previous process's memory would still sum to finite floats.if (DPCT_CHECK_ERROR(- dpct::get_in_order_queue().memset(base_, 0, (size_t)want).wait()) !=+ (strata::big_fill_zero(dpct::get_in_order_queue(), base_, (size_t)want), 0)) !=0) {err = "ExpertCache: cudaMemset of the slot arena failed";close();diff --git a/sycl/src/core/layer.cpp b/sycl/src/core/layer.cppindex 2ce1aa479..32a02253e 100644--- a/sycl/src/core/layer.cpp+++ b/sycl/src/core/layer.cpp@@ -987,29 +987,29 @@ void qsa_state_zero(const QsaState& st, const ModelGeometry& g, void* stream) {const int64_t live_slots = st.kv_elastic >= 0 ? pool_slots_mapped(*g_pools[(size_t) st.kv_elastic]) : st.n_slots;const size_t rows = (size_t) live_slots * s.n_head_kv * s.page_size;if (st.kv_hybrid) {- cs->memset(st.k_q, 0, rows * s.head_dim);- cs->memset(st.k_scale, 0,+ strata::big_fill_zero(*cs, st.k_q, rows * s.head_dim);+ strata::big_fill_zero(*cs, st.k_scale,rows * (s.head_dim / strata::kernels::KV_Q8_GROUP) * 2);- cs->memset(st.v_q4, 0,+ strata::big_fill_zero(*cs, st.v_q4,rows *strata::kernels::kv_q4_bytes_per_head((int)s.head_dim));} else if (st.kv_q4) {- cs->memset(st.k_q4, 0,+ strata::big_fill_zero(*cs, st.k_q4,rows *strata::kernels::kv_q4_bytes_per_head((int)s.head_dim));- cs->memset(st.v_q4, 0,+ strata::big_fill_zero(*cs, st.v_q4,rows *strata::kernels::kv_q4_bytes_per_head((int)s.head_dim));} else if (st.kv_int8) {- cs->memset(st.k_q, 0, rows * s.head_dim);- cs->memset(st.v_q, 0, rows * s.head_dim);- cs->memset(st.k_scale, 0,+ strata::big_fill_zero(*cs, st.k_q, rows * s.head_dim);+ strata::big_fill_zero(*cs, st.v_q, rows * s.head_dim);+ strata::big_fill_zero(*cs, st.k_scale,rows * (s.head_dim / strata::kernels::KV_Q8_GROUP) * 2);- cs->memset(st.v_scale, 0,+ strata::big_fill_zero(*cs, st.v_scale,rows * (s.head_dim / strata::kernels::KV_Q8_GROUP) * 2);} else {- cs->memset(st.k_pool, 0, rows * s.head_dim * 2);- cs->memset(st.v_pool, 0, rows * s.head_dim * 2);+ strata::big_fill_zero(*cs, st.k_pool, rows * s.head_dim * 2);+ strata::big_fill_zero(*cs, st.v_pool, rows * s.head_dim * 2);}// A streamed state starts over with nothing resident. Its host copy is not cleared (GBs over PCIe per new// conversation): no reader names a cell before this sequence has written it, and a block copied in wholediff --git a/sycl/src/core/mtp.cpp b/sycl/src/core/mtp.cppindex aa2fa6703..56eaed0e2 100644--- a/sycl/src/core/mtp.cpp+++ b/sycl/src/core/mtp.cpp@@ -2,6 +2,7 @@#define DPCT_PROFILING_ENABLED#include <sycl/sycl.hpp>#include <dpct/dpct.hpp>+#include "strata/sycl_queue.hpp"#include "strata/core/mtp.hpp"#include "strata/core/coupled_draft.hpp"#include "strata/core/on_device.hpp"@@ -468,7 +469,7 @@ bool MtpDrafter::load(const std::string &rt_dir, const ModelGeometry &g,count.used, dpct::get_in_order_queue())) != 0) {err = "mtp: buffers do not fit"; return false;}- dpct::get_in_order_queue().memset(arena_, 0, count.used).wait();+ strata::big_fill_zero(dpct::get_in_order_queue(), arena_, count.used);Bump real;real.base = (uint8_t*) arena_;carve(real);diff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cppindex 5ad44bd2e..f0fc2a2e4 100644--- a/sycl/src/core/verify.cpp+++ b/sycl/src/core/verify.cpp@@ -2,6 +2,7 @@#define DPCT_PROFILING_ENABLED#include <sycl/sycl.hpp>#include <dpct/dpct.hpp>+#include "strata/sycl_queue.hpp"#include "strata/core/verify.hpp"#include "strata/core/remote_expert_opt.hpp"#include "strata/core/dma_batch.hpp"@@ -529,7 +530,7 @@ bool Verifier::init(const WeightTable &wt, const ModelGeometry &g,err = "verify: the device arena (" + std::to_string(count.used >> 20) + " MiB) does not fit";return false;}- dpct::get_in_order_queue().memset(arena_, 0, count.used).wait();+ strata::big_fill_zero(dpct::get_in_order_queue(), arena_, count.used);if (g_trace && trace_h_ == nullptr) { // #649: the breadcrumbs, mapped so they read while the GPU hangstrace_n_ = (size_t) (g.n_layers + 1) * kProfPer * 2;if (!mapped(trace_n_ * 8, (void**) &trace_h_, (void**) &trace_m_)) {