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/A770: wide MMVQ kernels at 2-8 columns in large-GRF mode on Arc A-series

Andy Slaterdb0b4d315cf1
diff --git a/sycl/src/kernels/cuda/native_mmvq.dp.cpp b/sycl/src/kernels/cuda/native_mmvq.dp.cpp
index 850e87b1a..1ba3c817e 100644
--- a/sycl/src/kernels/cuda/native_mmvq.dp.cpp
+++ b/sycl/src/kernels/cuda/native_mmvq.dp.cpp
@@ -25,6 +25,7 @@
#define DPCT_PROFILING_ENABLED
#include <sycl/sycl.hpp>
+#include <sycl/ext/intel/experimental/grf_size_properties.hpp>
#include <dpct/dpct.hpp>
#include "strata/sycl_math.hpp"
#include "strata/sycl_queue.hpp"
@@ -1714,6 +1715,19 @@ inline int q6k_wide_rpw() {
static const int v = std::getenv("STRATA_MMVQ_WIDE_RPW") ? std::atoi(std::getenv("STRATA_MMVQ_WIDE_RPW")) : 1;
return v;
}
+// Large-GRF mode (256 registers per thread instead of 128) for the wide kernels (Q6_K a2 and the generic one) at 2-8
+// columns: on the A770 they spill at 128, and mmvq_bench Q6_K 4 columns goes 70-80 -> 150-237 GB/s with the same
+// checksum. Large GRF halves the threads an Xe core keeps resident, so it is the default on Arc A-series (Alchemist)
+// only, where it was measured; Battlemage and anything else, and 1 column everywhere, launch the same kernels as before.
+// STRATA_MMVQ_LARGE_GRF=1 forces it on, =0 off.
+inline bool mmvq_large_grf(dpct::queue_ptr s) {
+ static const bool v = [s] {
+ const char* e = std::getenv("STRATA_MMVQ_LARGE_GRF");
+ if (e != nullptr) return std::atoi(e) != 0;
+ return strata::intel_gpu_gen(s->get_device()) == strata::IntelGpuGen::Alchemist;
+ }();
+ return v;
+}
template <int NCOLS>
void launch_q6k_wide(const void* weights, const void* x_q8_1, float* y, int n_in, int n_out, dpct::queue_ptr s) {
const auto* w = static_cast<const Q6KBlock*>(weights);
@@ -1737,6 +1751,17 @@ void launch_q6k_wide(const void* weights, const void* x_q8_1, float* y, int n_in
}
if (rpw == 1 && q6k_a2()) {
const unsigned blocks = unsigned((std::size_t(n_out) + WARPS - 1) / WARPS);
+ if constexpr (NCOLS > 1) {
+ if (mmvq_large_grf(s)) {
+ s->parallel_for<dpct_kernel_name<class native_mmvq_q6k_wide_a2_grf256, dpct_kernel_scalar<NCOLS>>>(
+ sycl::nd_range<3>(sycl::range(1, 1, blocks) * sycl::range(1, WARPS, WARP), sycl::range(1, WARPS, WARP)),
+ sycl::ext::oneapi::experimental::properties{sycl::ext::intel::experimental::grf_size<256>},
+ [=](sycl::nd_item<3>) [[sycl::reqd_sub_group_size(32)]] {
+ native_mmvq_q6k_wide_kernel<NCOLS, 1, WARP, (int) sizeof(Q6KBlock), true>(w, x, y, n_in, n_out);
+ });
+ return;
+ }
+ }
s->parallel_for<dpct_kernel_name<class native_mmvq_q6k_wide_a2, dpct_kernel_scalar<NCOLS>>>(
sycl::nd_range<3>(sycl::range(1, 1, blocks) * sycl::range(1, WARPS, WARP), sycl::range(1, WARPS, WARP)),
[=](sycl::nd_item<3>) [[sycl::reqd_sub_group_size(32)]] {
@@ -1969,6 +1994,15 @@ void launch_wide(const void* weights, const void* x_q8_1, float* y, int n_in, in
STRATA_WKR(2) STRATA_WKR(4)
#undef STRATA_WKR
const unsigned blocks = unsigned((std::size_t(n_out) + WARPS - 1) / WARPS);
+ if constexpr (NCOLS > 1) {
+ if (mmvq_large_grf(s)) {
+ s->parallel_for<dpct_kernel_name<class native_mmvq_wide_grf256, F, dpct_kernel_scalar<NCOLS>>>(
+ sycl::nd_range<3>(sycl::range(1, 1, blocks) * sycl::range(1, WARPS, WARP), sycl::range(1, WARPS, WARP)),
+ sycl::ext::oneapi::experimental::properties{sycl::ext::intel::experimental::grf_size<256>},
+ [=](sycl::nd_item<3>) [[sycl::reqd_sub_group_size(32)]] { native_mmvq_wide_kernel<F, NCOLS>(w, x, y, n_in, n_out); });
+ return;
+ }
+ }
s->parallel_for<dpct_kernel_name<class native_mmvq_wide, F, dpct_kernel_scalar<NCOLS>>>(
sycl::nd_range<3>(sycl::range(1, 1, blocks) * sycl::range(1, WARPS, WARP), sycl::range(1, WARPS, WARP)),
[=](sycl::nd_item<3>) [[sycl::reqd_sub_group_size(32)]] { native_mmvq_wide_kernel<F, NCOLS>(w, x, y, n_in, n_out); });
diff --git a/sycl/src/kernels/mmvq_bench.cpp b/sycl/src/kernels/mmvq_bench.cpp
index 6bc370a16..906b926e7 100644
--- a/sycl/src/kernels/mmvq_bench.cpp
+++ b/sycl/src/kernels/mmvq_bench.cpp
@@ -6,6 +6,7 @@
#include <chrono>
#include <cstdio>
#include <cstdlib>
+#include <cstring>
#include <vector>
#include <cmath>
int main(int argc, char** argv) {
@@ -46,6 +47,10 @@ int main(int argc, char** argv) {
for (int i = 0; i < it; ++i) strata::kernels::native_q6_k_mmvq(w, xq, y, n_in, n_out, ncols, s);
s->wait();
const double us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count() / it;
- std::printf("q6_k mmvq %d x %d, %d cols: %.1f us (%.1f GB/s of weights)\n", n_in, n_out, ncols, us, wbytes / us / 1e3);
+ std::vector<float> hy((size_t) ncols * n_out);
+ s->memcpy(hy.data(), y, hy.size() * 4).wait();
+ unsigned long long cs = 1469598103934665603ull;
+ for (float v : hy) { unsigned u; std::memcpy(&u, &v, 4); cs = (cs ^ u) * 1099511628211ull; }
+ std::printf("q6_k mmvq %d x %d, %d cols: %.1f us (%.1f GB/s of weights) checksum %016llx\n", n_in, n_out, ncols, us, wbytes / us / 1e3, cs);
return 0;
}