okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221bench: community report, Intel Arc Pro B65 32 GB (SYCL), IQ2_XS (PR #955)98d1c8d4f

main
5.5 KiB122 linesraw
1--- a/sycl/src/kernels/cuda/fused_gr.dp.cpp
2+++ b/sycl/src/kernels/cuda/fused_gr.dp.cpp
3@@ -1604,7 +1604,7 @@
4     return p;
5 }
6 
7-void fused_gr_read_multi(const FusedGrArgs* a, int n_tok, float* xn_scratch, void* stream, unsigned long long* stamp_buf,
8+bool fused_gr_read_multi(const FusedGrArgs* a, int n_tok, float* xn_scratch, void* stream, unsigned long long* stamp_buf,
9                          int stamp_i0) {
10     if (n_tok < 1 || n_tok > kFusedGrMaxT || xn_scratch == nullptr) {
11         std::fprintf(stderr, "fused_gr_read_multi: invalid arguments\n");
12@@ -1752,7 +1752,7 @@
13         */
14         const dpct::err0 e3 = 0;
15 
16-        return;
17+        return false;   // SYCL read does not produce the new fused q8_1 images
18     }
19     m.part = down_partials(st);
20     {
21@@ -1879,6 +1879,8 @@
22     need to rewrite this code.
23     */
24     const dpct::err0 e = 0;
25+    return false;   // Outputs were written; q8_1 images are not fused on SYCL.
26+
27 }
28 
29 bool fused_gr_supported(int64_t n_embd, int64_t hc, int64_t hc_lr) {
30--- a/sycl/src/core/expert_source.cpp
31+++ b/sycl/src/core/expert_source.cpp
32@@ -2630,7 +2630,11 @@
33 // `unbuffered` (Windows, experts_unbuffered): each chunk's 4 KiB-aligned window is read with FILE_FLAG_NO_BUFFERING into
34 // an aligned buffer and scattered into the blobs - no copy through the file cache when the drive is read anyway.
35 LoadStats load_experts_gguf(const std::string& gguf, uint8_t* dst, const strata::kernels::cpu::ExpertLayout& lay,
36-                            int threads, bool unbuffered) {
37+                            int threads, bool unbuffered, const std::atomic<int>* ready) {
38+    auto wait_ready = [ready](int64_t l) {
39+        if (ready != nullptr)
40+            while (ready->load(std::memory_order_acquire) <= l + 1) std::this_thread::yield();
41+    };
42     LoadStats st;
43     st.layers = (uint64_t) lay.n_layers;
44     const auto t0 = std::chrono::steady_clock::now();
45@@ -2660,6 +2664,7 @@
46             for (;;) {
47                 const int64_t l = next.fetch_add(1);
48                 if (l >= lay.n_layers || bad) break;
49+                wait_ready(l);
50                 const auto& fm = lay.fmt[(size_t) l];
51                 const uint64_t blob = lay.bytes[(size_t) l];
52                 const uint64_t per[3] = {fm.up_off, fm.up_off, blob - fm.down_off};
53@@ -2738,6 +2743,7 @@
54         for (;;) {
55             const int64_t l = next.fetch_add(1);
56             if (l >= lay.n_layers || bad) break;
57+                wait_ready(l);
58             const auto& fm = lay.fmt[(size_t) l];
59             const uint64_t blob = lay.bytes[(size_t) l];
60             const uint64_t per[3] = {fm.up_off, fm.up_off, blob - fm.down_off};
61--- a/sycl/src/prefill/gemm.dp.cpp
62+++ b/sycl/src/prefill/gemm.dp.cpp
63@@ -439,9 +439,10 @@
64 }
65 
66 void Gemm::bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64_t N, int64_t K, int64_t ldy,
67-                float beta) {
68+                float beta, int64_t ldx) {
69     if (T <= 0 || N <= 0) return;
70     if (ldy <= 0) ldy = N;
71+    if (ldx <= 0) ldx = K;
72     const float alpha = 1.0f;
73 #if defined(__HIPCC__) && defined(STRATA_HIPBLASLT_AVAILABLE)
74     if (try_hipblaslt(hipblaslt_state_, strata::prefill::hipblaslt::InputType::bf16, X, W, Y, T, N, K, ldy,
75@@ -455,7 +456,7 @@
76            (dpct::blas::descriptor_ptr)handle_, oneapi::mkl::transpose::trans,
77            oneapi::mkl::transpose::nontrans, (int)N, (int)T, (int)K, &alpha, W,
78            dpct::library_data_t::real_bfloat16, (int)K, X,
79-           dpct::library_data_t::real_bfloat16, (int)K, &beta, Y,
80+           dpct::library_data_t::real_bfloat16, (int)ldx, &beta, Y,
81            dpct::library_data_t::real_float, (int)ldy,
82            dpct::compute_type::f32)),
83        "cublasGemmEx");
84@@ -486,7 +487,22 @@
85 }
86 
87 void Gemm::native(const uint16_t* X, int ggml_type, const void* W_blocks, float* Y, int64_t T, int64_t N, int64_t K,
88-                  int64_t ldy, float beta) {
89+                  int64_t ldy, float beta, int64_t ldx) {
90+    if (ldx <= 0) ldx = K;
91+    // The current SYCL prompt uses contiguous rows; preserve that path exactly.
92+    // Shared headers also admit padded input rows. Respect their stride.
93+    auto product = [&](const uint16_t* weights, float* output, int64_t columns) {
94+        if (ldx == K) { f16(X, weights, output, T, columns, K, ldy, beta); return; }
95+        const float alpha = 1.0f;
96+        const int64_t output_stride = ldy > 0 ? ldy : columns;
97+        ck(DPCT_CHECK_ERROR(dpct::blas::gemm(
98+            (dpct::blas::descriptor_ptr)handle_, oneapi::mkl::transpose::trans,
99+            oneapi::mkl::transpose::nontrans, (int)columns, (int)T, (int)K, &alpha, weights,
100+            dpct::library_data_t::real_half, (int)K, X,
101+            dpct::library_data_t::real_half, (int)ldx, &beta, output,
102+            dpct::library_data_t::real_float, (int)output_stride,
103+            dpct::compute_type::f32)), "SYCL native GEMM padded input");
104+    };
105     if (N * K > scratch_elems_) {
106         // Too large for the scratch at once: in row slices.
107         const int64_t rows = scratch_elems_ / K;
108@@ -495,12 +511,12 @@
109         for (int64_t r0 = 0; r0 < N; r0 += rows) {
110             const int64_t n = (N - r0 < rows) ? N - r0 : rows;
111             strata::kernels::dequant_f16(ggml_type, W_blocks, r0, n, K, scratch_, stream_);
112-            f16(X, scratch_, Y + r0, T, n, K, ldy, beta);
113+            product(scratch_, Y + r0, n);
114         }
115         return;
116     }
117     strata::kernels::dequant_f16(ggml_type, W_blocks, 0, N, K, scratch_, stream_);
118-    f16(X, scratch_, Y, T, N, K, ldy, beta);
119+    product(scratch_, Y, N);
120 }
121 
122 }  // namespace strata::prefill