convert.cpp 21.8 KB
Newer Older
xuxzh1's avatar
init  
xuxzh1 committed
1
2
3
4
5
#include "convert.hpp"
#include "dequantize.hpp"
#include "presets.hpp"

template <int qk, int qr, dequantize_kernel_t dequantize_kernel, typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
6
static void dequantize_block(const void * __restrict__ vx, dst_t * __restrict__ y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
7
                             const sycl::nd_item<3> &item_ct1) {
xuxzh1's avatar
update  
xuxzh1 committed
8
    const int64_t i = 2 * (item_ct1.get_local_range(2) * item_ct1.get_group(2) +
xuxzh1's avatar
init  
xuxzh1 committed
9
10
11
12
13
14
                       item_ct1.get_local_id(2));

    if (i >= k) {
        return;
    }

xuxzh1's avatar
update  
xuxzh1 committed
15
16
17
18
    const int64_t ib = i/qk; // block index
    const int64_t iqs = (i%qk)/qr; // quant index
    const int64_t iybs = i - i%qk; // y block start index
    const int64_t y_offset = qr == 1 ? 1 : qk/2;
xuxzh1's avatar
init  
xuxzh1 committed
19
20
21
22
23
24
25
26
27
28
29

    // dequantize
    dfloat2 v;
    dequantize_kernel(vx, ib, iqs, v);

    y[iybs + iqs + 0] = v.x();
    y[iybs + iqs + y_offset] = v.y();
}

template <int qk, int qr, dequantize_kernel_t dequantize_kernel, typename dst_t>
static void dequantize_block_sycl(const void *__restrict__ vx,
xuxzh1's avatar
update  
xuxzh1 committed
30
                                  dst_t *__restrict__ y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
31
                                  dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
32
    const int64_t num_blocks = (k + 2*SYCL_DEQUANTIZE_BLOCK_SIZE - 1) / (2*SYCL_DEQUANTIZE_BLOCK_SIZE);
xuxzh1's avatar
init  
xuxzh1 committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});
        stream->parallel_for(
            sycl::nd_range<3>(
                sycl::range<3>(1, 1, num_blocks) *
                    sycl::range<3>(1, 1, SYCL_DEQUANTIZE_BLOCK_SIZE),
                sycl::range<3>(1, 1, SYCL_DEQUANTIZE_BLOCK_SIZE)),
            [=](sycl::nd_item<3> item_ct1) {
                dequantize_block<qk, qr, dequantize_kernel>(vx, y, k, item_ct1);
            });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
48
static void dequantize_row_q2_K_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
49
                                     dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
50
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#if QK_K == 256
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 64),
                                               sycl::range<3>(1, 1, 64)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q2_K(vx, y, item_ct1);
                             });
    }
#else
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q2_K(vx, y, item_ct1);
                             });
    }

#endif
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
80
static void dequantize_row_q3_K_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
81
                                     dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
82
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#if QK_K == 256
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 64),
                                               sycl::range<3>(1, 1, 64)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q3_K(vx, y, item_ct1);
                             });
    }
#else
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q3_K(vx, y, item_ct1);
                             });
    }
#endif
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
111
static void dequantize_row_q4_0_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
112
                                     dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
113
114
    const int64_t nb32 = k / 32;
    const int64_t nb = (k + 255) / 256;
xuxzh1's avatar
init  
xuxzh1 committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q4_0(vx, y, nb32, item_ct1);
                             });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
129
static void dequantize_row_q4_1_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
130
                                     dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
131
132
    const int64_t nb32 = k / 32;
    const int64_t nb = (k + 255) / 256;
xuxzh1's avatar
init  
xuxzh1 committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q4_1(vx, y, nb32, item_ct1);
                             });
    }
}


template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
148
static void dequantize_row_q4_K_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
149
                                     dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
150
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            sycl::local_accessor<uint8_t, 1> scale_local_acc(sycl::range<1>(12), cgh);
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q4_K(vx, y, get_pointer(scale_local_acc), item_ct1);
                             });
        });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
168
static void dequantize_row_q5_K_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
169
                                     dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
170
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#if QK_K == 256
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 64),
                                               sycl::range<3>(1, 1, 64)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q5_K(vx, y, item_ct1);
                             });
    }
#else
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q5_K(vx, y, item_ct1);
                             });
    }

#endif
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
200
static void dequantize_row_q6_K_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
201
                                     dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
202
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#if QK_K == 256
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 64),
                                               sycl::range<3>(1, 1, 64)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q6_K(vx, y, item_ct1);
                             });
    }
#else
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_q6_K(vx, y, item_ct1);
                             });
    }

#endif
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
232
static void dequantize_row_iq1_s_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
233
                                        dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
234
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_iq1_s(
                                     vx, y, item_ct1, iq1s_grid_gpu
                                     );
                             });
        });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
253
static void dequantize_row_iq1_m_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
254
                                        dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
255
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_iq1_m(
                                     vx, y, item_ct1, iq1s_grid_gpu
                                     );
                             });
        });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
