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: SIMD16 variants of the decode mmvq kernels (opt-in STRATA_MMVQ_SG), mmvq_sg_bench

maxfridbee7c42b62b969
diff --git a/docs/INTEL.md b/docs/INTEL.md
index c961b89da..57a0acf98 100644
--- a/docs/INTEL.md
+++ b/docs/INTEL.md
@@ -368,6 +368,12 @@ runtime's teardown began); it now exits directly once its requests are done.
31 tok/s (from 4-5).
4. QSA block selection on XMX: every query against every pooled block, a dense product that grows with the context.
5. The hot decode kernels re-tuned for Xe2's native 16-wide sub-groups (twice the registers per thread).
+ **Tried, no gain**: SIMD16 builds of the multi-column mmvq and the wide Q6_K kernel (`STRATA_MMVQ_SG`: 16 all,
+ 1 IQ4_XS only, 2 short outputs only; default 32). Alone (`mmvq_sg_bench`) SIMD16 is up to 1.45x faster on IQ4_XS
+ and 1.3x on the 640-row shared-expert projections, 10-25% slower on the large K-quant ones; in the engine no
+ setting beats SIMD32 beyond run-to-run noise (SIMD32 itself lands at 39 or 45 tok/s). Output tokens identical.
+ The same bench shows the real headroom: the dense decode kernels stream 100-280 GB/s of a 608 GB/s card
+ (Q6_K, the most common type, ~146 GB/s at 2-4 columns).
6. INT8 prompt GEMMs: experts dequantized to INT8, oneMKL/oneDNN INT8 on XMX (half the dequant bytes, 2x rate).
7. Fewer graph nodes per decode round (~2,500 at ~5 us): norm+rope, scores+top-k, gate+quantize fused.
8. Wider speculation (two draft branches per verify window): the kernels are latency-bound, so it is nearly free.
diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt
index 682a6ed68..f4392de3e 100644
--- a/sycl/CMakeLists.txt
+++ b/sycl/CMakeLists.txt
@@ -193,6 +193,8 @@ if(STRATA_SYCL_PARITY)
target_link_libraries(kv_hybrid_parity PRIVATE strata_kernels)
add_executable(mmvq_bench ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/mmvq_bench.cpp) # dense mmvq timing
target_link_libraries(mmvq_bench PRIVATE strata_kernels)
+ add_executable(mmvq_sg_bench ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/mmvq_sg_bench.cpp) # SIMD16 vs 32 decode mmvq
+ target_link_libraries(mmvq_sg_bench PRIVATE strata_kernels)
add_executable(xmx_gemm_bench ${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/xmx_gemm_bench.cpp) # XMX quantized GEMM vs dequant+oneMKL
target_link_libraries(xmx_gemm_bench PRIVATE strata_kernels strata_prefill) # -qmkl for the oneMKL reference
# one native expert three ways on real GGUF rows (ggml reference, CPU path, GPU native_expert_grouped):
diff --git a/sycl/src/kernels/cuda/native_mmvq.dp.cpp b/sycl/src/kernels/cuda/native_mmvq.dp.cpp
index 3d05318d6..8abf24759 100644
--- a/sycl/src/kernels/cuda/native_mmvq.dp.cpp
+++ b/sycl/src/kernels/cuda/native_mmvq.dp.cpp
@@ -35,6 +35,7 @@
#include <cstdlib>
#include <limits>
#include <stdexcept>
+#include <type_traits>
#include <string>
#include <cmath>
@@ -142,6 +143,25 @@ __dpct_inline__ float warp_sum(float x) {
return x;
}
+template <int SG> __dpct_inline__ float sg_sum(float x) { // SYCL port: warp_sum for a SG-wide sub-group
+#pragma unroll
+ for (int offset = SG / 2; offset > 0; offset >>= 1)
+ x += sycl::permute_group_by_xor(sycl::ext::oneapi::this_work_item::get_sub_group(), x, offset);
+ return x;
+}
+// SYCL port: the decode mmvq kernels as Xe2-native SIMD16 sub-groups (twice the registers per lane, same 128
+// threads per group) or as the CUDA-shaped 32-lane warp (default). STRATA_MMVQ_SG: 16 = all SIMD16, 1 = IQ4_XS
+// only, 2 = short outputs (n_out <= 1024) only, 3 = both. mmvq_sg_bench alone: SIMD16 wins on IQ4_XS (up to
+// 1.45x) and short outputs (up to 1.3x), loses 10-25% on the large K-quant projections.
+inline int mmvq_sg() {
+ static const int v = std::getenv("STRATA_MMVQ_SG") ? std::atoi(std::getenv("STRATA_MMVQ_SG")) : 32;
+ return v;
+}
+inline bool mmvq_sg16(bool iq4xs, int n_out) {
+ const int v = mmvq_sg();
+ return v == 16 || ((v & 1) && v < 4 && iq4xs) || ((v & 2) && v < 4 && n_out <= 1024);
+}
+
__dpct_inline__ float warp_max(float x) {
#pragma unroll
for (int offset = WARP / 2; offset > 0; offset >>= 1) {
@@ -1181,7 +1201,7 @@ struct SmallTraits {
// equal to ncols = 1 only to float rounding (the cross-warp reduction groups partial sums differently).
bool g_multi_exact = true; // until the upstream layout is timed on an idle GPU (plan rule: default only what is measured)
-template <typename F, int NCOLS, int NW, int ROWS>
+template <typename F, int NCOLS, int NW, int ROWS, int SG = WARP>
/*
DPCT1110: The total declared local variable size in device function
native_mmvq_multi_kernel exceeds 128 bytes and may cause high register pressure.
@@ -1194,9 +1214,9 @@ native_mmvq_multi_kernel(const typename F::Block *__restrict__ w,
int n_in, int n_out) {
auto item_ct1 = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
constexpr int BPI =
- F::BPI * NW / WARPS; // blocks per iteration scale with the warp count
+ F::BPI * NW * SG / (WARPS * WARP); // blocks per iteration scale with the thread count
const int tid =
- WARP * int(item_ct1.get_local_id(1)) + int(item_ct1.get_local_id(2));
+ SG * int(item_ct1.get_local_id(1)) + int(item_ct1.get_local_id(2));
const int row0 = ROWS * int(item_ct1.get_group(2));
const int blocks_per_row = n_in / F::DIV;
const int x_stride = n_in / Q8K; // Q8_1 blocks per activation column
@@ -1230,7 +1250,7 @@ native_mmvq_multi_kernel(const typename F::Block *__restrict__ w,
}
}
auto &partial = *sycl::ext::oneapi::group_local_memory_for_overwrite<
- float[NW - 1 > 0 ? NW - 1 : 1][NCOLS][ROWS][WARP]>(
+ float[NW - 1 > 0 ? NW - 1 : 1][NCOLS][ROWS][SG]>(
sycl::ext::oneapi::this_work_item::get_work_group<3>());
if (item_ct1.get_local_id(1) > 0) {
#pragma unroll
@@ -1254,7 +1274,7 @@ native_mmvq_multi_kernel(const typename F::Block *__restrict__ w,
#pragma unroll
for (int l = 0; l < NW - 1; ++l) tmp[j][i] +=
partial[l][j][i][item_ct1.get_local_id(2)];
- tmp[j][i] = warp_sum(tmp[j][i]);
+ tmp[j][i] = sg_sum<SG>(tmp[j][i]);
if (item_ct1.get_local_id(2) == i && row0 + i < n_out)
y[std::size_t(j) * n_out + row0 + i] = tmp[j][i];
}
@@ -1308,12 +1328,13 @@ void native_mmvq_rowwarp_kernel(const typename F::Block* __restrict__ w, const Q
// 4-byte loads and measures 130-140 GB/s on the 8192-wide Q6_K projections. Here 8 lanes share a 256-block:
// lane g takes positions iqs = 4g..4g+3, so its ql (16 B), qh (16 B) and each column's q8 ints (16 B) are one
// vector load each; a 32-lane sub-group has four blocks in flight. One row per warp, WARPS rows per group.
-template <int NCOLS, int RPW>
+template <int NCOLS, int RPW, int SG = WARP>
void native_mmvq_q6k_wide_kernel(const Q6KBlock* __restrict__ w, const Q81Block* __restrict__ x,
float* __restrict__ y, int n_in, int n_out) {
auto item = sycl::ext::oneapi::this_work_item::get_nd_item<3>();
const int lane = int(item.get_local_id(2)), warp = int(item.get_local_id(1));
- const int row0 = (int(item.get_group(2)) * WARPS + warp) * RPW;
+ constexpr int NWG = WARPS * WARP / SG; // sub-groups per work-group
+ const int row0 = (int(item.get_group(2)) * NWG + warp) * RPW;
if (row0 >= n_out) return;
const int blocks_per_row = n_in / QK, x_stride = n_in / Q8K;
const int g = lane & 7, sub = lane >> 3; // position group within the block, block within the iteration
@@ -1323,7 +1344,7 @@ void native_mmvq_q6k_wide_kernel(const Q6KBlock* __restrict__ w, const Q81Block*
const int bq8_offset = 4 * (g >> 2) + ((g & 3) >> 1);
const int u_int4 = g & 1; // ints 4(g%2)..+3 of the q8 block = one int4
float acc[RPW][NCOLS] = {};
- for (int kbx = sub; kbx < blocks_per_row; kbx += 4) {
+ for (int kbx = sub; kbx < blocks_per_row; kbx += SG / 8) {
const int kby = kbx * (QK / Q8K);
sycl::int4 ql4[RPW], qh4[RPW]; float dsc0[RPW], dsc1[RPW];
#pragma unroll
@@ -1372,7 +1393,7 @@ void native_mmvq_q6k_wide_kernel(const Q6KBlock* __restrict__ w, const Q81Block*
for (int j = 0; j < NCOLS; ++j) {
float v = acc[r][j];
#pragma unroll
- for (int o = WARP / 2; o > 0; o >>= 1) v += dpct::experimental::permute_sub_group_by_xor(0xffffffffu, sg, v, o);
+ for (int o = SG / 2; o > 0; o >>= 1) v += sycl::permute_group_by_xor(sg, v, o);
if (lane == 0 && row0 + r < n_out) y[std::size_t(j) * n_out + row0 + r] = v;
}
}
@@ -1385,6 +1406,14 @@ void launch_q6k_wide(const void* weights, const void* x_q8_1, float* y, int n_in
const auto* w = static_cast<const Q6KBlock*>(weights);
const auto* x = static_cast<const Q81Block*>(x_q8_1);
const int rpw = q6k_wide_rpw();
+ if (rpw == 1 && mmvq_sg16(false, n_out)) {
+ constexpr int NWG = WARPS * WARP / 16;
+ const unsigned blocks = unsigned((std::size_t(n_out) + NWG - 1) / NWG);
+ s->parallel_for<dpct_kernel_name<class native_mmvq_q6k_wide16, dpct_kernel_scalar<NCOLS>>>(
+ sycl::nd_range<3>(sycl::range(1, 1, blocks) * sycl::range(1, NWG, 16), sycl::range(1, NWG, 16)),
+ [=](sycl::nd_item<3>) [[sycl::reqd_sub_group_size(16)]] { native_mmvq_q6k_wide_kernel<NCOLS, 1, 16>(w, x, y, n_in, n_out); });
+ return;
+ }
#define STRATA_Q6W(RP) if (rpw == RP) { \
const unsigned blocks = unsigned((std::size_t(n_out) + WARPS * RP - 1) / (WARPS * RP)); \
s->parallel_for<dpct_kernel_name<class native_mmvq_q6k_wide, dpct_kernel_scalar<NCOLS>, dpct_kernel_scalar<RP>>>( \
@@ -1449,6 +1478,25 @@ void launch_multi_n(const void *weights, const void *x_q8_1, float *y, int n_in,
}
return;
}
+ if (mmvq_sg16(std::is_same_v<F, IQ4XSTraits>, n_out)) { // same 128 threads as 8 SIMD16 sub-groups
+ constexpr int NW16 = WARPS * WARP / 16;
+ const sycl::range<3> t16(1, NW16, 16);
+ if (n_in / F::DIV < F::BPI) {
+ const unsigned blocks = unsigned((std::size_t(n_out) + WARPS - 1) / WARPS);
+ s->parallel_for<dpct_kernel_name<class native_mmvq_multi16_small, F, dpct_kernel_scalar<NCOLS>>>(
+ sycl::nd_range<3>(sycl::range(1, 1, blocks) * t16, t16),
+ [=](sycl::nd_item<3>) [[sycl::reqd_sub_group_size(16)]] {
+ native_mmvq_multi_kernel<F, NCOLS, NW16, WARPS, 16>(w, x, y, n_in, n_out);
+ });
+ } else {
+ s->parallel_for<dpct_kernel_name<class native_mmvq_multi16, F, dpct_kernel_scalar<NCOLS>>>(
+ sycl::nd_range<3>(sycl::range(1, 1, unsigned(n_out)) * t16, t16),
+ [=](sycl::nd_item<3>) [[sycl::reqd_sub_group_size(16)]] {
+ native_mmvq_multi_kernel<F, NCOLS, NW16, 1, 16>(w, x, y, n_in, n_out);
+ });
+ }
+ return;
+ }
const dpct::dim3 threads(WARP, WARPS);
if (n_in / F::DIV < F::BPI) {
const unsigned blocks = unsigned((std::size_t(n_out) + WARPS - 1) / WARPS);
diff --git a/sycl/src/kernels/mmvq_sg_bench.cpp b/sycl/src/kernels/mmvq_sg_bench.cpp
new file mode 100644
index 000000000..91ddd99bb
--- /dev/null
+++ b/sycl/src/kernels/mmvq_sg_bench.cpp
@@ -0,0 +1,54 @@
+// sycl/src/kernels/mmvq_sg_bench.cpp - SYCL port: the decode mmvq kernels on the Coder's dense shapes and types.
+// mmvq_sg_bench (run with STRATA_MMVQ_SG=16 and =32; prints us per call and a checksum of the outputs)
+#include "strata/kernels/native_mmvq.hpp"
+#include <sycl/sycl.hpp>
+#include <dpct/dpct.hpp>
+#include <chrono>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
+#include <vector>
+int main() {
+ sycl::queue* s = &dpct::get_in_order_queue();
+ struct T { const char* name; int type, bytes; }; // ggml type, bytes per 256 weights
+ const T types[] = {{"q6_k", 14, 210}, {"q5_k", 13, 176}, {"q4_k", 12, 144}, {"iq4_xs", 23, 136}};
+ const int shapes[][2] = {{2560, 10240}, {2560, 12288}, {6144, 2560}, {2560, 640}};
+ const int cols[] = {2, 4, 6};
+ for (const T& t : types)
+ for (auto& sh : shapes) {
+ const int n_in = sh[0], n_out = sh[1];
+ const size_t wbytes = (size_t) n_out * (n_in / 256) * t.bytes;
+ std::vector<uint8_t> hw(wbytes);
+ for (size_t i = 0; i < wbytes; ++i) hw[i] = (uint8_t) (i * 2654435761u >> 13) & 0x3b; // keeps fp16 fields finite
+ void* w = sycl::malloc_device(wbytes, *s);
+ s->memcpy(w, hw.data(), wbytes).wait();
+ for (int nc : cols) {
+ std::vector<float> hx((size_t) nc * n_in);
+ for (size_t i = 0; i < hx.size(); ++i) hx[i] = (float) ((i * 7919) % 1000) / 500.f - 1.f;
+ float* x = sycl::malloc_device<float>(hx.size(), *s);
+ void* xq = sycl::malloc_device((size_t) nc * (n_in / 32) * 36, *s);
+ float* y = sycl::malloc_device<float>((size_t) nc * n_out, *s);
+ s->memcpy(x, hx.data(), hx.size() * 4).wait();
+ strata::kernels::native_quantize_q8_1(x, xq, n_in, nc, s);
+ auto run = [&] { strata::kernels::native_mmvq(t.type, w, xq, y, n_in, n_out, nc, s); };
+ const auto w0 = std::chrono::steady_clock::now();
+ while (std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - w0).count() < 150) {
+ for (int i = 0; i < 20; ++i) run();
+ s->wait();
+ }
+ const int it = 300;
+ const auto t0 = std::chrono::steady_clock::now();
+ for (int i = 0; i < it; ++i) run();
+ s->wait();
+ const double us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count() / it;
+ std::vector<float> hy((size_t) nc * n_out);
+ s->memcpy(hy.data(), y, hy.size() * 4).wait();
+ double cs = 0; for (float v : hy) cs += std::isfinite(v) ? std::fabs((double) v) : 1e30;
+ std::printf("%-7s %5d x %5d cols %d %7.1f us %6.1f GB/s sum %.6e\n", t.name, n_in, n_out, nc, us,
+ wbytes / us / 1e3, cs);
+ sycl::free(x, *s); sycl::free(xq, *s); sycl::free(y, *s);
+ }
+ sycl::free(w, *s);
+ }
+ return 0;
+}