Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-sycl/mmvq.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-sycl / mmvq.cpp` 3255 lines ยท 168241 bytes Raw Blame History 1 #include "mmvq.hpp" 2 3 #include "ggml.h" 4 #include "common.hpp" 5 #include "element_wise.hpp" 6 #include "quants.hpp" 7 #include "vecdotq.hpp" 8 9 #ifdef GGML_SYCL_MMVQ_HAS_XMX 10 # include "esimd.hpp" 11 #endif // GGML_SYCL_MMVQ_HAS_XMX 12 13 // vec_dot_q_sycl_t adapters for the IQ vec_dots that take their codebook tables as extra 14 // arguments: bind the constant tables here (as vec_dot_iq2_s_q8_1 / vec_dot_iq1_m_q8_1 already do 15 // internally) so they can be used as template arguments of mul_mat_vec_q_moe. 16 static __dpct_inline__ float vec_dot_iq2_xxs_q8_1_moe(const void * __restrict__ vbq, 17 const block_q8_1 * __restrict__ bq8_1, 18 const int & iqs) { 19 return vec_dot_iq2_xxs_q8_1(vbq, bq8_1, iqs, iq2xxs_grid, ksigns_iq2xs, kmask_iq2xs); 20 } 21 22 static __dpct_inline__ float vec_dot_iq2_xs_q8_1_moe(const void * __restrict__ vbq, 23 const block_q8_1 * __restrict__ bq8_1, 24 const int & iqs) { 25 return vec_dot_iq2_xs_q8_1(vbq, bq8_1, iqs, iq2xs_grid); 26 } 27 28 static __dpct_inline__ float vec_dot_iq3_xxs_q8_1_moe(const void * __restrict__ vbq, 29 const block_q8_1 * __restrict__ bq8_1, 30 const int & iqs) { 31 return vec_dot_iq3_xxs_q8_1(vbq, bq8_1, iqs, iq3xxs_grid); 32 } 33 34 static __dpct_inline__ float vec_dot_iq3_s_q8_1_moe(const void * __restrict__ vbq, 35 const block_q8_1 * __restrict__ bq8_1, 36 const int & iqs) { 37 return vec_dot_iq3_s_q8_1(vbq, bq8_1, iqs, iq3s_grid); 38 } 39 40 static __dpct_inline__ float vec_dot_iq1_s_q8_1_moe(const void * __restrict__ vbq, 41 const block_q8_1 * __restrict__ bq8_1, 42 const int & iqs) { 43 return vec_dot_iq1_s_q8_1(vbq, bq8_1, iqs, iq1s_grid_gpu); 44 } 45 46 // Minimum weight-row count at which the Q4_K multi-column MMVQ kernel handles two output rows per 47 // subgroup (rows_per_sg == 2) instead of one, when ncols_dst == 2. 48 // 49 // Pairing rows lets a subgroup load each activation block once and apply it to two rows, at the cost 50 // of halving the number of subgroups in the launch. With only two destination columns there is too 51 // little work per row to hide that loss of parallelism, so pairing only pays off once there are 52 // enough rows to keep the device occupied. This is a measured performance crossover, not a 53 // correctness or hardware limit - both variants compute the same result for any nrows. 54 // 55 // Derived on Intel Arc Pro B70 with `test-backend-ops perf -o MUL_MAT` (Q4_K, ncols_dst == 2), 56 // sweeping nrows over 5120..6912 at ncols 17408 and 19968: one row per subgroup was up to 9% faster 57 // below the crossover, two rows per subgroup 8-15% faster above it, and the crossover fell inside 58 // (6144, 6272] for both ncols with no measurable ncols dependence. A later 32-row granularity sweep 59 // narrowed it to (6144, 6176], so 6272 is a conservative gate rather than the exact crossover. 60 // ncols_dst >= 3 amortizes the activation loads over more columns and is faster with two rows at 61 // every row count, so it does not consult this threshold. 62 static constexpr int Q4_K_MMVQ_ROW_PAIR_MIN_NROWS = 6272; 63 64 template 65 static void mul_mat_vec_q_reorder(const void * __restrict__ vx, const void * __restrict__ vy, float * __restrict__ dst, 66 const int ncols, const int nrows, const sycl::nd_item<3> & nd_item) { 67 using block_type = ggml_sycl_reordered::block_q_t; 68 using block_traits = typename block_type::traits; 69 70 const auto sg = nd_item.get_sub_group(); 71 const int sg_range = sg.get_group_linear_range(); 72 const int workgroup_id = nd_item.get_group_linear_id(); 73 const int sg_id = sg.get_group_linear_id(); 74 const int row = workgroup_id * sg_range + sg_id; 75 76 if (row >= nrows) { 77 return; 78 } 79 80 const int blocks_per_row = ncols / block_traits::qk; 81 constexpr int blocks_per_subgroup = ceil_div(block_traits::vdr_mmvq * WARP_SIZE, block_traits::qi); 82 constexpr int block_elements_per_subgroup = block_traits::qi / block_traits::vdr_mmvq; 83 const int nblocks = nrows * (ncols / block_traits::qk); 84 85 static_assert(blocks_per_subgroup > 0); 86 static_assert(block_elements_per_subgroup > 0); 87 88 float partial_sum = 0.0f; 89 for (int i = sg.get_local_linear_id() / block_elements_per_subgroup; i < blocks_per_row; i += blocks_per_subgroup) { 90 const int ibx = row * blocks_per_row + i; // x block index 91 92 const auto bx_offset = block_type::get_block_offset(ibx, nblocks); 93 const auto d_offset = block_type::get_d_offset(nrows, ncols, ibx); 94 // Y block index that aligns with ibx 95 const int iby = i * block_type::block_to_q8_1_ratio(); 96 const int8_t* q8_1_quant_ptr = (const int8_t*)vy + iby * QK8_1; 97 const sycl::half2* q8_1_ds_ptr = (const sycl::half2*)((const char*)vy + ncols + iby * sizeof(sycl::half2)); 98 99 #pragma unroll 100 for (int elem = 0; elem < block_elements_per_subgroup; elem += WARP_SIZE) { 101 // x block quant index when casting the quants to int 102 const int iqs = elem + block_traits::vdr_mmvq * (sg.get_local_linear_id() % block_elements_per_subgroup); 103 104 partial_sum += reorder_vec_dot_q_sycl()(vx, bx_offset, d_offset, q8_1_quant_ptr, q8_1_ds_ptr, iqs); 105 } 106 } 107 108 auto sum = sycl::reduce_over_group(nd_item.get_sub_group(), partial_sum, std::plus<>()); 109 110 if (sg.leader()) { 111 dst[row] = sum; 112 } 113 } 114 115 // With has_fusion, `vgate` is a second weight matrix sharing vx's shape, stride and reorder 116 // layout: one pass computes both row dot products and the epilogue writes glu(gate, up). 117 template ::value> 119 static void mul_mat_vec_q_reorder_ncols(const void * __restrict__ vx, const void * __restrict__ vgate, 120 const void * __restrict__ vy, float * __restrict__ dst, const int ncols, 121 const int nrows, const int stride_col_y_bytes, const int stride_col_dst, 122 const ggml_glu_op glu_op, const sycl::nd_item<3> & nd_item) { 123 using block_type = ggml_sycl_reordered::block_q_t; 124 using block_traits = typename block_type::traits; 125 126 const auto sg = nd_item.get_sub_group(); 127 const int sg_range = sg.get_group_linear_range(); 128 const int workgroup_id = nd_item.get_group_linear_id(); 129 const int sg_id = sg.get_group_linear_id(); 130 const int row0 = (workgroup_id * sg_range + sg_id) * rows_per_sg; 131 132 // row is sub-group uniform, so this retires whole sub-groups and the collectives below 133 // stay convergent 134 if (row0 >= nrows) { 135 return; 136 } 137 138 static_assert(rows_per_sg == 1 || 139 reorder_vec_dot_shared_activations::value); 140 141 const int blocks_per_row = ncols / block_traits::qk; 142 constexpr int blocks_per_subgroup = ceil_div(block_traits::vdr_mmvq * WARP_SIZE, block_traits::qi); 143 constexpr int block_elements_per_subgroup = block_traits::qi / block_traits::vdr_mmvq; 144 const int nblocks = nrows * (ncols / block_traits::qk); 145 146 static_assert(blocks_per_subgroup > 0); 147 static_assert(block_elements_per_subgroup > 0); 148 149 float partial_sum[ncols_dst][rows_per_sg] = {}; 150 // sized 1 rather than 0 when unused: zero-length arrays are not standard C++, and the 151 // array is dead and eliminated in that case 152 [[maybe_unused]] float partial_gate[has_fusion ? ncols_dst : 1][has_fusion ? rows_per_sg : 1] = {}; 153 for (int i = sg.get_local_linear_id() / block_elements_per_subgroup; i < blocks_per_row; i += blocks_per_subgroup) { 154 const int iby = i * block_type::block_to_q8_1_ratio(); 155 156 #pragma unroll 157 for (int elem = 0; elem < block_elements_per_subgroup; elem += WARP_SIZE) { 158 const int iqs = elem + block_traits::vdr_mmvq * (sg.get_local_linear_id() % block_elements_per_subgroup); 159 160 if constexpr (rows_per_sg > 1) { 161 typename reorder_vec_dot_q_sycl::weights wx[rows_per_sg]; 162 [[maybe_unused]] typename reorder_vec_dot_q_sycl::weights wg[rows_per_sg]; 163 #pragma unroll 164 for (int r = 0; r < rows_per_sg; ++r) { 165 const int row = sycl::min(row0 + r, nrows - 1); 166 const int ibx = row * blocks_per_row + i; 167 const auto bx_offset = block_type::get_block_offset(ibx, nblocks); 168 const auto d_offset = block_type::get_d_offset(nrows, ncols, ibx); 169 wx[r] = reorder_vec_dot_q_sycl::load(vx, bx_offset, d_offset, iqs); 170 if constexpr (has_fusion) { 171 wg[r] = reorder_vec_dot_q_sycl::load(vgate, bx_offset, d_offset, iqs); 172 } 173 } 174 #pragma unroll 175 for (int j = 0; j < ncols_dst; ++j) { 176 const char * vy_j = (const char *) vy + j * stride_col_y_bytes; 177 const int8_t * q8_1_quant_ptr = (const int8_t *) vy_j + iby * QK8_1; 178 const sycl::half2 * q8_1_ds_ptr = 179 (const sycl::half2 *) (vy_j + ncols + iby * sizeof(sycl::half2)); 180 const auto a = reorder_vec_dot_q_sycl::load_activations(q8_1_quant_ptr, q8_1_ds_ptr, iqs); 181 #pragma unroll 182 for (int r = 0; r < rows_per_sg; ++r) { 183 partial_sum[j][r] += reorder_vec_dot_q_sycl::apply(wx[r], a); 184 if constexpr (has_fusion) { 185 partial_gate[j][r] += reorder_vec_dot_q_sycl::apply(wg[r], a); 186 } 187 } 188 } 189 } else if constexpr (shared_weights) { 190 const int ibx = row0 * blocks_per_row + i; 191 const auto bx_offset = block_type::get_block_offset(ibx, nblocks); 192 const auto d_offset = block_type::get_d_offset(nrows, ncols, ibx); 193 const auto wx = reorder_vec_dot_q_sycl::load(vx, bx_offset, d_offset, iqs); 194 if constexpr (has_fusion) { 195 const auto wg = reorder_vec_dot_q_sycl::load(vgate, bx_offset, d_offset, iqs); 196 197 #pragma unroll 198 for (int j = 0; j < ncols_dst; ++j) { 199 const char * vy_j = (const char *) vy + j * stride_col_y_bytes; 200 const int8_t * q8_1_quant_ptr = (const int8_t *) vy_j + iby * QK8_1; 201 const sycl::half2 * q8_1_ds_ptr = 202 (const sycl::half2 *) (vy_j + ncols + iby * sizeof(sycl::half2)); 203 204 // up and gate share the activation, so load it once and apply it twice 205 const auto a = reorder_vec_dot_q_sycl::load_activations(q8_1_quant_ptr, q8_1_ds_ptr, iqs); 206 207 partial_sum[j][0] += reorder_vec_dot_q_sycl::apply(wx, a); 208 partial_gate[j][0] += reorder_vec_dot_q_sycl::apply(wg, a); 209 } 210 } else { 211 #pragma unroll 212 for (int j = 0; j < ncols_dst; ++j) { 213 const char * vy_j = (const char *) vy + j * stride_col_y_bytes; 214 const int8_t * q8_1_quant_ptr = (const int8_t *) vy_j + iby * QK8_1; 215 const sycl::half2 * q8_1_ds_ptr = 216 (const sycl::half2 *) (vy_j + ncols + iby * sizeof(sycl::half2)); 217 218 partial_sum[j][0] += reorder_vec_dot_q_sycl::dot(wx, q8_1_quant_ptr, q8_1_ds_ptr, iqs); 219 } 220 } 221 } else { 222 const int ibx = row0 * blocks_per_row + i; 223 const auto bx_offset = block_type::get_block_offset(ibx, nblocks); 224 const auto d_offset = block_type::get_d_offset(nrows, ncols, ibx); 225 #pragma unroll 226 for (int j = 0; j < ncols_dst; ++j) { 227 const char * vy_j = (const char *) vy + j * stride_col_y_bytes; 228 const int8_t * q8_1_quant_ptr = (const int8_t *) vy_j + iby * QK8_1; 229 const sycl::half2 * q8_1_ds_ptr = 230 (const sycl::half2 *) (vy_j + ncols + iby * sizeof(sycl::half2)); 231 232 partial_sum[j][0] += 233 reorder_vec_dot_q_sycl()(vx, bx_offset, d_offset, q8_1_quant_ptr, q8_1_ds_ptr, iqs); 234 235 if constexpr (has_fusion) { 236 partial_gate[j][0] += 237 reorder_vec_dot_q_sycl()(vgate, bx_offset, d_offset, q8_1_quant_ptr, q8_1_ds_ptr, iqs); 238 } 239 } 240 } 241 } 242 } 243 244 #pragma unroll 245 for (int j = 0; j < ncols_dst; ++j) { 246 #pragma unroll 247 for (int r = 0; r < rows_per_sg; ++r) { 248 float sum = sycl::reduce_over_group(nd_item.get_sub_group(), partial_sum[j][r], std::plus<>()); 249 250 if constexpr (has_fusion) { 251 const float gate = sycl::reduce_over_group(nd_item.get_sub_group(), partial_gate[j][r], std::plus<>()); 252 253 // uniform across the launch; the launcher only instantiates SWIGLU and GEGLU 254 sum *= glu_op == GGML_GLU_OP_SWIGLU ? op_silu(gate) : op_gelu(gate); 255 } 256 257 if (sg.leader() && row0 + r < nrows) { 258 dst[j * stride_col_dst + row0 + r] = sum; 259 } 260 } 261 } 262 } 263 264 template 265 static void mul_mat_vec_q(const void * __restrict__ vx, const void * __restrict__ vy, float * __restrict__ dst, 266 const int ncols, const int nrows, const sycl::nd_item<3> & item_ct1) { 267 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + item_ct1.get_local_id(1); 268 269 if (row >= nrows) { 270 return; 271 } 272 273 const int blocks_per_row = ncols / qk; 274 constexpr int blocks_per_warp = (vdr * WARP_SIZE + qi - 1) / qi; // Ensuring blocks_per_warp > 0 275 276 assert(blocks_per_warp > 0); 277 278 // partial sum for each thread 279 float tmp = 0.0f; 280 281 const block_q_t * x = (const block_q_t *) vx; 282 const block_q8_1 * y = (const block_q8_1 *) vy; 283 284 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; i += blocks_per_warp) { 285 const int ibx = row * blocks_per_row + i; // x block index 286 287 const int iby = i * (qk / QK8_1); // y block index that aligns with ibx 288 289 for (size_t elem = 0; elem < qi / vdr; elem += WARP_SIZE) { 290 const int iqs = elem + vdr * (item_ct1.get_local_id(2) % 291 (qi / vdr)); // x block quant index when casting the quants to int 292 293 tmp += vec_dot_q_sycl(&x[ibx], &y[iby], iqs); 294 } 295 } 296 297 // sum up partial sums and write back result 298 #pragma unroll 299 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 300 tmp += dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 301 } 302 303 if (item_ct1.get_local_id(2) == 0) { 304 dst[row] = tmp; 305 } 306 } 307 308 template 310 static void mul_mat_vec_q_ncols( 311 const void * __restrict__ vx, 312 const void * __restrict__ vy, 313 float * __restrict__ dst, 314 const int ncols, 315 const int nrows, 316 const int stride_col_y, 317 const int stride_col_dst, 318 const sycl::nd_item<3> & item_ct1) { 319 320 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) 321 + item_ct1.get_local_id(1); 322 323 if (row >= nrows) { 324 return; 325 } 326 327 const int blocks_per_row = ncols / qk; 328 constexpr int blocks_per_warp = (vdr * WARP_SIZE + qi - 1) / qi; 329 330 // partial sums: one per output column 331 float tmp[ncols_dst] = {0.0f}; 332 333 const block_q_t * x = (const block_q_t *) vx; 334 const block_q8_1 * y = (const block_q8_1 *) vy; 335 336 for (int i = item_ct1.get_local_id(2) / (qi / vdr); 337 i < blocks_per_row; 338 i += blocks_per_warp) { 339 340 const int ibx = row * blocks_per_row + i; 341 const int iby = i * (qk / QK8_1); 342 343 // read weight block once, dot against all columns 344 for (size_t elem = 0; elem < qi / vdr; elem += WARP_SIZE) { 345 const int iqs = elem + vdr * (item_ct1.get_local_id(2) % (qi / vdr)); 346 347 #pragma unroll 348 for (int j = 0; j < ncols_dst; ++j) { 349 tmp[j] += vec_dot_q_sycl(&x[ibx], &y[j * stride_col_y + iby], iqs); 350 } 351 } 352 } 353 354 // reduce within subgroup 355 #pragma unroll 356 for (int j = 0; j < ncols_dst; ++j) { 357 #pragma unroll 358 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 359 tmp[j] += dpct::permute_sub_group_by_xor( 360 item_ct1.get_sub_group(), tmp[j], mask); 361 } 362 } 363 364 if (item_ct1.get_local_id(2) == 0) { 365 #pragma unroll 366 for (int j = 0; j < ncols_dst; ++j) { 367 dst[j * stride_col_dst + row] = tmp[j]; 368 } 369 } 370 } 371 372 template 373 static void launch_mul_mat_vec_q(const void * vx, const void * vy, float * dst, 374 const int ncols, const int nrows, const int ncols_dst, 375 const int stride_col_y, const int stride_col_dst, 376 dpct::queue_ptr stream) { 377 GGML_ASSERT(ncols % assert_qk == 0); 378 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 379 const sycl::range<3> block_nums(1, 1, block_num_y); 380 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 381 382 const auto launch = [&](auto ncols_tag) { 383 constexpr int N = decltype(ncols_tag)::value; 384 stream->submit([&](sycl::handler & cgh) { 385 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 386 [=](sycl::nd_item<3> item_ct1) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 387 if constexpr (N == 1) { 388 mul_mat_vec_q( 389 vx, vy, dst, ncols, nrows, item_ct1); 390 } else { 391 mul_mat_vec_q_ncols( 392 vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, item_ct1); 393 } 394 }); 395 }); 396 }; 397 398 switch (ncols_dst) { 399 case 1: launch(std::integral_constant{}); break; 400 case 2: launch(std::integral_constant{}); break; 401 case 3: launch(std::integral_constant{}); break; 402 case 4: launch(std::integral_constant{}); break; 403 case 5: launch(std::integral_constant{}); break; 404 case 6: launch(std::integral_constant{}); break; 405 case 7: launch(std::integral_constant{}); break; 406 case 8: launch(std::integral_constant{}); break; 407 default: GGML_ABORT("unsupported ncols_dst=%d", ncols_dst); 408 } 409 } 410 411 template 412 static void mul_mat_vec_q_iq2_xxs_q8_1(const void *__restrict__ vx, 413 const void *__restrict__ vy, 414 float *__restrict__ dst, const int ncols, 415 const int nrows, 416 const sycl::nd_item<3> &item_ct1) { 417 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 418 item_ct1.get_local_id(1); 419 420 if (row >= nrows) { 421 return; 422 } 423 424 const int blocks_per_row = ncols / qk; 425 const int blocks_per_warp = vdr * WARP_SIZE / qi; 426 assert(blocks_per_warp>0); 427 428 // partial sum for each thread 429 float tmp = 0.0f; 430 431 const block_q_t * x = (const block_q_t *) vx; 432 const block_q8_1 * y = (const block_q8_1 *) vy; 433 434 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 435 i += blocks_per_warp) { 436 const int ibx = row*blocks_per_row + i; // x block index 437 438 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 439 440 const int iqs = 441 vdr * 442 (item_ct1.get_local_id(2) % 443 (qi / vdr)); // x block quant index when casting the quants to int 444 445 tmp += vec_dot_iq2_xxs_q8_1(&x[ibx], &y[iby], iqs, iq2xxs_grid, ksigns_iq2xs, kmask_iq2xs); 446 } 447 448 // sum up partial sums and write back result 449 #pragma unroll 450 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 451 tmp += 452 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 453 } 454 455 if (item_ct1.get_local_id(2) == 0) { 456 dst[row] = tmp; 457 } 458 } 459 460 template 461 static void mul_mat_vec_q_iq2_xs_q8_1(const void *__restrict__ vx, 462 const void *__restrict__ vy, 463 float *__restrict__ dst, const int ncols, 464 const int nrows, 465 const sycl::nd_item<3> &item_ct1) { 466 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 467 item_ct1.get_local_id(1); 468 469 if (row >= nrows) { 470 return; 471 } 472 473 const int blocks_per_row = ncols / qk; 474 const int blocks_per_warp = vdr * WARP_SIZE / qi; 475 assert(blocks_per_warp>0); 476 // partial sum for each thread 477 float tmp = 0.0f; 478 479 const block_q_t * x = (const block_q_t *) vx; 480 const block_q8_1 * y = (const block_q8_1 *) vy; 481 482 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 483 i += blocks_per_warp) { 484 const int ibx = row*blocks_per_row + i; // x block index 485 486 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 487 488 const int iqs = 489 vdr * 490 (item_ct1.get_local_id(2) % 491 (qi / vdr)); // x block quant index when casting the quants to int 492 493 tmp += vec_dot_iq2_xs_q8_1(&x[ibx], &y[iby], iqs, iq2xs_grid); 494 } 495 496 // sum up partial sums and write back result 497 #pragma unroll 498 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 499 tmp += 500 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 501 } 502 503 if (item_ct1.get_local_id(2) == 0) { 504 dst[row] = tmp; 505 } 506 } 507 508 template 509 static void mul_mat_vec_q_iq2_s_q8_1(const void *__restrict__ vx, 510 const void *__restrict__ vy, 511 float *__restrict__ dst, const int ncols, 512 const int nrows, 513 const sycl::nd_item<3> &item_ct1) { 514 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 515 item_ct1.get_local_id(1); 516 517 if (row >= nrows) { 518 return; 519 } 520 521 const int blocks_per_row = ncols / qk; 522 const int blocks_per_warp = vdr * WARP_SIZE / qi; 523 assert(blocks_per_warp>0); 524 // partial sum for each thread 525 float tmp = 0.0f; 526 527 const block_q_t * x = (const block_q_t *) vx; 528 const block_q8_1 * y = (const block_q8_1 *) vy; 529 530 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 531 i += blocks_per_warp) { 532 const int ibx = row*blocks_per_row + i; // x block index 533 534 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 535 536 const int iqs = 537 vdr * 538 (item_ct1.get_local_id(2) % 539 (qi / vdr)); // x block quant index when casting the quants to int 540 541 tmp += vec_dot_iq2_s_q8_1(&x[ibx], &y[iby], iqs); 542 } 543 544 // sum up partial sums and write back result 545 #pragma unroll 546 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 547 tmp += 548 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 549 } 550 551 if (item_ct1.get_local_id(2) == 0) { 552 dst[row] = tmp; 553 } 554 } 555 556 template 557 static void mul_mat_vec_q_iq3_xxs_q8_1(const void *__restrict__ vx, 558 const void *__restrict__ vy, 559 float *__restrict__ dst, const int ncols, 560 const int nrows, 561 const sycl::nd_item<3> &item_ct1) { 562 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 563 item_ct1.get_local_id(1); 564 565 if (row >= nrows) { 566 return; 567 } 568 569 const int blocks_per_row = ncols / qk; 570 const int blocks_per_warp = vdr * WARP_SIZE / qi; 571 assert(blocks_per_warp>0); 572 // partial sum for each thread 573 float tmp = 0.0f; 574 575 const block_q_t * x = (const block_q_t *) vx; 576 const block_q8_1 * y = (const block_q8_1 *) vy; 577 578 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 579 i += blocks_per_warp) { 580 const int ibx = row*blocks_per_row + i; // x block index 581 582 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 583 584 const int iqs = 585 vdr * 586 (item_ct1.get_local_id(2) % 587 (qi / vdr)); // x block quant index when casting the quants to int 588 589 tmp += vec_dot_iq3_xxs_q8_1(&x[ibx], &y[iby], iqs, iq3xxs_grid); 590 } 591 592 // sum up partial sums and write back result 593 #pragma unroll 594 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 595 tmp += 596 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 597 } 598 599 if (item_ct1.get_local_id(2) == 0) { 600 dst[row] = tmp; 601 } 602 } 603 604 static __dpct_inline__ float vec_dot_iq3_s_q8_1_adapter( 605 const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & iqs) { 606 return vec_dot_iq3_s_q8_1(vbq, bq8_1, iqs, iq3s_grid); 607 } 608 609 template 610 static void mul_mat_vec_q_iq3_s_q8_1(const void *__restrict__ vx, 611 const void *__restrict__ vy, 612 float *__restrict__ dst, const int ncols, 613 const int nrows, 614 const sycl::nd_item<3> &item_ct1) { 615 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 616 item_ct1.get_local_id(1); 617 618 if (row >= nrows) { 619 return; 620 } 621 622 const int blocks_per_row = ncols / qk; 623 const int blocks_per_warp = vdr * WARP_SIZE / qi; 624 assert(blocks_per_warp>0); 625 // partial sum for each thread 626 float tmp = 0.0f; 627 628 const block_q_t * x = (const block_q_t *) vx; 629 const block_q8_1 * y = (const block_q8_1 *) vy; 630 631 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 632 i += blocks_per_warp) { 633 const int ibx = row*blocks_per_row + i; // x block index 634 635 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 636 637 const int iqs = 638 vdr * 639 (item_ct1.get_local_id(2) % 640 (qi / vdr)); // x block quant index when casting the quants to int 641 642 tmp += vec_dot_iq3_s_q8_1(&x[ibx], &y[iby], iqs, iq3s_grid); 643 } 644 645 // sum up partial sums and write back result 646 #pragma unroll 647 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 648 tmp += 649 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 650 } 651 652 if (item_ct1.get_local_id(2) == 0) { 653 dst[row] = tmp; 654 } 655 } 656 657 template 658 static void mul_mat_vec_q_iq1_s_q8_1(const void *__restrict__ vx, 659 const void *__restrict__ vy, 660 float *__restrict__ dst, const int ncols, 661 const int nrows, 662 const sycl::nd_item<3> &item_ct1) { 663 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 664 item_ct1.get_local_id(1); 665 666 if (row >= nrows) { 667 return; 668 } 669 670 const int blocks_per_row = ncols / qk; 671 const int blocks_per_warp = vdr * WARP_SIZE / qi; 672 assert(blocks_per_warp>0); 673 // partial sum for each thread 674 float tmp = 0.0f; 675 676 const block_q_t * x = (const block_q_t *) vx; 677 const block_q8_1 * y = (const block_q8_1 *) vy; 678 679 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 680 i += blocks_per_warp) { 681 const int ibx = row*blocks_per_row + i; // x block index 682 683 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 684 685 const int iqs = 686 vdr * 687 (item_ct1.get_local_id(2) % 688 (qi / vdr)); // x block quant index when casting the quants to int 689 690 tmp += vec_dot_iq1_s_q8_1(&x[ibx], &y[iby], iqs, iq1s_grid_gpu); 691 } 692 693 // sum up partial sums and write back result 694 #pragma unroll 695 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 696 tmp += 697 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 698 } 699 700 if (item_ct1.get_local_id(2) == 0) { 701 dst[row] = tmp; 702 } 703 } 704 705 template 706 static void mul_mat_vec_q_iq1_m_q8_1(const void *__restrict__ vx, 707 const void *__restrict__ vy, 708 float *__restrict__ dst, const int ncols, 709 const int nrows, 710 const sycl::nd_item<3> &item_ct1) { 711 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 712 item_ct1.get_local_id(1); 713 714 if (row >= nrows) { 715 return; 716 } 717 718 const int blocks_per_row = ncols / qk; 719 const int blocks_per_warp = vdr * WARP_SIZE / qi; 720 assert(blocks_per_warp>0); 721 // partial sum for each thread 722 float tmp = 0.0f; 723 724 const block_q_t * x = (const block_q_t *) vx; 725 const block_q8_1 * y = (const block_q8_1 *) vy; 726 727 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 728 i += blocks_per_warp) { 729 const int ibx = row*blocks_per_row + i; // x block index 730 731 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 732 733 const int iqs = 734 vdr * 735 (item_ct1.get_local_id(2) % 736 (qi / vdr)); // x block quant index when casting the quants to int 737 738 tmp += vec_dot_iq1_m_q8_1(&x[ibx], &y[iby], iqs); 739 } 740 741 // sum up partial sums and write back result 742 #pragma unroll 743 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 744 tmp += 745 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 746 } 747 748 if (item_ct1.get_local_id(2) == 0) { 749 dst[row] = tmp; 750 } 751 } 752 753 template 754 static void mul_mat_vec_q_iq4_nl_q8_1(const void *__restrict__ vx, 755 const void *__restrict__ vy, 756 float *__restrict__ dst, const int ncols, 757 const int nrows, 758 const sycl::nd_item<3> &item_ct1) { 759 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 760 item_ct1.get_local_id(1); 761 762 if (row >= nrows) { 763 return; 764 } 765 766 const int blocks_per_row = ncols / qk; 767 const int blocks_per_warp = vdr * WARP_SIZE / qi; 768 assert(blocks_per_warp>0); 769 // partial sum for each thread 770 float tmp = 0.0f; 771 772 const block_q_t * x = (const block_q_t *) vx; 773 const block_q8_1 * y = (const block_q8_1 *) vy; 774 775 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 776 i += blocks_per_warp) { 777 const int ibx = row*blocks_per_row + i; // x block index 778 779 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 780 781 const int iqs = 782 vdr * 783 (item_ct1.get_local_id(2) % 784 (qi / vdr)); // x block quant index when casting the quants to int 785 786 tmp += vec_dot_iq4_nl_q8_1(&x[ibx], &y[iby], iqs); 787 } 788 789 // sum up partial sums and write back result 790 #pragma unroll 791 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 792 tmp += 793 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 794 } 795 796 if (item_ct1.get_local_id(2) == 0) { 797 dst[row] = tmp; 798 } 799 } 800 801 802 template 803 static void mul_mat_vec_q_iq4_xs_q8_1(const void *__restrict__ vx, 804 const void *__restrict__ vy, 805 float *__restrict__ dst, const int ncols, 806 const int nrows, 807 const sycl::nd_item<3> &item_ct1) { 808 const int row = item_ct1.get_group(2) * item_ct1.get_local_range(1) + 809 item_ct1.get_local_id(1); 810 811 if (row >= nrows) { 812 return; 813 } 814 815 const int blocks_per_row = ncols / qk; 816 const int blocks_per_warp = vdr * WARP_SIZE / qi; 817 assert(blocks_per_warp>0); 818 // partial sum for each thread 819 float tmp = 0.0f; 820 821 const block_q_t * x = (const block_q_t *) vx; 822 const block_q8_1 * y = (const block_q8_1 *) vy; 823 824 for (int i = item_ct1.get_local_id(2) / (qi / vdr); i < blocks_per_row; 825 i += blocks_per_warp) { 826 const int ibx = row*blocks_per_row + i; // x block index 827 828 const int iby = i * (qk/QK8_1); // y block index that aligns with ibx 829 830 const int iqs = 831 vdr * 832 (item_ct1.get_local_id(2) % 833 (qi / vdr)); // x block quant index when casting the quants to int 834 835 tmp += vec_dot_iq4_xs_q8_1(&x[ibx], &y[iby], iqs); 836 } 837 838 // sum up partial sums and write back result 839 #pragma unroll 840 for (int mask = WARP_SIZE / 2; mask > 0; mask >>= 1) { 841 tmp += 842 dpct::permute_sub_group_by_xor(item_ct1.get_sub_group(), tmp, mask); 843 } 844 845 if (item_ct1.get_local_id(2) == 0) { 846 dst[row] = tmp; 847 } 848 } 849 850 static void reorder_mul_mat_vec_q4_0_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 851 const int nrows, dpct::queue_ptr stream) { 852 GGML_ASSERT(ncols % QK4_0 == 0); 853 // Round up to a whole number of subgroup-sized workgroups; out-of-range rows are skipped inside the kernel. 854 constexpr size_t num_subgroups = WARP_SIZE; 855 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 856 const sycl::range<3> block_nums(1, 1, block_num_y); 857 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 858 859 stream->submit([&](sycl::handler & cgh) { 860 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 861 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 862 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, nrows, 863 nd_item); 864 }); 865 }); 866 } 867 868 template 869 static void reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols( 870 const void * vx, const void * vy, float * dst, 871 const int ncols, const int nrows, 872 const int stride_col_y_bytes, const int stride_col_dst, 873 dpct::queue_ptr stream) { 874 GGML_ASSERT(ncols % QK4_0 == 0); 875 constexpr size_t num_subgroups = WARP_SIZE; 876 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 877 const sycl::range<3> block_nums(1, 1, block_num_y); 878 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 879 880 stream->submit([&](sycl::handler & cgh) { 881 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 882 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 883 mul_mat_vec_q_reorder_ncols, ncols_dst>( 884 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 885 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 886 }); 887 }); 888 } 889 890 static void reorder_mul_mat_vec_q4_0_q8_1_sycl_switch_ncols( 891 const void * vx, const void * vy, float * dst, 892 const int ncols, const int nrows, const int ncols_dst, 893 const int stride_col_y_bytes, const int stride_col_dst, 894 dpct::queue_ptr stream) { 895 switch (ncols_dst) { 896 case 1: reorder_mul_mat_vec_q4_0_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 897 case 2: reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 898 case 3: reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 899 case 4: reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 900 case 5: reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 901 case 6: reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 902 case 7: reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 903 case 8: reorder_mul_mat_vec_q4_0_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 904 default: GGML_ABORT("unsupported ncols_dst=%d for Q4_0 reorder multi-col MMVQ", ncols_dst); 905 } 906 } 907 908 static void mul_mat_vec_q4_0_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, const int nrows, 909 dpct::queue_ptr stream) { 910 launch_mul_mat_vec_q( 911 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 912 } 913 914 915 static void mul_mat_vec_q4_0_q8_1_sycl_switch_ncols( 916 const void * vx, const void * vy, float * dst, 917 const int ncols, const int nrows, const int ncols_dst, 918 const int stride_col_y, const int stride_col_dst, 919 dpct::queue_ptr stream) { 920 if (ncols_dst < 1 || ncols_dst > 8) { 921 GGML_ABORT("unsupported ncols_dst=%d for Q4_0 multi-col MMVQ", ncols_dst); 922 } 923 launch_mul_mat_vec_q( 924 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 925 } 926 927 928 static void mul_mat_vec_q4_1_q8_1_sycl(const void *vx, const void *vy, 929 float *dst, const int ncols, 930 const int nrows, 931 dpct::queue_ptr stream) { 932 launch_mul_mat_vec_q( 934 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 935 } 936 937 938 static void mul_mat_vec_q4_1_q8_1_sycl_switch_ncols( 939 const void * vx, const void * vy, float * dst, 940 const int ncols, const int nrows, const int ncols_dst, 941 const int stride_col_y, const int stride_col_dst, 942 dpct::queue_ptr stream) { 943 if (ncols_dst < 1 || ncols_dst > 8) { 944 GGML_ABORT("unsupported ncols_dst=%d for Q4_1 multi-col MMVQ", ncols_dst); 945 } 946 launch_mul_mat_vec_q( 948 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 949 } 950 951 952 static void mul_mat_vec_mxfp4_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, const int nrows, 953 dpct::queue_ptr stream) { 954 launch_mul_mat_vec_q( 955 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 956 } 957 958 959 static void mul_mat_vec_mxfp4_q8_1_sycl_switch_ncols( 960 const void * vx, const void * vy, float * dst, 961 const int ncols, const int nrows, const int ncols_dst, 962 const int stride_col_y, const int stride_col_dst, 963 dpct::queue_ptr stream) { 964 if (ncols_dst < 1 || ncols_dst > 8) { 965 GGML_ABORT("unsupported ncols_dst=%d for MXFP4 multi-col MMVQ", ncols_dst); 966 } 967 launch_mul_mat_vec_q( 968 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 969 } 970 971 972 static void mul_mat_vec_nvfp4_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, const int nrows, 973 dpct::queue_ptr stream) { 974 launch_mul_mat_vec_q( 975 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 976 } 977 978 979 static void mul_mat_vec_nvfp4_q8_1_sycl_switch_ncols( 980 const void * vx, const void * vy, float * dst, 981 const int ncols, const int nrows, const int ncols_dst, 982 const int stride_col_y, const int stride_col_dst, 983 dpct::queue_ptr stream) { 984 if (ncols_dst < 1 || ncols_dst > 8) { 985 GGML_ABORT("unsupported ncols_dst=%d for NVFP4 multi-col MMVQ", ncols_dst); 986 } 987 launch_mul_mat_vec_q( 988 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 989 } 990 991 992 static void mul_mat_vec_q5_0_q8_1_sycl(const void *vx, const void *vy, 993 float *dst, const int ncols, 994 const int nrows, 995 dpct::queue_ptr stream) { 996 launch_mul_mat_vec_q( 998 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 999 } 1000 1001 1002 static void mul_mat_vec_q5_0_q8_1_sycl_switch_ncols( 1003 const void * vx, const void * vy, float * dst, 1004 const int ncols, const int nrows, const int ncols_dst, 1005 const int stride_col_y, const int stride_col_dst, 1006 dpct::queue_ptr stream) { 1007 if (ncols_dst < 1 || ncols_dst > 8) { 1008 GGML_ABORT("unsupported ncols_dst=%d for Q5_0 multi-col MMVQ", ncols_dst); 1009 } 1010 launch_mul_mat_vec_q( 1012 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1013 } 1014 1015 1016 static void mul_mat_vec_q5_1_q8_1_sycl(const void *vx, const void *vy, 1017 float *dst, const int ncols, 1018 const int nrows, 1019 dpct::queue_ptr stream) { 1020 launch_mul_mat_vec_q( 1022 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1023 } 1024 1025 1026 static void mul_mat_vec_q5_1_q8_1_sycl_switch_ncols( 1027 const void * vx, const void * vy, float * dst, 1028 const int ncols, const int nrows, const int ncols_dst, 1029 const int stride_col_y, const int stride_col_dst, 1030 dpct::queue_ptr stream) { 1031 if (ncols_dst < 1 || ncols_dst > 8) { 1032 GGML_ABORT("unsupported ncols_dst=%d for Q5_1 multi-col MMVQ", ncols_dst); 1033 } 1034 launch_mul_mat_vec_q( 1036 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1037 } 1038 1039 1040 static void reorder_mul_mat_vec_q8_0_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1041 const int nrows, dpct::queue_ptr stream) { 1042 GGML_ASSERT(ncols % QK8_0 == 0); 1043 // Round up to a whole number of subgroup-sized workgroups; out-of-range rows are skipped inside the kernel. 1044 constexpr size_t num_subgroups = WARP_SIZE; 1045 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1046 const sycl::range<3> block_nums(1, 1, block_num_y); 1047 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1048 1049 if (g_ggml_sycl_mmvq_wide) { 1050 stream->submit([&](sycl::handler & cgh) { 1051 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1052 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1053 mul_mat_vec_q_reorder(vx, vy, dst, ncols, nrows, nd_item); 1054 }); 1055 }); 1056 return; 1057 } 1058 1059 stream->submit([&](sycl::handler & cgh) { 1060 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1061 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1062 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, nrows, 1063 nd_item); 1064 }); 1065 }); 1066 } 1067 1068 template 1069 static void reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols( 1070 const void * vx, const void * vy, float * dst, 1071 const int ncols, const int nrows, 1072 const int stride_col_y_bytes, const int stride_col_dst, 1073 dpct::queue_ptr stream) { 1074 GGML_ASSERT(ncols % QK8_0 == 0); 1075 constexpr size_t num_subgroups = WARP_SIZE; 1076 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1077 const sycl::range<3> block_nums(1, 1, block_num_y); 1078 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1079 1080 stream->submit([&](sycl::handler & cgh) { 1081 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1082 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1083 mul_mat_vec_q_reorder_ncols, ncols_dst>( 1084 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1085 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1086 }); 1087 }); 1088 } 1089 1090 static void reorder_mul_mat_vec_q8_0_q8_1_sycl_switch_ncols( 1091 const void * vx, const void * vy, float * dst, 1092 const int ncols, const int nrows, const int ncols_dst, 1093 const int stride_col_y_bytes, const int stride_col_dst, 1094 dpct::queue_ptr stream) { 1095 switch (ncols_dst) { 1096 case 1: reorder_mul_mat_vec_q8_0_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1097 case 2: reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1098 case 3: reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1099 case 4: reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1100 case 5: reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1101 case 6: reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1102 case 7: reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1103 case 8: reorder_mul_mat_vec_q8_0_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1104 default: GGML_ABORT("unsupported ncols_dst=%d for Q8_0 reorder multi-col MMVQ", ncols_dst); 1105 } 1106 } 1107 1108 // MXFP4 reorder GEMV. Only MoE expert slices are reordered (opt_for_reorder_id); these dense entry 1109 // points serve per-expert ggml_sycl_mul_mat calls from multi-token MUL_MAT_ID after that reorder. 1110 static void reorder_mul_mat_vec_mxfp4_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1111 const int nrows, dpct::queue_ptr stream) { 1112 GGML_ASSERT(ncols % QK_MXFP4 == 0); 1113 constexpr size_t num_subgroups = WARP_SIZE; 1114 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1115 const sycl::range<3> block_nums(1, 1, block_num_y); 1116 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1117 1118 stream->submit([&](sycl::handler & cgh) { 1119 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1120 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1121 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, nrows, 1122 nd_item); 1123 }); 1124 }); 1125 } 1126 1127 template 1128 static void reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols( 1129 const void * vx, const void * vy, float * dst, 1130 const int ncols, const int nrows, 1131 const int stride_col_y_bytes, const int stride_col_dst, 1132 dpct::queue_ptr stream) { 1133 GGML_ASSERT(ncols % QK_MXFP4 == 0); 1134 constexpr size_t num_subgroups = WARP_SIZE; 1135 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1136 const sycl::range<3> block_nums(1, 1, block_num_y); 1137 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1138 1139 stream->submit([&](sycl::handler & cgh) { 1140 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1141 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1142 mul_mat_vec_q_reorder_ncols, ncols_dst>( 1143 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1144 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1145 }); 1146 }); 1147 } 1148 1149 static void reorder_mul_mat_vec_mxfp4_q8_1_sycl_switch_ncols( 1150 const void * vx, const void * vy, float * dst, 1151 const int ncols, const int nrows, const int ncols_dst, 1152 const int stride_col_y_bytes, const int stride_col_dst, 1153 dpct::queue_ptr stream) { 1154 switch (ncols_dst) { 1155 case 1: reorder_mul_mat_vec_mxfp4_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1156 case 2: reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1157 case 3: reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1158 case 4: reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1159 case 5: reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1160 case 6: reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1161 case 7: reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1162 case 8: reorder_mul_mat_vec_mxfp4_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1163 default: GGML_ABORT("unsupported ncols_dst=%d for MXFP4 reorder multi-col MMVQ", ncols_dst); 1164 } 1165 } 1166 1167 static void mul_mat_vec_q8_0_q8_1_sycl(const void *vx, const void *vy, 1168 float *dst, const int ncols, 1169 const int nrows, 1170 dpct::queue_ptr stream) { 1171 launch_mul_mat_vec_q( 1173 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1174 } 1175 1176 1177 static void mul_mat_vec_q8_0_q8_1_sycl_switch_ncols( 1178 const void * vx, const void * vy, float * dst, 1179 const int ncols, const int nrows, const int ncols_dst, 1180 const int stride_col_y, const int stride_col_dst, 1181 dpct::queue_ptr stream) { 1182 if (ncols_dst < 1 || ncols_dst > 8) { 1183 GGML_ABORT("unsupported ncols_dst=%d for Q8_0 multi-col MMVQ", ncols_dst); 1184 } 1185 launch_mul_mat_vec_q( 1187 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1188 } 1189 1190 1191 static void mul_mat_vec_q1_0_q8_1_sycl(const void * vx, const void * vy, 1192 float * dst, const int ncols, 1193 const int nrows, 1194 dpct::queue_ptr stream) { 1195 launch_mul_mat_vec_q( 1197 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1198 } 1199 1200 1201 static void mul_mat_vec_q1_0_q8_1_sycl_switch_ncols( 1202 const void * vx, const void * vy, float * dst, 1203 const int ncols, const int nrows, const int ncols_dst, 1204 const int stride_col_y, const int stride_col_dst, 1205 dpct::queue_ptr stream) { 1206 if (ncols_dst < 1 || ncols_dst > 8) { 1207 GGML_ABORT("unsupported ncols_dst=%d for Q1_0 multi-col MMVQ", ncols_dst); 1208 } 1209 launch_mul_mat_vec_q( 1211 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1212 } 1213 1214 1215 static void mul_mat_vec_q2_0_q8_1_sycl(const void * vx, const void * vy, 1216 float * dst, const int ncols, 1217 const int nrows, 1218 dpct::queue_ptr stream) { 1219 launch_mul_mat_vec_q( 1221 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1222 } 1223 1224 1225 static void mul_mat_vec_q2_0_q8_1_sycl_switch_ncols( 1226 const void * vx, const void * vy, float * dst, 1227 const int ncols, const int nrows, const int ncols_dst, 1228 const int stride_col_y, const int stride_col_dst, 1229 dpct::queue_ptr stream) { 1230 if (ncols_dst < 1 || ncols_dst > 8) { 1231 GGML_ABORT("unsupported ncols_dst=%d for Q2_0 multi-col MMVQ", ncols_dst); 1232 } 1233 launch_mul_mat_vec_q( 1235 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1236 } 1237 1238 1239 static void mul_mat_vec_q2_K_q8_1_sycl(const void *vx, const void *vy, 1240 float *dst, const int ncols, 1241 const int nrows, 1242 dpct::queue_ptr stream) { 1243 launch_mul_mat_vec_q( 1245 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1246 } 1247 1248 1249 static void mul_mat_vec_q2_K_q8_1_sycl_switch_ncols( 1250 const void * vx, const void * vy, float * dst, 1251 const int ncols, const int nrows, const int ncols_dst, 1252 const int stride_col_y, const int stride_col_dst, 1253 dpct::queue_ptr stream) { 1254 if (ncols_dst < 1 || ncols_dst > 8) { 1255 GGML_ABORT("unsupported ncols_dst=%d for Q2_K multi-col MMVQ", ncols_dst); 1256 } 1257 launch_mul_mat_vec_q( 1259 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1260 } 1261 1262 1263 static void reorder_mul_mat_vec_q2_k_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1264 const int nrows, dpct::queue_ptr stream) { 1265 GGML_ASSERT(ncols % QK_K == 0); 1266 1267 // Round up to a whole number of subgroup-sized workgroups; out-of-range rows are skipped inside the kernel. 1268 constexpr size_t num_subgroups = WARP_SIZE; 1269 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1270 const sycl::range<3> block_nums(1, 1, block_num_y); 1271 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1272 1273 stream->submit([&](sycl::handler & cgh) { 1274 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1275 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1276 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, nrows, 1277 nd_item); 1278 }); 1279 }); 1280 } 1281 1282 template 1283 static void reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols( 1284 const void * vx, const void * vy, float * dst, 1285 const int ncols, const int nrows, 1286 const int stride_col_y_bytes, const int stride_col_dst, 1287 dpct::queue_ptr stream) { 1288 GGML_ASSERT(ncols % QK_K == 0); 1289 constexpr size_t num_subgroups = WARP_SIZE; 1290 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1291 const sycl::range<3> block_nums(1, 1, block_num_y); 1292 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1293 1294 stream->submit([&](sycl::handler & cgh) { 1295 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1296 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1297 mul_mat_vec_q_reorder_ncols, ncols_dst>( 1298 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1299 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1300 }); 1301 }); 1302 } 1303 1304 static void reorder_mul_mat_vec_q2_k_q8_1_sycl_switch_ncols( 1305 const void * vx, const void * vy, float * dst, 1306 const int ncols, const int nrows, const int ncols_dst, 1307 const int stride_col_y_bytes, const int stride_col_dst, 1308 dpct::queue_ptr stream) { 1309 switch (ncols_dst) { 1310 case 1: reorder_mul_mat_vec_q2_k_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1311 case 2: reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1312 case 3: reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1313 case 4: reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1314 case 5: reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1315 case 6: reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1316 case 7: reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1317 case 8: reorder_mul_mat_vec_q2_k_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1318 default: GGML_ABORT("unsupported ncols_dst=%d for Q2_K reorder multi-col MMVQ", ncols_dst); 1319 } 1320 } 1321 1322 static void mul_mat_vec_q3_K_q8_1_sycl(const void *vx, const void *vy, 1323 float *dst, const int ncols, 1324 const int nrows, 1325 dpct::queue_ptr stream) { 1326 launch_mul_mat_vec_q( 1328 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1329 } 1330 1331 1332 static void reorder_mul_mat_vec_q3_k_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1333 const int nrows, dpct::queue_ptr stream) { 1334 GGML_ASSERT(ncols % QK_K == 0); 1335 1336 // Round up to a whole number of subgroup-sized workgroups; out-of-range rows are skipped inside the kernel. 1337 constexpr size_t num_subgroups = WARP_SIZE; 1338 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1339 const sycl::range<3> block_nums(1, 1, block_num_y); 1340 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1341 1342 stream->submit([&](sycl::handler & cgh) { 1343 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1344 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1345 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, nrows, 1346 nd_item); 1347 }); 1348 }); 1349 } 1350 1351 template 1352 static void reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols( 1353 const void * vx, const void * vy, float * dst, 1354 const int ncols, const int nrows, 1355 const int stride_col_y_bytes, const int stride_col_dst, 1356 dpct::queue_ptr stream) { 1357 GGML_ASSERT(ncols % QK_K == 0); 1358 constexpr size_t num_subgroups = WARP_SIZE; 1359 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1360 const sycl::range<3> block_nums(1, 1, block_num_y); 1361 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1362 1363 stream->submit([&](sycl::handler & cgh) { 1364 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1365 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1366 mul_mat_vec_q_reorder_ncols, ncols_dst>( 1367 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1368 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1369 }); 1370 }); 1371 } 1372 1373 static void reorder_mul_mat_vec_q3_k_q8_1_sycl_switch_ncols( 1374 const void * vx, const void * vy, float * dst, 1375 const int ncols, const int nrows, const int ncols_dst, 1376 const int stride_col_y_bytes, const int stride_col_dst, 1377 dpct::queue_ptr stream) { 1378 switch (ncols_dst) { 1379 case 1: reorder_mul_mat_vec_q3_k_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1380 case 2: reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1381 case 3: reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1382 case 4: reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1383 case 5: reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1384 case 6: reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1385 case 7: reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1386 case 8: reorder_mul_mat_vec_q3_k_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1387 default: GGML_ABORT("unsupported ncols_dst=%d for Q3_K reorder multi-col MMVQ", ncols_dst); 1388 } 1389 } 1390 1391 static void mul_mat_vec_q3_K_q8_1_sycl_switch_ncols( 1392 const void * vx, const void * vy, float * dst, 1393 const int ncols, const int nrows, const int ncols_dst, 1394 const int stride_col_y, const int stride_col_dst, 1395 dpct::queue_ptr stream) { 1396 if (ncols_dst < 1 || ncols_dst > 8) { 1397 GGML_ABORT("unsupported ncols_dst=%d for Q3_K multi-col MMVQ", ncols_dst); 1398 } 1399 launch_mul_mat_vec_q( 1401 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1402 } 1403 1404 1405 1406 static void mul_mat_vec_q4_K_q8_1_sycl(const void *vx, const void *vy, 1407 float *dst, const int ncols, 1408 const int nrows, 1409 dpct::queue_ptr stream) { 1410 launch_mul_mat_vec_q( 1412 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1413 } 1414 1415 1416 static void mul_mat_vec_q4_K_q8_1_sycl_switch_ncols( 1417 const void * vx, const void * vy, float * dst, 1418 const int ncols, const int nrows, 1419 const int ncols_dst, 1420 const int stride_col_y, const int stride_col_dst, 1421 dpct::queue_ptr stream) { 1422 if (ncols_dst < 1 || ncols_dst > 8) { 1423 GGML_ABORT("unsupported ncols_dst=%d for Q4_K multi-col MMVQ", ncols_dst); 1424 } 1425 launch_mul_mat_vec_q( 1427 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1428 } 1429 1430 1431 static void reorder_mul_mat_vec_q4_k_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1432 const int nrows, dpct::queue_ptr stream) { 1433 GGML_ASSERT(ncols % QK_K == 0); 1434 1435 // Round up to a whole number of subgroup-sized workgroups; out-of-range rows are skipped inside the kernel. 1436 constexpr size_t num_subgroups = WARP_SIZE; 1437 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1438 const sycl::range<3> block_nums(1, 1, block_num_y); 1439 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1440 1441 stream->submit([&](sycl::handler & cgh) { 1442 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1443 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1444 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, 1445 nrows, nd_item); 1446 }); 1447 }); 1448 } 1449 1450 template 1451 static void reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols_impl( 1452 const void * vx, const void * vy, float * dst, 1453 const int ncols, const int nrows, 1454 const int stride_col_y_bytes, const int stride_col_dst, 1455 dpct::queue_ptr stream) { 1456 GGML_ASSERT(ncols % QK_K == 0); 1457 1458 constexpr size_t num_subgroups = WARP_SIZE; 1459 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups * rows_per_sg); 1460 const sycl::range<3> block_nums(1, 1, block_num_y); 1461 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1462 1463 stream->submit([&](sycl::handler & cgh) { 1464 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1465 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1466 mul_mat_vec_q_reorder_ncols, ncols_dst, 1467 /*has_fusion=*/ false, rows_per_sg>( 1468 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1469 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1470 }); 1471 }); 1472 } 1473 1474 template 1475 static void reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols( 1476 const void * vx, const void * vy, float * dst, 1477 const int ncols, const int nrows, 1478 const int stride_col_y_bytes, const int stride_col_dst, 1479 dpct::queue_ptr stream) { 1480 constexpr int rows_per_sg = ncols_dst >= 3 && ncols_dst <= 4 ? 2 : 1; 1481 reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols_impl(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); 1482 } 1483 1484 static void reorder_mul_mat_vec_q4_k_q8_1_sycl_switch_ncols( 1485 const void * vx, const void * vy, float * dst, 1486 const int ncols, const int nrows, const int ncols_dst, 1487 const int stride_col_y_bytes, const int stride_col_dst, 1488 dpct::queue_ptr stream) { 1489 switch (ncols_dst) { 1490 case 1: reorder_mul_mat_vec_q4_k_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1491 case 2: 1492 if (nrows >= Q4_K_MMVQ_ROW_PAIR_MIN_NROWS) { 1493 reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols_impl<2, 2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); 1494 } else { 1495 reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols_impl<2, 1>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); 1496 } 1497 break; 1498 case 3: reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1499 case 4: reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1500 case 5: reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1501 case 6: reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1502 case 7: reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1503 case 8: reorder_mul_mat_vec_q4_k_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1504 default: GGML_ABORT("unsupported ncols_dst=%d for Q4_K reorder multi-col MMVQ", ncols_dst); 1505 } 1506 } 1507 1508 static void mul_mat_vec_q5_K_q8_1_sycl(const void *vx, const void *vy, 1509 float *dst, const int ncols, 1510 const int nrows, 1511 dpct::queue_ptr stream) { 1512 launch_mul_mat_vec_q( 1514 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1515 } 1516 1517 1518 static void mul_mat_vec_q5_K_q8_1_sycl_switch_ncols( 1519 const void * vx, const void * vy, float * dst, 1520 const int ncols, const int nrows, 1521 const int ncols_dst, 1522 const int stride_col_y, const int stride_col_dst, 1523 dpct::queue_ptr stream) { 1524 if (ncols_dst < 1 || ncols_dst > 8) { 1525 GGML_ABORT("unsupported ncols_dst=%d for Q5_K multi-col MMVQ", ncols_dst); 1526 } 1527 launch_mul_mat_vec_q( 1529 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1530 } 1531 1532 1533 static void reorder_mul_mat_vec_q5_k_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1534 const int nrows, dpct::queue_ptr stream) { 1535 GGML_ASSERT(ncols % QK_K == 0); 1536 1537 constexpr size_t num_subgroups = WARP_SIZE; 1538 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1539 const sycl::range<3> block_nums(1, 1, block_num_y); 1540 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1541 1542 stream->submit([&](sycl::handler & cgh) { 1543 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1544 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1545 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, 1546 nrows, nd_item); 1547 }); 1548 }); 1549 } 1550 1551 template 1552 static void reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols_impl( 1553 const void * vx, const void * vy, float * dst, 1554 const int ncols, const int nrows, 1555 const int stride_col_y_bytes, const int stride_col_dst, 1556 dpct::queue_ptr stream) { 1557 GGML_ASSERT(ncols % QK_K == 0); 1558 1559 constexpr size_t num_subgroups = WARP_SIZE; 1560 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups * rows_per_sg); 1561 const sycl::range<3> block_nums(1, 1, block_num_y); 1562 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1563 1564 stream->submit([&](sycl::handler & cgh) { 1565 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1566 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1567 mul_mat_vec_q_reorder_ncols, ncols_dst, 1568 /*has_fusion=*/ false, rows_per_sg, shared_weights>( 1569 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1570 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1571 }); 1572 }); 1573 } 1574 1575 template 1576 static void reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols( 1577 const void * vx, const void * vy, float * dst, 1578 const int ncols, const int nrows, 1579 const int stride_col_y_bytes, const int stride_col_dst, 1580 dpct::queue_ptr stream) { 1581 if (ggml_sycl_q5_k_mmvq_reuse(ggml_sycl_get_device())) { 1582 constexpr int rows_per_sg = ncols_dst >= 3 ? 2 : 1; 1583 reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols_impl(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); 1584 } else { 1585 reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols_impl(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); 1586 } 1587 } 1588 1589 static void reorder_mul_mat_vec_q5_k_q8_1_sycl_switch_ncols( 1590 const void * vx, const void * vy, float * dst, 1591 const int ncols, const int nrows, const int ncols_dst, 1592 const int stride_col_y_bytes, const int stride_col_dst, 1593 dpct::queue_ptr stream) { 1594 switch (ncols_dst) { 1595 case 1: reorder_mul_mat_vec_q5_k_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1596 case 2: reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1597 case 3: reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1598 case 4: reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1599 case 5: reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1600 case 6: reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1601 case 7: reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1602 case 8: reorder_mul_mat_vec_q5_k_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1603 default: GGML_ABORT("unsupported ncols_dst=%d for Q5_K reorder multi-col MMVQ", ncols_dst); 1604 } 1605 } 1606 1607 static void reorder_mul_mat_vec_q6_k_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1608 const int nrows, dpct::queue_ptr stream) { 1609 GGML_ASSERT(ncols % QK_K == 0); 1610 // Round up to a whole number of subgroup-sized workgroups; out-of-range rows are skipped inside the kernel. 1611 constexpr size_t num_subgroups = WARP_SIZE; 1612 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1613 const sycl::range<3> block_nums(1, 1, block_num_y); 1614 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1615 1616 1617 stream->submit([&](sycl::handler & cgh) { 1618 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1619 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1620 mul_mat_vec_q_reorder>(vx, vy, dst, ncols, nrows, 1621 nd_item); 1622 }); 1623 }); 1624 } 1625 1626 template 1627 static void reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols( 1628 const void * vx, const void * vy, float * dst, 1629 const int ncols, const int nrows, 1630 const int stride_col_y_bytes, const int stride_col_dst, 1631 dpct::queue_ptr stream) { 1632 GGML_ASSERT(ncols % QK_K == 0); 1633 constexpr size_t num_subgroups = WARP_SIZE; 1634 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1635 const sycl::range<3> block_nums(1, 1, block_num_y); 1636 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1637 1638 stream->submit([&](sycl::handler & cgh) { 1639 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1640 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1641 mul_mat_vec_q_reorder_ncols, ncols_dst>( 1642 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1643 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1644 }); 1645 }); 1646 } 1647 1648 static void reorder_mul_mat_vec_q6_k_q8_1_sycl_switch_ncols( 1649 const void * vx, const void * vy, float * dst, 1650 const int ncols, const int nrows, const int ncols_dst, 1651 const int stride_col_y_bytes, const int stride_col_dst, 1652 dpct::queue_ptr stream) { 1653 switch (ncols_dst) { 1654 case 1: reorder_mul_mat_vec_q6_k_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1655 case 2: reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1656 case 3: reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1657 case 4: reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1658 case 5: reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1659 case 6: reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1660 case 7: reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1661 case 8: reorder_mul_mat_vec_q6_k_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1662 default: GGML_ABORT("unsupported ncols_dst=%d for Q6_K reorder multi-col MMVQ", ncols_dst); 1663 } 1664 } 1665 1666 static void mul_mat_vec_q6_K_q8_1_sycl(const void *vx, const void *vy, 1667 float *dst, const int ncols, 1668 const int nrows, 1669 dpct::queue_ptr stream) { 1670 launch_mul_mat_vec_q( 1672 vx, vy, dst, ncols, nrows, 1, 0, 0, stream); 1673 } 1674 1675 1676 static void mul_mat_vec_q6_K_q8_1_sycl_switch_ncols( 1677 const void * vx, const void * vy, float * dst, 1678 const int ncols, const int nrows, 1679 const int ncols_dst, 1680 const int stride_col_y, const int stride_col_dst, 1681 dpct::queue_ptr stream) { 1682 if (ncols_dst < 1 || ncols_dst > 8) { 1683 GGML_ABORT("unsupported ncols_dst=%d for Q6_K multi-col MMVQ", ncols_dst); 1684 } 1685 launch_mul_mat_vec_q( 1687 vx, vy, dst, ncols, nrows, ncols_dst, stride_col_y, stride_col_dst, stream); 1688 } 1689 1690 1691 1692 static void mul_mat_vec_iq2_xxs_q8_1_sycl(const void *vx, const void *vy, 1693 float *dst, const int ncols, 1694 const int nrows, 1695 dpct::queue_ptr stream) { 1696 GGML_ASSERT(ncols % QK_K == 0); 1697 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1698 const sycl::range<3> block_nums(1, 1, block_num_y); 1699 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1700 { 1701 stream->submit([&](sycl::handler &cgh) { 1702 cgh.parallel_for( 1703 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1704 [=](sycl::nd_item<3> item_ct1) 1705 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1706 mul_mat_vec_q_iq2_xxs_q8_1( 1707 vx, vy, dst, ncols, nrows, item_ct1); 1708 }); 1709 }); 1710 } 1711 } 1712 1713 static void mul_mat_vec_iq2_xs_q8_1_sycl(const void *vx, const void *vy, 1714 float *dst, const int ncols, 1715 const int nrows, 1716 dpct::queue_ptr stream) { 1717 GGML_ASSERT(ncols % QK_K == 0); 1718 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1719 const sycl::range<3> block_nums(1, 1, block_num_y); 1720 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1721 { 1722 stream->submit([&](sycl::handler & cgh) { 1723 cgh.parallel_for( 1724 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1725 [=](sycl::nd_item<3> item_ct1) 1726 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1727 mul_mat_vec_q_iq2_xs_q8_1( 1728 vx, vy, dst, ncols, nrows, item_ct1); 1729 }); 1730 }); 1731 } 1732 } 1733 1734 static void mul_mat_vec_iq2_s_q8_1_sycl(const void *vx, const void *vy, 1735 float *dst, const int ncols, 1736 const int nrows, 1737 dpct::queue_ptr stream) { 1738 GGML_ASSERT(ncols % QK_K == 0); 1739 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1740 const sycl::range<3> block_nums(1, 1, block_num_y); 1741 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1742 { 1743 1744 stream->submit([&](sycl::handler &cgh) { 1745 cgh.parallel_for( 1746 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1747 [=](sycl::nd_item<3> item_ct1) 1748 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1749 mul_mat_vec_q_iq2_s_q8_1( 1750 vx, vy, dst, ncols, nrows, item_ct1); 1751 }); 1752 }); 1753 } 1754 } 1755 1756 static void mul_mat_vec_iq3_xxs_q8_1_sycl(const void *vx, const void *vy, 1757 float *dst, const int ncols, 1758 const int nrows, 1759 dpct::queue_ptr stream) { 1760 GGML_ASSERT(ncols % QK_K == 0); 1761 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1762 const sycl::range<3> block_nums(1, 1, block_num_y); 1763 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1764 { 1765 1766 stream->submit([&](sycl::handler &cgh) { 1767 cgh.parallel_for( 1768 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1769 [=](sycl::nd_item<3> item_ct1) 1770 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1771 mul_mat_vec_q_iq3_xxs_q8_1( 1772 vx, vy, dst, ncols, nrows, item_ct1); 1773 }); 1774 }); 1775 } 1776 } 1777 1778 template 1779 static void reorder_mul_mat_vec_iq3_q8_1_sycl(const void * vx, const void * vy, float * dst, const int ncols, 1780 const int nrows, dpct::queue_ptr stream) { 1781 static_assert(type == GGML_TYPE_IQ3_XXS || type == GGML_TYPE_IQ3_S); 1782 GGML_ASSERT(ncols % QK_K == 0); 1783 constexpr size_t num_subgroups = WARP_SIZE; 1784 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1785 const sycl::range<3> block_nums(1, 1, block_num_y); 1786 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1787 1788 stream->submit([&](sycl::handler & cgh) { 1789 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1790 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1791 mul_mat_vec_q_reorder>( 1792 vx, vy, dst, ncols, nrows, nd_item); 1793 }); 1794 }); 1795 } 1796 1797 template 1798 static void reorder_mul_mat_vec_iq3_q8_1_sycl_ncols( 1799 const void * vx, const void * vy, float * dst, 1800 const int ncols, const int nrows, 1801 const int stride_col_y_bytes, const int stride_col_dst, 1802 dpct::queue_ptr stream) { 1803 static_assert(type == GGML_TYPE_IQ3_XXS || type == GGML_TYPE_IQ3_S); 1804 GGML_ASSERT(ncols % QK_K == 0); 1805 constexpr size_t num_subgroups = WARP_SIZE; 1806 const int block_num_y = ceil_div(nrows, GGML_SYCL_MMV_Y * (int) num_subgroups); 1807 const sycl::range<3> block_nums(1, 1, block_num_y); 1808 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE); 1809 1810 stream->submit([&](sycl::handler & cgh) { 1811 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1812 [=](sycl::nd_item<3> nd_item) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1813 mul_mat_vec_q_reorder_ncols, ncols_dst>( 1814 vx, /*vgate=*/ nullptr, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, 1815 /*glu_op=*/ GGML_GLU_OP_SWIGLU, nd_item); 1816 }); 1817 }); 1818 } 1819 1820 template 1821 static void reorder_mul_mat_vec_iq3_q8_1_sycl_switch_ncols( 1822 const void * vx, const void * vy, float * dst, 1823 const int ncols, const int nrows, const int ncols_dst, 1824 const int stride_col_y_bytes, const int stride_col_dst, 1825 dpct::queue_ptr stream) { 1826 switch (ncols_dst) { 1827 case 1: reorder_mul_mat_vec_iq3_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 1828 case 2: reorder_mul_mat_vec_iq3_q8_1_sycl_ncols(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1829 case 3: reorder_mul_mat_vec_iq3_q8_1_sycl_ncols(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1830 case 4: reorder_mul_mat_vec_iq3_q8_1_sycl_ncols(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1831 case 5: reorder_mul_mat_vec_iq3_q8_1_sycl_ncols(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1832 case 6: reorder_mul_mat_vec_iq3_q8_1_sycl_ncols(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1833 case 7: reorder_mul_mat_vec_iq3_q8_1_sycl_ncols(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1834 case 8: reorder_mul_mat_vec_iq3_q8_1_sycl_ncols(vx, vy, dst, ncols, nrows, stride_col_y_bytes, stride_col_dst, stream); break; 1835 default: GGML_ABORT("unsupported ncols_dst=%d for reordered IQ3 multi-col MMVQ", ncols_dst); 1836 } 1837 } 1838 1839 static void mul_mat_vec_iq3_s_q8_1_sycl(const void *vx, const void *vy, 1840 float *dst, const int ncols, 1841 const int nrows, 1842 dpct::queue_ptr stream) { 1843 GGML_ASSERT(ncols % QK_K == 0); 1844 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1845 const sycl::range<3> block_nums(1, 1, block_num_y); 1846 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1847 { 1848 1849 stream->submit([&](sycl::handler &cgh) { 1850 cgh.parallel_for( 1851 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1852 [=](sycl::nd_item<3> item_ct1) 1853 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1854 mul_mat_vec_q_iq3_s_q8_1( 1855 vx, vy, dst, ncols, nrows, item_ct1); 1856 }); 1857 }); 1858 } 1859 } 1860 1861 template 1862 static void mul_mat_vec_iq3_s_q8_1_sycl_ncols(const void * vx, 1863 const void * vy, 1864 float * dst, 1865 const int ncols, 1866 const int nrows, 1867 const int stride_col_y, 1868 const int stride_col_dst, 1869 dpct::queue_ptr stream) { 1870 GGML_ASSERT(ncols % QK_K == 0); 1871 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1872 const sycl::range<3> block_nums(1, 1, block_num_y); 1873 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1874 stream->submit([&](sycl::handler & cgh) { 1875 cgh.parallel_for(sycl::nd_range<3>(block_nums * block_dims, block_dims), 1876 [=](sycl::nd_item<3> item_ct1) [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1877 mul_mat_vec_q_ncols( 1878 vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, item_ct1); 1879 }); 1880 }); 1881 } 1882 1883 static void mul_mat_vec_iq3_s_q8_1_sycl_switch_ncols(const void * vx, 1884 const void * vy, 1885 float * dst, 1886 const int ncols, 1887 const int nrows, 1888 const int ncols_dst, 1889 const int stride_col_y, 1890 const int stride_col_dst, 1891 dpct::queue_ptr stream) { 1892 switch (ncols_dst) { 1893 case 1: 1894 mul_mat_vec_iq3_s_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); 1895 break; 1896 case 2: 1897 mul_mat_vec_iq3_s_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); 1898 break; 1899 case 3: 1900 mul_mat_vec_iq3_s_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); 1901 break; 1902 case 4: 1903 mul_mat_vec_iq3_s_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); 1904 break; 1905 case 5: 1906 mul_mat_vec_iq3_s_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); 1907 break; 1908 case 6: 1909 mul_mat_vec_iq3_s_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); 1910 break; 1911 case 7: 1912 mul_mat_vec_iq3_s_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); 1913 break; 1914 case 8: 1915 mul_mat_vec_iq3_s_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); 1916 break; 1917 default: 1918 GGML_ABORT("unsupported ncols_dst=%d for IQ3_S multi-col MMVQ", ncols_dst); 1919 } 1920 } 1921 1922 static void mul_mat_vec_iq1_s_q8_1_sycl(const void *vx, const void *vy, 1923 float *dst, const int ncols, 1924 const int nrows, 1925 dpct::queue_ptr stream) { 1926 GGML_ASSERT(ncols % QK_K == 0); 1927 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1928 const sycl::range<3> block_nums(1, 1, block_num_y); 1929 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1930 { 1931 1932 stream->submit([&](sycl::handler &cgh) { 1933 cgh.parallel_for( 1934 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1935 [=](sycl::nd_item<3> item_ct1) 1936 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1937 mul_mat_vec_q_iq1_s_q8_1( 1938 vx, vy, dst, ncols, nrows, item_ct1); 1939 }); 1940 }); 1941 } 1942 } 1943 1944 static void mul_mat_vec_iq1_m_q8_1_sycl(const void *vx, const void *vy, 1945 float *dst, const int ncols, 1946 const int nrows, 1947 dpct::queue_ptr stream) { 1948 GGML_ASSERT(ncols % QK_K == 0); 1949 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1950 const sycl::range<3> block_nums(1, 1, block_num_y); 1951 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1952 { 1953 stream->submit([&](sycl::handler &cgh) { 1954 cgh.parallel_for( 1955 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1956 [=](sycl::nd_item<3> item_ct1) 1957 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1958 mul_mat_vec_q_iq1_m_q8_1( 1959 vx, vy, dst, ncols, nrows, item_ct1); 1960 }); 1961 }); 1962 } 1963 } 1964 1965 static void mul_mat_vec_iq4_nl_q8_1_sycl(const void *vx, const void *vy, 1966 float *dst, const int ncols, 1967 const int nrows, 1968 dpct::queue_ptr stream) { 1969 GGML_ASSERT(ncols % QK4_NL == 0); 1970 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1971 const sycl::range<3> block_nums(1, 1, block_num_y); 1972 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1973 { 1974 1975 stream->submit([&](sycl::handler &cgh) { 1976 cgh.parallel_for( 1977 sycl::nd_range<3>(block_nums * block_dims, block_dims), 1978 [=](sycl::nd_item<3> item_ct1) 1979 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 1980 mul_mat_vec_q_iq4_nl_q8_1( 1981 vx, vy, dst, ncols, nrows, item_ct1); 1982 }); 1983 }); 1984 } 1985 } 1986 1987 static void mul_mat_vec_iq4_xs_q8_1_sycl(const void *vx, const void *vy, 1988 float *dst, const int ncols, 1989 const int nrows, 1990 dpct::queue_ptr stream) { 1991 GGML_ASSERT(ncols % QK_K == 0); 1992 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 1993 const sycl::range<3> block_nums(1, 1, block_num_y); 1994 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 1995 { 1996 1997 stream->submit([&](sycl::handler &cgh) { 1998 cgh.parallel_for( 1999 sycl::nd_range<3>(block_nums * block_dims, block_dims), 2000 [=](sycl::nd_item<3> item_ct1) 2001 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 2002 mul_mat_vec_q_iq4_xs_q8_1( 2003 vx, vy, dst, ncols, nrows, item_ct1); 2004 }); 2005 }); 2006 } 2007 } 2008 2009 template 2010 static void mul_mat_vec_iq4_xs_q8_1_sycl_ncols( 2011 const void * vx, const void * vy, float * dst, 2012 const int ncols, const int nrows, 2013 const int stride_col_y, const int stride_col_dst, 2014 dpct::queue_ptr stream) { 2015 GGML_ASSERT(ncols % QK_K == 0); 2016 const int block_num_y = (nrows + GGML_SYCL_MMV_Y - 1) / GGML_SYCL_MMV_Y; 2017 const sycl::range<3> block_nums(1, 1, block_num_y); 2018 const sycl::range<3> block_dims(1, GGML_SYCL_MMV_Y, WARP_SIZE); 2019 2020 stream->submit([&](sycl::handler & cgh) { 2021 cgh.parallel_for( 2022 sycl::nd_range<3>(block_nums * block_dims, block_dims), 2023 [=](sycl::nd_item<3> item_ct1) 2024 [[sycl::reqd_sub_group_size(WARP_SIZE)]] { 2025 mul_mat_vec_q_ncols( 2029 vx, vy, dst, ncols, nrows, 2030 stride_col_y, stride_col_dst, item_ct1); 2031 }); 2032 }); 2033 } 2034 2035 static void mul_mat_vec_iq4_xs_q8_1_sycl_switch_ncols( 2036 const void * vx, const void * vy, float * dst, 2037 const int ncols, const int nrows, 2038 const int ncols_dst, 2039 const int stride_col_y, const int stride_col_dst, 2040 dpct::queue_ptr stream) { 2041 switch (ncols_dst) { 2042 case 1: mul_mat_vec_iq4_xs_q8_1_sycl(vx, vy, dst, ncols, nrows, stream); break; 2043 case 2: mul_mat_vec_iq4_xs_q8_1_sycl_ncols<2>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); break; 2044 case 3: mul_mat_vec_iq4_xs_q8_1_sycl_ncols<3>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); break; 2045 case 4: mul_mat_vec_iq4_xs_q8_1_sycl_ncols<4>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); break; 2046 case 5: mul_mat_vec_iq4_xs_q8_1_sycl_ncols<5>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); break; 2047 case 6: mul_mat_vec_iq4_xs_q8_1_sycl_ncols<6>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); break; 2048 case 7: mul_mat_vec_iq4_xs_q8_1_sycl_ncols<7>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); break; 2049 case 8: mul_mat_vec_iq4_xs_q8_1_sycl_ncols<8>(vx, vy, dst, ncols, nrows, stride_col_y, stride_col_dst, stream); break; 2050 default: GGML_ABORT("unsupported ncols_dst=%d for IQ4_XS multi-col MMVQ", ncols_dst); 2051 } 2052 } 2053 2054 #ifdef GGML_SYCL_MMVQ_HAS_XMX 2055 // vgate is the gate weight of the fused gate and up kernel, nullptr for a plain mat-vec 2056 template