274
static void dequantize_row_iq2_xxs_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
275
                                        dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
276
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_iq2_xxs(
                                     vx, y, item_ct1, iq2xxs_grid,
                                     ksigns_iq2xs, kmask_iq2xs);
                             });
        });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
295
static void dequantize_row_iq2_xs_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
296
                                       dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
297
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_iq2_xs(
                                     vx, y, item_ct1, iq2xs_grid,
                                     ksigns_iq2xs, kmask_iq2xs);
                             });
        });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
316
static void dequantize_row_iq2_s_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
317
                                      dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
318
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_iq2_s(vx, y, item_ct1);
                             });
        });
    }
}


template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
336
static void dequantize_row_iq3_xxs_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
337
                                        dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
338
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_iq3_xxs(
                                     vx, y, item_ct1, iq3xxs_grid,
                                     ksigns_iq2xs, kmask_iq2xs);
                             });
        });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
357
static void dequantize_row_iq3_s_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
358
                                        dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
359
    const int64_t nb = k / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->submit([&](sycl::handler &cgh) {
            cgh.parallel_for(sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                                   sycl::range<3>(1, 1, 32),
                                               sycl::range<3>(1, 1, 32)),
                             [=](sycl::nd_item<3> item_ct1) {
                                 dequantize_block_iq3_s(
                                     vx, y, item_ct1, kmask_iq2xs, iq3s_grid);
                             });
        });
    }
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
377
static void dequantize_row_iq4_xs_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
378
                                       dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
379
    const int64_t nb = (k + QK_K - 1) / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#if QK_K == 64
    dequantize_row_iq4_nl_sycl(vx, y, k, stream);
#else
      {
            dpct::has_capability_or_fail(stream->get_device(),
                                         {sycl::aspect::fp16});

            stream->submit([&](sycl::handler &cgh) {
                  cgh.parallel_for(
                      sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                            sycl::range<3>(1, 1, 32),
                                        sycl::range<3>(1, 1, 32)),
                      [=](sycl::nd_item<3> item_ct1) {
                            dequantize_block_iq4_xs(vx, y, item_ct1);
                      });
            });
      }
#endif
}

template <typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
401
static void dequantize_row_iq4_nl_sycl(const void *vx, dst_t *y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
402
                                       dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
403
    const int64_t nb = (k + QK_K - 1) / QK_K;
xuxzh1's avatar
init  
xuxzh1 committed
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
      {
            dpct::has_capability_or_fail(stream->get_device(),
                                         {sycl::aspect::fp16});

            stream->submit([&](sycl::handler &cgh) {
                  cgh.parallel_for(
                      sycl::nd_range<3>(sycl::range<3>(1, 1, nb) *
                                            sycl::range<3>(1, 1, 32),
                                        sycl::range<3>(1, 1, 32)),
                      [=](sycl::nd_item<3> item_ct1) {
                            dequantize_block_iq4_nl(vx, y, item_ct1);
                      });
            });
      }
}

template <typename src_t, typename dst_t>
xuxzh1's avatar
update  
xuxzh1 committed
421
static void convert_unary(const void * __restrict__ vx, dst_t * __restrict__ y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
422
                          const sycl::nd_item<3> &item_ct1) {
xuxzh1's avatar
update  
xuxzh1 committed
423
424
    const int64_t work_group_size = item_ct1.get_local_range(2);
    const int64_t global_id = item_ct1.get_local_id(2) + work_group_size * item_ct1.get_group(2);
xuxzh1's avatar
init  
xuxzh1 committed
425

xuxzh1's avatar
update  
xuxzh1 committed
426
    // make each work-item deal with more elements since sycl global range can not exceed max int
xuxzh1's avatar
init  
xuxzh1 committed
427
    const src_t * x = (src_t *) vx;
xuxzh1's avatar
update  
xuxzh1 committed
428
429
430
    for (int64_t i = global_id; i < k; i += work_group_size * item_ct1.get_group_range(2)) {
        y[i] = x[i];
    }
xuxzh1's avatar
init  
xuxzh1 committed
431
432
433
434
}

template <typename src_t, typename dst_t>
static void convert_unary_sycl(const void *__restrict__ vx,
xuxzh1's avatar
update  
xuxzh1 committed
435
                               dst_t *__restrict__ y, const int64_t k,
xuxzh1's avatar
init  
xuxzh1 committed
436
                               dpct::queue_ptr stream) {
xuxzh1's avatar
update  
xuxzh1 committed
437
438
439
440
441
442
    const int64_t num_blocks = (k + SYCL_DEQUANTIZE_BLOCK_SIZE - 1) / SYCL_DEQUANTIZE_BLOCK_SIZE;

    // decrease global range when it exceeds the max int
    int64_t local_size = downsample_sycl_global_range(num_blocks, SYCL_DEQUANTIZE_BLOCK_SIZE);
    sycl::range<3> block_nums(1, 1, num_blocks);
    sycl::range<3> local_range(1, 1, local_size);
xuxzh1's avatar
init  
xuxzh1 committed
443
444
445
446
447
    {
        dpct::has_capability_or_fail(stream->get_device(),
                                     {sycl::aspect::fp16});

        stream->parallel_for(
xuxzh1's avatar
update  
xuxzh1 committed
448
            sycl::nd_range<3>(block_nums * local_range, local_range),
xuxzh1's avatar
init  
xuxzh1 committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
            [=](sycl::nd_item<3> item_ct1) {
                convert_unary<src_t>(vx, y, k, item_ct1);
            });
    }
}

