interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-sycl / set_rows.cpp

577 lines · 23545 bytes Raw Blame History
1#include "set_rows.hpp"
2#include "cpy.hpp"
3
4#include "ggml-quants.h"
5
6#include <vector>
7
8namespace utils {
9template<typename T>
10static constexpr bool is_arithmetic_v() {
11 return std::is_arithmetic_v<T> || std::is_same_v<T, sycl::half>
12#ifdef GGML_SYCL_HAS_BF16
13 || std::is_same_v<T, sycl::ext::oneapi::bfloat16>
14#endif
15 ;
16}
17}
18
19template<typename TIn, typename TOut>
20static inline std::enable_if_t<utils::is_arithmetic_v<TIn>() && utils::is_arithmetic_v<TOut>(), void>
21convert (const char* src, char* dst) {
22 auto src_val = *reinterpret_cast<const TIn*>(src);
23 auto dst_val = sycl::vec<TIn, 1>(src_val).template convert<TOut, sycl::rounding_mode::automatic>()[0];
24 *reinterpret_cast<TOut*>(dst) = dst_val;
25}
26
27#ifdef GGML_SYCL_HAS_BF16
28// sycl::vec::convert does not provide a half -> bfloat16 path, so route through float.
29template<>
30inline void convert<sycl::half, sycl::ext::oneapi::bfloat16>(const char* src, char* dst) {
31 const float tmp = sycl::vec<sycl::half, 1>(*reinterpret_cast<const sycl::half*>(src))
32 .template convert<float, sycl::rounding_mode::automatic>()[0];
33 *reinterpret_cast<sycl::ext::oneapi::bfloat16*>(dst) = sycl::ext::oneapi::bfloat16(tmp);
34}
35#endif
36
37template <typename TIn, typename TIdx, typename blockType, int qk, cpy_kernel_t cpyblck>
38static void set_rows_sycl_q(const char * __restrict__ src0_d,
39 const TIdx * __restrict__ src1_d,
40 blockType * __restrict__ dst_d,
41 // tensor dimensions src0 and src1
42 const int64_t ne00,
43 const int64_t ne01,
44 const int64_t ne02,
45 const int64_t ne03,
46 const int64_t ne10,
47 const int64_t ne11,
48 const int64_t ne12,
49 const int64_t ne13,
50 // strides for src0
51 const size_t nb00,
52 const size_t nb01,
53 const size_t nb02,
54 const size_t nb03,
55 // strides for src1
56 const size_t nb10,
57 const size_t nb11,
58 const size_t nb12,
59 const size_t nb13,
60 // strides for dst
61 const size_t nb1,
62 const size_t nb2,
63 const size_t nb3,
64 queue_ptr stream) {
65 const int64_t total_blocks = (ne00 * ne01 * ne02 * ne03) / qk;
66 constexpr int block_size = 256;
67 const int64_t grid_size = ceil_div(total_blocks, block_size);
68
69 stream->parallel_for(sycl::nd_range<1>(grid_size * block_size, block_size), [=](sycl::nd_item<1> item_ct1) {
70 const int64_t i = item_ct1.get_global_linear_id();
71 if (i >= total_blocks) {
72 return;
73 }
74 const int64_t i_base = i * qk;
75 const int64_t i03 = i_base / (ne00 * ne01 * ne02);
76 const int64_t rem1 = i_base - i03 * (ne00 * ne01 * ne02);
77 const int64_t i02 = rem1 / (ne00 * ne01);
78 const int64_t rem2 = rem1 - i02 * ne00 * ne01;
79 const int64_t i01 = rem2 / ne00;
80 const int64_t i00 = rem2 - i01 * ne00;
81 const int64_t i12 = i03 % ne12;
82 const int64_t i11 = i02 % ne11;
83 const int64_t i10 = i01;
84 const size_t src_offset = calculate_offset<3>({ nb01, nb02, nb03 }, { i01, i02, i03 });
85 const char * src_block = src0_d + src_offset + i00 * sizeof(TIn);
86 const size_t src1_offset = calculate_offset<3>({ nb10, nb11, nb12 }, { i10, i11, i12 });
87 const int64_t dst_row = src1_d[src1_offset / sizeof(TIdx)];
88 const size_t dst_offset =
89 calculate_offset<3>({ nb1, nb2, nb3 }, { dst_row, i02, i03 }) + (i00 / qk) * sizeof(blockType);
90 char * dst_block = reinterpret_cast<char *>(reinterpret_cast<char *>(dst_d) + dst_offset);
91 if constexpr (std::is_same_v<TIn, float>) {
92 cpyblck(src_block, dst_block);
93 } else {
94 float src_block_f32[qk];
95 const TIn * src_block_t = reinterpret_cast<const TIn *>(src_block);
96 for (int j = 0; j < qk; ++j) {
97 src_block_f32[j] = (float) src_block_t[j];
98 }
99 cpyblck(reinterpret_cast<const char *>(src_block_f32), dst_block);
100 }
101 });
102 GGML_UNUSED(ne10);
103 GGML_UNUSED(ne13);
104 GGML_UNUSED(nb00);
105 GGML_UNUSED(nb13);
106}
107
108template<typename blockType>
109using quantize_row_qk_t = void (*)(const float *, blockType *, int64_t);
110
111using quantize_rows_f_t = size_t (*)(const float *, void *, int64_t, int64_t, const float *);
112
113template <typename TIn, typename TIdx, typename blockType, int qk, quantize_row_qk_t<blockType> quantize_row>
114static void set_rows_sycl_qk_host(
115 const ggml_tensor * src0,
116 const ggml_tensor * src1,
117 ggml_tensor * dst,
118 const int64_t ne00,
119 const int64_t ne01,
120 const int64_t ne02,
121 const int64_t ne03,
122 const int64_t ne11,
123 const int64_t ne12,
124 const size_t nb01,
125 const size_t nb02,
126 const size_t nb03,
127 const size_t nb10,
128 const size_t nb11,
129 const size_t nb12,
130 const size_t nb1,
131 const size_t nb2,
132 const size_t nb3,
133 queue_ptr stream) {
134 GGML_ASSERT(ne00 % qk == 0);
135
136 const size_t src0_bytes = ggml_nbytes(src0);
137 const size_t src1_bytes = ggml_nbytes(src1);
138
139 std::vector<char> src0_host(src0_bytes);
140 std::vector<char> src1_host(src1_bytes);
141
142 stream->memcpy(src0_host.data(), src0->data, src0_bytes);
143 stream->memcpy(src1_host.data(), src1->data, src1_bytes);
144 stream->wait();
145
146 std::vector<float> src_row_f32(ne00);
147 const int64_t nblocks = ne00 / qk;
148 std::vector<blockType> dst_row_q(nblocks);
149
150 for (int64_t i03 = 0; i03 < ne03; ++i03) {
151 for (int64_t i02 = 0; i02 < ne02; ++i02) {
152 for (int64_t i01 = 0; i01 < ne01; ++i01) {
153 const int64_t i12 = i03 % ne12;
154 const int64_t i11 = i02 % ne11;
155 const int64_t i10 = i01;
156
157 const size_t src1_offset = calculate_offset<3>({ nb10, nb11, nb12 }, { i10, i11, i12 });
158 const int64_t dst_row = *(const TIdx *) (src1_host.data() + src1_offset);
159
160 const size_t src0_row_offset = calculate_offset<3>({ nb01, nb02, nb03 }, { i01, i02, i03 });
161 const TIn * src_row = reinterpret_cast<const TIn *>(src0_host.data() + src0_row_offset);
162
163 for (int64_t i00 = 0; i00 < ne00; ++i00) {
164 src_row_f32[i00] = (float) src_row[i00];
165 }
166
167 quantize_row(src_row_f32.data(), dst_row_q.data(), ne00);
168
169 const size_t dst_offset = calculate_offset<3>({ nb1, nb2, nb3 }, { dst_row, i02, i03 });
170 stream->memcpy((char *) dst->data + dst_offset, dst_row_q.data(), nblocks * sizeof(blockType));
171 stream->wait();
172 }
173 }
174 }
175}
176
177template <typename TIn, typename TIdx, typename blockType, int qk, quantize_rows_f_t quantize_rows>
178static void set_rows_sycl_iq_host(
179 const ggml_tensor * src0,
180 const ggml_tensor * src1,
181 ggml_tensor * dst,
182 const int64_t ne00,
183 const int64_t ne01,
184 const int64_t ne02,
185 const int64_t ne03,
186 const int64_t ne11,
187 const int64_t ne12,
188 const size_t nb01,
189 const size_t nb02,
190 const size_t nb03,
191 const size_t nb10,
192 const size_t nb11,
193 const size_t nb12,
194 const size_t nb1,
195 const size_t nb2,
196 const size_t nb3,
197 queue_ptr stream) {
198 GGML_ASSERT(ne00 % qk == 0);
199
200 const size_t src0_bytes = ggml_nbytes(src0);
201 const size_t src1_bytes = ggml_nbytes(src1);
202
203 std::vector<char> src0_host(src0_bytes);
204 std::vector<char> src1_host(src1_bytes);
205
206 stream->memcpy(src0_host.data(), src0->data, src0_bytes);
207 stream->memcpy(src1_host.data(), src1->data, src1_bytes);
208 stream->wait();
209
210 std::vector<float> src_row_f32(ne00);
211 const int64_t nblocks = ne00 / qk;
212 std::vector<blockType> dst_row_q(nblocks);
213
214 for (int64_t i03 = 0; i03 < ne03; ++i03) {
215 for (int64_t i02 = 0; i02 < ne02; ++i02) {
216 for (int64_t i01 = 0; i01 < ne01; ++i01) {
217 const int64_t i12 = i03 % ne12;
218 const int64_t i11 = i02 % ne11;
219 const int64_t i10 = i01;
220
221 const size_t src1_offset = calculate_offset<3>({ nb10, nb11, nb12 }, { i10, i11, i12 });
222 const int64_t dst_row = *(const TIdx *) (src1_host.data() + src1_offset);
223
224 const size_t src0_row_offset = calculate_offset<3>({ nb01, nb02, nb03 }, { i01, i02, i03 });
225 const TIn * src_row = reinterpret_cast<const TIn *>(src0_host.data() + src0_row_offset);
226
227 for (int64_t i00 = 0; i00 < ne00; ++i00) {
228 src_row_f32[i00] = (float) src_row[i00];
229 }
230
231 quantize_rows(src_row_f32.data(), dst_row_q.data(), 1, ne00, nullptr);
232
233 const size_t dst_offset = calculate_offset<3>({ nb1, nb2, nb3 }, { dst_row, i02, i03 });
234 stream->memcpy((char *) dst->data + dst_offset, dst_row_q.data(), nblocks * sizeof(blockType));
235 stream->wait();
236 }
237 }
238 }
239}
240
241template<typename TIn, typename TIdx, typename TOut>
242static void k_set_rows(
243 const char * __restrict__ src0, const TIdx * __restrict__ src1, char * __restrict__ dst,
244 const int64_t ne00, const int64_t ne01, const int64_t ne02,
245 const int64_t ne11, const int64_t ne12,
246 const size_t nb01, const size_t nb02, const size_t nb03,
247 const size_t nb10, const size_t nb11, const size_t nb12,
248 const size_t nb1, const size_t nb2, const size_t nb3,
249 const size_t src_type_size, const size_t dst_type_size,
250 const int64_t total_elements,
251 const sycl::nd_item<1> & item_ct1) {
252
253 const int64_t i = item_ct1.get_global_linear_id();
254 if (i >= total_elements) {
255 return;
256 }
257
258 const int64_t i03 = i / (ne00 * ne01 * ne02);
259 const int64_t i02 = (i - i03 * ne00 * ne01 * ne02) / (ne00 * ne01);
260 const int64_t i01 = (i - i03 * ne00 * ne01 * ne02 - i02 * ne00 * ne01) / ne00;
261 const int64_t i00 = i - i03 * ne00 * ne01 * ne02 - i02 * ne00 * ne01 - i01 * ne00;
262
263 const int64_t i12 = i03 % ne12;
264 const int64_t i11 = i02 % ne11;
265 const int64_t i10 = i01;
266
267 const int64_t dst_row = *(const TIdx *)((const char *)src1 + calculate_offset<3>({nb10, nb11, nb12}, {i10, i11, i12}));
268
269 const char * src0_row = src0 + calculate_offset<3>({nb01, nb02, nb03}, {i01, i02, i03});
270 const char * src_elem = src0_row + i00 * src_type_size;
271 char * dst_row_ptr = dst + dst_row*nb1 + i02*nb2 + i03*nb3;
272 char * dst_elem = dst_row_ptr + i00 * dst_type_size;
273
274 convert<TIn, TOut>(src_elem, dst_elem);
275}
276
277template<typename TIn, typename TIdx, typename TOut>
278static void set_rows_sycl(
279 const char * src0_d, const TIdx * src1_d, char * dst_d,
280 const int64_t ne00, const int64_t ne01, const int64_t ne02, const int64_t ne03,
281 const int64_t ne11, const int64_t ne12, const size_t nb01, const size_t nb02, const size_t nb03,
282 const size_t nb10, const size_t nb11, const size_t nb12,
283 const size_t nb1, const size_t nb2, const size_t nb3,
284 const size_t src_type_size, const size_t dst_type_size,
285 queue_ptr stream) {
286
287 const int64_t total_elements = ne00 * ne01 * ne02 * ne03;
288
289 constexpr int block_size = 64;
290 const int64_t grid_size = ceil_div(total_elements, block_size);
291
292 stream->parallel_for(
293 sycl::nd_range<1>(grid_size * block_size, block_size),
294 [=](sycl::nd_item<1> item_ct1) [[sycl::reqd_sub_group_size(WARP_SIZE)]] {
295 k_set_rows<TIn, TIdx, TOut>(
296 src0_d, src1_d, dst_d,
297 ne00, ne01, ne02,
298 ne11, ne12,
299 nb01, nb02, nb03,
300 nb10, nb11, nb12,
301 nb1, nb2, nb3,
302 src_type_size, dst_type_size,
303 total_elements,
304 item_ct1
305 );
306 }
307 );
308}
309
310template<typename TIn, typename TIdx>
311static void set_rows_sycl(ggml_backend_sycl_context & ctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst) {
312 const char * src0_d = (const char *)src0->data;
313 const TIdx * src1_d = (const TIdx *)src1->data;
314
315 GGML_TENSOR_BINARY_OP_LOCALS
316
317 dpct::queue_ptr stream = ctx.stream();
318 switch (dst->type) {
319 case GGML_TYPE_F32:
320 set_rows_sycl<TIn, TIdx, float>(
321 src0_d, src1_d, (char *)dst->data,
322 ne00, ne01, ne02, ne03,
323 ne11, ne12,
324 nb01, nb02, nb03,
325 nb10, nb11, nb12,
326 nb1, nb2, nb3,
327 sizeof(TIn), sizeof(float),
328 stream
329 );
330 break;
331 case GGML_TYPE_F16:
332 dpct::has_capability_or_fail(stream->get_device(), { sycl::aspect::fp16 });
333 set_rows_sycl<TIn, TIdx, sycl::half>(
334 src0_d, src1_d, (char *)dst->data,
335 ne00, ne01, ne02, ne03,
336 ne11, ne12,
337 nb01, nb02, nb03,
338 nb10, nb11, nb12,
339 nb1, nb2, nb3,
340 sizeof(TIn), sizeof(sycl::half),
341 stream
342 );
343 break;
344#ifdef GGML_SYCL_HAS_BF16
345 case GGML_TYPE_BF16:
346 set_rows_sycl<TIn, TIdx, sycl::ext::oneapi::bfloat16>(
347 src0_d, src1_d, (char *)dst->data,
348 ne00, ne01, ne02, ne03,
349 ne11, ne12,
350 nb01, nb02, nb03,
351 nb10, nb11, nb12,
352 nb1, nb2, nb3,
353 sizeof(TIn), sizeof(sycl::ext::oneapi::bfloat16),
354 stream
355 );
356 break;
357#endif
358 case GGML_TYPE_Q8_0:
359 set_rows_sycl_q<TIn, TIdx, block_q8_0, QK8_0, cpy_blck_f32_q8_0>(
360 src0_d, src1_d, (block_q8_0 *) dst->data, ne00, ne01, ne02, ne03,
361 ne10, ne11, ne12, ne13, nb00, nb01,
362 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
363 break;
364 case GGML_TYPE_Q1_0:
365 set_rows_sycl_q<TIn, TIdx, block_q1_0, QK1_0, cpy_blck_f32_q1_0>(
366 src0_d, src1_d, (block_q1_0 *) dst->data, ne00, ne01, ne02, ne03,
367 ne10, ne11, ne12, ne13, nb00, nb01,
368 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
369 break;
370 case GGML_TYPE_Q2_0:
371 set_rows_sycl_q<TIn, TIdx, block_q2_0, QK2_0, cpy_blck_f32_q2_0>(
372 src0_d, src1_d, (block_q2_0 *) dst->data, ne00, ne01, ne02, ne03,
373 ne10, ne11, ne12, ne13, nb00, nb01,
374 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
375 break;
376 case GGML_TYPE_Q5_1:
377 set_rows_sycl_q<TIn, TIdx, block_q5_1, QK5_1, cpy_blck_f32_q5_1>(
378 src0_d, src1_d, (block_q5_1 *) dst->data, ne00, ne01, ne02, ne03,
379 ne10, ne11, ne12, ne13, nb00, nb01,
380 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
381 break;
382 case GGML_TYPE_Q5_0:
383 set_rows_sycl_q<TIn, TIdx, block_q5_0, QK5_0, cpy_blck_f32_q5_0>(
384 src0_d, src1_d, (block_q5_0 *) dst->data, ne00, ne01, ne02, ne03,
385 ne10, ne11, ne12, ne13, nb00, nb01,
386 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
387 break;
388 case GGML_TYPE_Q4_1:
389 set_rows_sycl_q<TIn, TIdx, block_q4_1, QK4_1, cpy_blck_f32_q4_1>(
390 src0_d, src1_d, (block_q4_1 *) dst->data, ne00, ne01, ne02, ne03,
391 ne10, ne11, ne12, ne13, nb00, nb01,
392 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
393 break;
394 case GGML_TYPE_Q4_0:
395 set_rows_sycl_q<TIn, TIdx, block_q4_0, QK4_0, cpy_blck_f32_q4_0>(
396 src0_d, src1_d, (block_q4_0 *) dst->data, ne00, ne01, ne02, ne03,
397 ne10, ne11, ne12, ne13, nb00, nb01,
398 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
399 break;
400 case GGML_TYPE_IQ4_NL:
401 set_rows_sycl_q<TIn, TIdx, block_iq4_nl, QK4_NL, cpy_blck_f32_iq4_nl>(
402 src0_d, src1_d, (block_iq4_nl *) dst->data, ne00, ne01, ne02, ne03,
403 ne10, ne11, ne12, ne13, nb00, nb01,
404 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
405 break;
406 case GGML_TYPE_MXFP4:
407 set_rows_sycl_q<TIn, TIdx, block_mxfp4, QK_MXFP4, cpy_blck_f32_mxfp4>(
408 src0_d, src1_d, (block_mxfp4 *) dst->data, ne00, ne01, ne02, ne03,
409 ne10, ne11, ne12, ne13, nb00, nb01,
410 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
411 break;
412 case GGML_TYPE_NVFP4:
413 set_rows_sycl_q<TIn, TIdx, block_nvfp4, QK_NVFP4, cpy_blck_f32_nvfp4>(
414 src0_d, src1_d, (block_nvfp4 *) dst->data, ne00, ne01, ne02, ne03,
415 ne10, ne11, ne12, ne13, nb00, nb01,
416 nb02, nb03, nb10, nb11, nb12, nb13, nb1, nb2, nb3, stream);
417 break;
418 case GGML_TYPE_Q2_K:
419 set_rows_sycl_qk_host<TIn, TIdx, block_q2_K, QK_K, quantize_row_q2_K_ref>(
420 src0, src1, dst,
421 ne00, ne01, ne02, ne03,
422 ne11, ne12,
423 nb01, nb02, nb03,
424 nb10, nb11, nb12,
425 nb1, nb2, nb3,
426 stream);
427 break;
428 case GGML_TYPE_Q3_K:
429 set_rows_sycl_qk_host<TIn, TIdx, block_q3_K, QK_K, quantize_row_q3_K_ref>(
430 src0, src1, dst,
431 ne00, ne01, ne02, ne03,
432 ne11, ne12,
433 nb01, nb02, nb03,
434 nb10, nb11, nb12,
435 nb1, nb2, nb3,
436 stream);
437 break;
438 case GGML_TYPE_Q4_K:
439 set_rows_sycl_qk_host<TIn, TIdx, block_q4_K, QK_K, quantize_row_q4_K_ref>(
440 src0, src1, dst,
441 ne00, ne01, ne02, ne03,
442 ne11, ne12,
443 nb01, nb02, nb03,
444 nb10, nb11, nb12,
445 nb1, nb2, nb3,
446 stream);
447 break;
448 case GGML_TYPE_Q5_K:
449 set_rows_sycl_qk_host<TIn, TIdx, block_q5_K, QK_K, quantize_row_q5_K_ref>(
450 src0, src1, dst,
451 ne00, ne01, ne02, ne03,
452 ne11, ne12,
453 nb01, nb02, nb03,
454 nb10, nb11, nb12,
455 nb1, nb2, nb3,
456 stream);
457 break;
458 case GGML_TYPE_Q6_K:
459 set_rows_sycl_qk_host<TIn, TIdx, block_q6_K, QK_K, quantize_row_q6_K_ref>(
460 src0, src1, dst,
461 ne00, ne01, ne02, ne03,
462 ne11, ne12,
463 nb01, nb02, nb03,
464 nb10, nb11, nb12,
465 nb1, nb2, nb3,
466 stream);
467 break;
468 case GGML_TYPE_IQ2_XXS:
469 set_rows_sycl_iq_host<TIn, TIdx, block_iq2_xxs, QK_K, quantize_iq2_xxs>(
470 src0, src1, dst,
471 ne00, ne01, ne02, ne03,
472 ne11, ne12,
473 nb01, nb02, nb03,
474 nb10, nb11, nb12,
475 nb1, nb2, nb3,
476 stream);
477 break;
478 case GGML_TYPE_IQ2_XS:
479 set_rows_sycl_iq_host<TIn, TIdx, block_iq2_xs, QK_K, quantize_iq2_xs>(
480 src0, src1, dst,
481 ne00, ne01, ne02, ne03,
482 ne11, ne12,
483 nb01, nb02, nb03,
484 nb10, nb11, nb12,
485 nb1, nb2, nb3,
486 stream);
487 break;
488 case GGML_TYPE_IQ2_S:
489 set_rows_sycl_iq_host<TIn, TIdx, block_iq2_s, QK_K, quantize_iq2_s>(
490 src0, src1, dst,
491 ne00, ne01, ne02, ne03,
492 ne11, ne12,
493 nb01, nb02, nb03,
494 nb10, nb11, nb12,
495 nb1, nb2, nb3,
496 stream);
497 break;
498 case GGML_TYPE_IQ3_XXS:
499 set_rows_sycl_qk_host<TIn, TIdx, block_iq3_xxs, QK_K, quantize_row_iq3_xxs_ref>(
500 src0, src1, dst,
501 ne00, ne01, ne02, ne03,
502 ne11, ne12,
503 nb01, nb02, nb03,
504 nb10, nb11, nb12,
505 nb1, nb2, nb3,
506 stream);
507 break;
508 case GGML_TYPE_IQ3_S:
509 set_rows_sycl_qk_host<TIn, TIdx, block_iq3_s, QK_K, quantize_row_iq3_s_ref>(
510 src0, src1, dst,
511 ne00, ne01, ne02, ne03,
512 ne11, ne12,
513 nb01, nb02, nb03,
514 nb10, nb11, nb12,
515 nb1, nb2, nb3,
516 stream);
517 break;
518 case GGML_TYPE_IQ1_S:
519 set_rows_sycl_iq_host<TIn, TIdx, block_iq1_s, QK_K, quantize_iq1_s>(
520 src0, src1, dst,
521 ne00, ne01, ne02, ne03,
522 ne11, ne12,
523 nb01, nb02, nb03,
524 nb10, nb11, nb12,
525 nb1, nb2, nb3,
526 stream);
527 break;
528 case GGML_TYPE_IQ1_M:
529 set_rows_sycl_iq_host<TIn, TIdx, block_iq1_m, QK_K, quantize_iq1_m>(
530 src0, src1, dst,
531 ne00, ne01, ne02, ne03,
532 ne11, ne12,
533 nb01, nb02, nb03,
534 nb10, nb11, nb12,
535 nb1, nb2, nb3,
536 stream);
537 break;
538 case GGML_TYPE_IQ4_XS:
539 set_rows_sycl_qk_host<TIn, TIdx, block_iq4_xs, QK_K, quantize_row_iq4_xs_ref>(
540 src0, src1, dst,
541 ne00, ne01, ne02, ne03,
542 ne11, ne12,
543 nb01, nb02, nb03,
544 nb10, nb11, nb12,
545 nb1, nb2, nb3,
546 stream);
547 break;
548 default:
549 GGML_ABORT("Unsupported tensor type: src0 %s src1 %s dst %s", ggml_type_name(dst->src[0]->type),
550 ggml_type_name(dst->src[1]->type), ggml_type_name(dst->type));
551 break;
552 }
553}
554
555void ggml_sycl_op_set_rows(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
556 scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/2);
557 const ggml_tensor * src0 = dst->src[0];
558 const ggml_tensor * src1 = dst->src[1];
559
560 GGML_ASSERT(dst->src[0]->type == GGML_TYPE_F32 || dst->src[0]->type == GGML_TYPE_F16);
561 GGML_ASSERT(dst->src[1]->type == GGML_TYPE_I64 || dst->src[1]->type == GGML_TYPE_I32);
562
563 // dispatch on the index type (src1) and the source value type (src0)
564 if (src0->type == GGML_TYPE_F16) {
565 if (src1->type == GGML_TYPE_I64) {
566 set_rows_sycl<sycl::half, int64_t>(ctx, src0, src1, dst);
567 } else {
568 set_rows_sycl<sycl::half, int32_t>(ctx, src0, src1, dst);
569 }
570 } else {
571 if (src1->type == GGML_TYPE_I64) {
572 set_rows_sycl<float, int64_t>(ctx, src0, src1, dst);
573 } else {
574 set_rows_sycl<float, int32_t>(ctx, src0, src1, dst);
575 }
576 }
577}