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: fused multi-token router for 256 experts (was 512-only); 16.95 tok/s decode
maxfridbe8b804379ccb3
diff --git a/sycl/include/strata/kernels/native_router.hpp b/sycl/include/strata/kernels/native_router.hppnew file mode 100644index 000000000..4edfea614--- /dev/null+++ b/sycl/include/strata/kernels/native_router.hpp@@ -0,0 +1,21 @@+#pragma once+#include <cstdint>++namespace strata::kernels {+// Configure before session capture. Existing graphs retain their selected kernels.+// This experiment is off by default and does not modify the legacy router.+void native_router_set_enabled(bool enabled);+bool native_router_enabled();++// Pinned CUDA topk-moe contract for ONE token, 512 experts, top 10, softmax,+// no selection bias, lower normalization clamp 2^-14, and scale 1.+// Reads 512 finite F32 logits; writes 10 I32 IDs and 10 F32 weights. Equal+// computed probabilities select the lower expert index. All spans must be+// four-byte aligned and outputs disjoint from each other and the input.+// Requires a nonnull ordered CUDA stream. No allocation or synchronization.+void native_router_top10(const float* logits, int32_t* ids, float* weights, void* stream);+/// n_tok rows at once (logits [n,512], ids/weights [n,10]); each row exactly as the single call.+void native_router_top10_multi(const float* logits, int32_t* ids, float* weights, int n_tok, void* stream);+/// SYCL port: the same for 256 experts (the Coder) as well as 512; logits [n, n_expert].+void native_router_top10_multi_ne(const float* logits, int32_t* ids, float* weights, int n_tok, int n_expert, void* stream);+}diff --git a/sycl/src/core/layer.cpp b/sycl/src/core/layer.cppindex 5e68553c3..15fabdb00 100644--- a/sycl/src/core/layer.cpp+++ b/sycl/src/core/layer.cpp@@ -405,8 +405,8 @@ if (!native_bf16_projections) f32_to_bf16_bulk(x, b.x_bf16, g.n_embd, stream);project_bf16(x, b.x_bf16, (const uint16_t*) w_router->data, b.logits, g.n_embd, g.n_expert, true, stream);// ---- routing: softmax over ALL experts, stable descending argsort with ties by index, gather, renormalise// the native fused router is canonical-512x10 only; anything else takes the generic top-k kernel-if (native_router_enabled() && g.n_expert == 512 && k == 10) {- try { native_router_top10(b.logits, b.ids, b.weights, stream); }+if (native_router_enabled() && (g.n_expert == 512 || g.n_expert == 256) && k == 10) { // SYCL port: 256 too+ try { native_router_top10_multi_ne(b.logits, b.ids, b.weights, 1, (int) g.n_expert, stream); }catch (const std::exception& error) { err = v.name("router") + ": " + error.what(); return false; }} else router_top10(b.logits, 1, (int) g.n_expert, (int) k, b.ids, b.weights, stream);// ---- THE DOORBELL, AND IT IS THE WHOLE POINT OF THE PROTOCOL. The routed experts' INPUT (`x`) and thediff --git a/sycl/src/core/verify.cpp b/sycl/src/core/verify.cppindex 6a4cf2ed7..02d2af224 100644--- a/sycl/src/core/verify.cpp+++ b/sycl/src/core/verify.cpp@@ -685,11 +685,11 @@ bool Verifier::record_window(int T, dpct::queue_ptr cs, std::string &err) {// the window's rows routed in 2 launches (one router GEMV reading the weight once, one// top-10) instead of 2 per token; every row's arithmetic is the single-token call's (STRATA_DEC_BATCH=0: old)const WeightRef* w_router = v.get("ffn_gate_inp.weight");- if (dec_batch && n > 1 && w_router != nullptr && native_router_enabled() && NE == 512 && K == 10) {- try {+ if (dec_batch && n > 1 && w_router != nullptr && native_router_enabled() && (NE == 512 || NE == 256) && K == 10) {+ try { // SYCL port: the fused multi-token router for 256 experts as well (it was 512-only)bf16_gemv_fp32_mmvf_multi(mixed_ + tb * N, N, (const uint16_t*) w_router->data, logits_ + tb * NE, NE, N,NE, n, cs);- native_router_top10_multi(logits_ + tb * NE, ids_ + tb * K, w_ + tb * K, n, cs);+ native_router_top10_multi_ne(logits_ + tb * NE, ids_ + tb * K, w_ + tb * K, n, (int) NE, cs);} catch (const std::exception& e) { err = "verify router: " + std::string(e.what()); return false; }} elsefor (int t = tb; t < te; ++t) {diff --git a/sycl/src/kernels/cuda/native_router.dp.cpp b/sycl/src/kernels/cuda/native_router.dp.cppindex 4be5d9bde..fe28562c1 100644--- a/sycl/src/kernels/cuda/native_router.dp.cpp+++ b/sycl/src/kernels/cuda/native_router.dp.cpp@@ -67,34 +67,35 @@ exceeds 128 bytes and may cause high register pressure. Consult with yourhardware vendor to find the total register size available and adjust the code,or use smaller sub-group size to avoid high register pressure.*/+template <int NE> // SYCL port: 512 (canonical) or 256 (the Coder) experts, 32 lanes x NE/32 values__dpct_inline__ void route(const float *__restrict__ logits,int32_t *__restrict__ ids,float *__restrict__ weights) {// Preserve the pinned 32x8 block geometry; only row zero is active here.// blockIdx.x = the token (a multi-token launch; 0 for the single one)auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();- logits += (size_t)item_ct1.get_group(2) * 512;+ logits += (size_t)item_ct1.get_group(2) * NE;ids += (size_t)item_ct1.get_group(2) * 10;weights += (size_t)item_ct1.get_group(2) * 10;if (item_ct1.get_local_id(1) != 0) return;const int lane = item_ct1.get_local_id(2);- float values[16];+ float values[NE / 32];#pragma unroll- for (int i = 0; i < 16; ++i) values[i] = logits[lane + i * 32];+ for (int i = 0; i < NE / 32; ++i) values[i] = logits[lane + i * 32];item_ct1.barrier(sycl::access::fence_space::local_space);float maximum = -INFINITY;#pragma unroll- for (int i = 0; i < 16; ++i) maximum = sycl::max(maximum, values[i]);+ for (int i = 0; i < NE / 32; ++i) maximum = sycl::max(maximum, values[i]);maximum = warp_max(maximum);float sum = 0.0f;#pragma unroll- for (int i = 0; i < 16; ++i) {+ for (int i = 0; i < NE / 32; ++i) {values[i] = sycl::native::exp(values[i] - maximum);sum += values[i];}const float reciprocal = 1.0f / warp_sum(sum);#pragma unroll- for (int i = 0; i < 16; ++i) {+ for (int i = 0; i < NE / 32; ++i) {values[i] *= reciprocal;if (sycl::isnan(values[i])) values[i] = -FLT_MAX;}@@ -103,7 +104,7 @@ __dpct_inline__ void route(const float *__restrict__ logits,float best = values[0];int expert = lane;#pragma unroll- for (int i = 1; i < 16; ++i) {+ for (int i = 1; i < NE / 32; ++i) {if (values[i] > best) { best = values[i]; expert = lane + i * 32; }}#pragma unroll@@ -165,7 +166,7 @@ void native_router_top10(const float* logits, int32_t* ids, float* weights, voidexp_props,[=](sycl::nd_item<3> item_ct1)[[sycl::reqd_sub_group_size(32)]] {- route(logits, ids, weights);+ route<512>(logits, ids, weights);});}/*@@ -205,7 +206,7 @@ void native_router_top10_multi(const float* logits, int32_t* ids, float* weightsexp_props,[=](sycl::nd_item<3> item_ct1)[[sycl::reqd_sub_group_size(32)]] {- route(logits, ids, weights);+ route<512>(logits, ids, weights);});}/*@@ -229,4 +230,15 @@ void native_router_top10_multi(const float* logits, int32_t* ids, float* weightsif (error !=0) throw std::runtime_error(dpct::get_error_string_dummy(error));}++void native_router_top10_multi_ne(const float* logits, int32_t* ids, float* weights, int n_tok, int n_expert, void* stream) {+ if (n_expert == 512) { native_router_top10_multi(logits, ids, weights, n_tok, stream); return; }+ if (!stream || n_tok < 1 || n_expert != 256 || !valid(logits, (size_t) n_tok * 256 * 4) || !valid(ids, (size_t) n_tok * 10 * 4) ||+ !valid(weights, (size_t) n_tok * 10 * 4))+ throw std::invalid_argument("native router (multi, 256): a stream, 256 experts and aligned [n,256]/[n,10] buffers");+ ((sycl::queue *)(strata::q_of(stream)))+ ->parallel_for<dpct_kernel_name<class route_256_multi>>(+ sycl::nd_range<3>(sycl::range(1, 1, (unsigned) n_tok) * sycl::range(1, 8, 32), sycl::range(1, 8, 32)),+ [=](sycl::nd_item<3> item_ct1) [[sycl::reqd_sub_group_size(32)]] { route<256>(logits, ids, weights); });+}}diff --git a/sycl/tools/Dockerfile.unitrace b/sycl/tools/Dockerfile.unitracenew file mode 100644index 000000000..586c75c3e--- /dev/null+++ b/sycl/tools/Dockerfile.unitrace@@ -0,0 +1,8 @@+# strata-sycl-dev + Intel pti-gpu unitrace (per-kernel Level Zero profiling). Build:+# docker build -t strata-sycl-dev:unitrace -f sycl/tools/Dockerfile.unitrace sycl/tools+FROM strata-sycl-dev+RUN . /opt/intel/oneapi/setvars.sh --force >/dev/null 2>&1; \+ git clone --depth 1 https://github.com/intel/pti-gpu.git /opt/pti-gpu && \+ cd /opt/pti-gpu/tools/unitrace && mkdir build && cd build && \+ cmake -DCMAKE_BUILD_TYPE=Release .. >/dev/null && make -j"$(nproc)" >/dev/null 2>&1 && ./unitrace --version+ENV PATH=/opt/pti-gpu/tools/unitrace/build:$PATH