to_fp16_sycl_t ggml_get_to_fp16_sycl(ggml_type type) {
    switch (type) {
        case GGML_TYPE_Q4_0:
            return dequantize_block_sycl<QK4_0, QR4_0, dequantize_q4_0>;
        case GGML_TYPE_Q4_1:
            return dequantize_block_sycl<QK4_1, QR4_1, dequantize_q4_1>;
        case GGML_TYPE_Q5_0:
            return dequantize_block_sycl<QK5_0, QR5_0, dequantize_q5_0>;
        case GGML_TYPE_Q5_1:
            return dequantize_block_sycl<QK5_1, QR5_1, dequantize_q5_1>;
        case GGML_TYPE_Q8_0:
            return dequantize_block_sycl<QK8_0, QR8_0, dequantize_q8_0>;
        case GGML_TYPE_Q2_K:
            return dequantize_row_q2_K_sycl;
        case GGML_TYPE_Q3_K:
            return dequantize_row_q3_K_sycl;
        case GGML_TYPE_Q4_K:
            return dequantize_row_q4_K_sycl;
        case GGML_TYPE_Q5_K:
            return dequantize_row_q5_K_sycl;
        case GGML_TYPE_Q6_K:
            return dequantize_row_q6_K_sycl;
        case GGML_TYPE_IQ1_S:
            return dequantize_row_iq1_s_sycl;
        case GGML_TYPE_IQ1_M:
            return dequantize_row_iq1_m_sycl;
        case GGML_TYPE_IQ2_XXS:
            return dequantize_row_iq2_xxs_sycl;
        case GGML_TYPE_IQ2_XS:
            return dequantize_row_iq2_xs_sycl;
        case GGML_TYPE_IQ2_S:
            return dequantize_row_iq2_s_sycl;
        case GGML_TYPE_IQ3_XXS:
            return dequantize_row_iq3_xxs_sycl;
        case GGML_TYPE_IQ3_S:
            return dequantize_row_iq3_s_sycl;
        case GGML_TYPE_IQ4_XS:
            return dequantize_row_iq4_xs_sycl;
        case GGML_TYPE_IQ4_NL:
            return dequantize_row_iq4_nl_sycl;
        case GGML_TYPE_F32:
            return convert_unary_sycl<float>;
        default:
            return nullptr;
    }
}

to_fp32_sycl_t ggml_get_to_fp32_sycl(ggml_type type) {
    switch (type) {
        case GGML_TYPE_Q4_0:
            return dequantize_row_q4_0_sycl;
        case GGML_TYPE_Q4_1:
            return dequantize_row_q4_1_sycl;
        case GGML_TYPE_Q5_0:
            return dequantize_block_sycl<QK5_0, QR5_0, dequantize_q5_0>;
        case GGML_TYPE_Q5_1:
            return dequantize_block_sycl<QK5_1, QR5_1, dequantize_q5_1>;
        case GGML_TYPE_Q8_0:
            return dequantize_block_sycl<QK8_0, QR8_0, dequantize_q8_0>;
        case GGML_TYPE_Q2_K:
            return dequantize_row_q2_K_sycl;
        case GGML_TYPE_Q3_K:
            return dequantize_row_q3_K_sycl;
        case GGML_TYPE_Q4_K:
            return dequantize_row_q4_K_sycl;
        case GGML_TYPE_Q5_K:
            return dequantize_row_q5_K_sycl;
        case GGML_TYPE_Q6_K:
            return dequantize_row_q6_K_sycl;
        case GGML_TYPE_IQ1_S:
            return dequantize_row_iq1_s_sycl;
        case GGML_TYPE_IQ1_M:
            return dequantize_row_iq1_m_sycl;
        case GGML_TYPE_IQ2_XXS:
            return dequantize_row_iq2_xxs_sycl;
        case GGML_TYPE_IQ2_XS:
            return dequantize_row_iq2_xs_sycl;
        case GGML_TYPE_IQ2_S:
            return dequantize_row_iq2_s_sycl;
        case GGML_TYPE_IQ3_XXS:
            return dequantize_row_iq3_xxs_sycl;
        case GGML_TYPE_IQ3_S:
            return dequantize_row_iq3_s_sycl;
        case GGML_TYPE_IQ4_XS:
            return dequantize_row_iq4_xs_sycl;
        case GGML_TYPE_IQ4_NL:
            return dequantize_row_iq4_nl_sycl;
        case GGML_TYPE_F16:
            return convert_unary_sycl<sycl::half>;
        default:
            return nullptr;
    }
}