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 prompt path: the 32-value block dequantizers (Q5_1, Q8_0, Q4_0, Q4_1, Q5_0) write neighbouring values from neighbouring lanes, as vector stores
Niko122158515d2b9cb5
diff --git a/sycl/src/kernels/cuda/iq_kernels.dp.cpp b/sycl/src/kernels/cuda/iq_kernels.dp.cppindex 564201390..a63a1beef 100644--- a/sycl/src/kernels/cuda/iq_kernels.dp.cpp+++ b/sycl/src/kernels/cuda/iq_kernels.dp.cpp@@ -2746,7 +2746,8 @@ inline void dq_q2_0(const void *vx, int64_t ibs, dst_t *yy, int tid) {}// llama.cpp's dequantize_q4_K / dequantize_q5_K (dequantize.cuh; q5_K's 64 threads folded onto 32) and the 32-value-// blocks of Q5_1 / Q8_0, 8 of them per 256-value "superblock" (thread tid writes 8 values of block tid % 8).+// blocks of Q5_1 / Q8_0, 8 of them per 256-value "superblock" (thread tid writes 8 values of block tid / 4; it was block+// tid % 8, which scattered a sub-group's 2-byte stores 64 bytes apart: B70 Q5_1 / Q8_0 at 88-93 GB/s of FP16 against 250+).__dpct_inline__ void get_scale_min_k4(int j, const uint8_t *q, uint8_t &d,uint8_t &m) {if (j < 4) {@@ -2803,64 +2804,78 @@ template <typename dst_t>inline void dq_q5_0(const void *vx, int64_t ibs, dst_t *yy, int tid) {// symmetric: one delta (no min), the high bit folded in then centered by the format's fixed -16 offsetconst block_q5_0* x = (const block_q5_0*) vx + ibs * (QK_K / QK5_0);- const int ib = tid % 8, il = tid / 8;+ const int ib = tid / 4, il = tid % 4; // lanes 4b..4b+3 write block b: neighbouring lanes, neighbouring valuesconst float d = sycl::vec<sycl::half, 1>(x[ib].d).convert<float, sycl::rounding_mode::automatic>()[0];uint32_t qh;memcpy(&qh, x[ib].qh, sizeof(qh));dst_t* y = yy + 32 * ib;+ float v0[4], v1[4];+#pragma unrollfor (int j = 0; j < 4; ++j) {const int iqs = 4 * il + j;const int xh_0 = ((qh >> (iqs + 0)) << 4) & 0x10;const int xh_1 = ((qh >> (iqs + 12))) & 0x10;- y[iqs] = cvt<dst_t>(((float) ((x[ib].qs[iqs] & 0xf) | xh_0) - 16.0f) * d);- y[iqs + 16] = cvt<dst_t>(((float) ((x[ib].qs[iqs] >> 4) | xh_1) - 16.0f) * d);+ v0[j] = ((float) ((x[ib].qs[iqs] & 0xf) | xh_0) - 16.0f) * d;+ v1[j] = ((float) ((x[ib].qs[iqs] >> 4) | xh_1) - 16.0f) * d;}+ store_run<dst_t, 4>(y + 4 * il, v0);+ store_run<dst_t, 4>(y + 16 + 4 * il, v1);}template <typename dst_t>inline void dq_q4_0(const void *vx, int64_t ibs, dst_t *yy, int tid) {const block_q4_0* x = (const block_q4_0*) vx + ibs * (QK_K / QK4_0);- const int ib = tid % 8, il = tid / 8;+ const int ib = tid / 4, il = tid % 4; // lanes 4b..4b+3 write block b: neighbouring lanes, neighbouring valuesconst float d = sycl::vec<sycl::half, 1>(x[ib].d).convert<float, sycl::rounding_mode::automatic>()[0];dst_t* y = yy + 32 * ib;+ float v0[4], v1[4];+#pragma unrollfor (int j = 0; j < 4; ++j) {const int iqs = 4 * il + j; // llama.cpp's dequantize_q4_0 for value pairs iqs, iqs + 16- y[iqs] = cvt<dst_t>(((float) (x[ib].qs[iqs] & 0xf) - 8.0f) * d);- y[iqs + 16] = cvt<dst_t>(((float) (x[ib].qs[iqs] >> 4) - 8.0f) * d);+ v0[j] = ((float) (x[ib].qs[iqs] & 0xf) - 8.0f) * d;+ v1[j] = ((float) (x[ib].qs[iqs] >> 4) - 8.0f) * d;}+ store_run<dst_t, 4>(y + 4 * il, v0);+ store_run<dst_t, 4>(y + 16 + 4 * il, v1);}template <typename dst_t>inline void dq_q4_1(const void *vx, int64_t ibs, dst_t *yy, int tid) {const block_q4_1* x = (const block_q4_1*) vx + ibs * (QK_K / QK4_1);- const int ib = tid % 8, il = tid / 8;+ const int ib = tid / 4, il = tid % 4; // lanes 4b..4b+3 write block b: neighbouring lanes, neighbouring valuesconst sycl::float2 dm =(x[ib].dm).template convert<float, sycl::rounding_mode::automatic>();dst_t* y = yy + 32 * ib;+ float v0[4], v1[4];+#pragma unrollfor (int j = 0; j < 4; ++j) {const int iqs = 4 * il + j; // llama.cpp's dequantize_q4_1 for value pairs iqs, iqs + 16- y[iqs] = cvt<dst_t>((float)(x[ib].qs[iqs] & 0xf) * dm.x() + dm.y());- y[iqs + 16] = cvt<dst_t>((float)(x[ib].qs[iqs] >> 4) * dm.x() + dm.y());+ v0[j] = (float)(x[ib].qs[iqs] & 0xf) * dm.x() + dm.y();+ v1[j] = (float)(x[ib].qs[iqs] >> 4) * dm.x() + dm.y();}+ store_run<dst_t, 4>(y + 4 * il, v0);+ store_run<dst_t, 4>(y + 16 + 4 * il, v1);}template <typename dst_t>inline void dq_q5_1(const void *vx, int64_t ibs, dst_t *yy, int tid) {const block_q5_1* x = (const block_q5_1*) vx + ibs * (QK_K / QK5_1);- const int ib = tid % 8, il = tid / 8;+ const int ib = tid / 4, il = tid % 4; // lanes 4b..4b+3 write block b: neighbouring lanes, neighbouring valuesconst sycl::float2 dm =(x[ib].dm).template convert<float, sycl::rounding_mode::automatic>();uint32_t qh;memcpy(&qh, x[ib].qh, sizeof(qh));dst_t* y = yy + 32 * ib;+ float v0[4], v1[4];+#pragma unrollfor (int j = 0; j < 4; ++j) {const int iqs = 4 * il + j; // llama.cpp's dequantize_q5_1 for value pairs iqs, iqs + 16const int xh_0 = ((qh >> (iqs + 0)) << 4) & 0x10;const int xh_1 = ((qh >> (iqs + 12))) & 0x10;- y[iqs] =- cvt<dst_t>((float)((x[ib].qs[iqs] & 0xf) | xh_0) * dm.x() + dm.y());- y[iqs + 16] =- cvt<dst_t>((float)((x[ib].qs[iqs] >> 4) | xh_1) * dm.x() + dm.y());+ v0[j] = (float)((x[ib].qs[iqs] & 0xf) | xh_0) * dm.x() + dm.y();+ v1[j] = (float)((x[ib].qs[iqs] >> 4) | xh_1) * dm.x() + dm.y();}+ store_run<dst_t, 4>(y + 4 * il, v0);+ store_run<dst_t, 4>(y + 16 + 4 * il, v1);}template<typename dst_t>void dq_q6_k(const void* vx, int64_t ibs, dst_t* yy, int tid) {@@ -2887,13 +2902,14 @@ void dq_q6_k(const void* vx, int64_t ibs, dst_t* yy, int tid) {template <typename dst_t>inline void dq_q8_0(const void *vx, int64_t ibs, dst_t *yy, int tid) {const block_q8_0* x = (const block_q8_0*) vx + ibs * (QK_K / QK8_0);- const int ib = tid % 8, il = tid / 8;+ const int ib = tid / 4, il = tid % 4; // lanes 4b..4b+3 write block b: neighbouring lanes, neighbouring valuesconst float d = sycl::vec<sycl::half, 1>(x[ib].d).convert<float, sycl::rounding_mode::automatic>()[0];dst_t* y = yy + 32 * ib + 8 * il;+ float v[8];#pragma unroll- for (int j = 0; j < 8; ++j)- y[j] = cvt<dst_t>((float)x[ib].qs[8 * il + j] * d);+ for (int j = 0; j < 8; ++j) v[j] = (float)x[ib].qs[8 * il + j] * d;+ store_run<dst_t, 8>(y, v);}// BF16 (the token embedding as the checkpoint ships it, tools/embd_bf16_pack.py): 8 values per thread.diff --git a/sycl/src/kernels/dequant_bench.cpp b/sycl/src/kernels/dequant_bench.cppindex 5311690d4..4f04d768b 100644--- a/sycl/src/kernels/dequant_bench.cpp+++ b/sycl/src/kernels/dequant_bench.cpp@@ -17,7 +17,8 @@ struct Ty { int id; const char* name; int bytes_per_256; };const Ty kTypes[] = {{16, "IQ2_XXS", 66}, {17, "IQ2_XS", 74}, {22, "IQ2_S", 82}, {18, "IQ3_XXS", 98},{21, "IQ3_S", 110}, {20, "IQ4_NL", 144}, {42, "Q2_0", 72},// Unsloth's files (MODEL-UPDATE): gate/up Q4_K / Q5_K / Q6_K / Q8_0, down Q5_1 / Q8_0- {12, "Q4_K", 144}, {13, "Q5_K", 176}, {14, "Q6_K", 210}, {7, "Q5_1", 192}, {8, "Q8_0", 272}};+ {12, "Q4_K", 144}, {13, "Q5_K", 176}, {14, "Q6_K", 210}, {7, "Q5_1", 192}, {8, "Q8_0", 272},+ {2, "Q4_0", 144}, {3, "Q4_1", 160}, {6, "Q5_0", 176}};uint64_t fnv(const uint16_t* p, size_t n) {uint64_t h = 1469598103934665603ull;for (size_t i = 0; i < n; ++i) { h ^= p[i]; h *= 1099511628211ull; }