@@ -36,6 +36,13 @@ struct ggml_cuda_type_traits<GGML_TYPE_IQ5_K_R4> {
36
36
static constexpr int qi = QI5_XS;
37
37
};
38
38
39
+ template <>
40
+ struct ggml_cuda_type_traits <GGML_TYPE_IQ1_M_R4> {
41
+ static constexpr int qk = 32 ;
42
+ static constexpr int qr = 2 ;
43
+ static constexpr int qi = 4 ;
44
+ };
45
+
39
46
// Reminder:
40
47
// constexpr int qk = ggml_cuda_type_traits<type>::qk;
41
48
// constexpr int qi = ggml_cuda_type_traits<type>::qi;
@@ -338,7 +345,6 @@ __device__ __forceinline__ void vec_dot_iq4_ks_r4_q8_1(
338
345
}
339
346
}
340
347
341
- // TODO
342
348
__device__ __forceinline__ void vec_dot_iq1_s_r4_q8_1 (
343
349
const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & kbx, const int & iqs, float * result) {
344
350
@@ -356,7 +362,7 @@ __device__ __forceinline__ void vec_dot_iq1_s_r4_q8_1(
356
362
for (int k = 0 ; k < 4 ; ++k) minus = ggml_cuda_dp4a (0x01010101 , q8[4 *(iqs/2 )+k], minus);
357
363
358
364
for (int i = 0 ; i < 4 ; ++i) {
359
- float dl = ( float ) dptr[i]*(2 *((bq1->qh [i] >> 12 ) & 7 ) + 1 ) * d8;
365
+ float dl = __half2float ( dptr[i]) *(2 *((bq1->qh [i] >> 12 ) & 7 ) + 1 ) * d8;
360
366
float ml = dl * (bq1->qh [i] & 0x8000 ? -1 -IQ1S_DELTA : -1 +IQ1S_DELTA);
361
367
grid32[0 ] = iq1s_grid_gpu[bq1->qs [4 *iqs+i] | (((bq1->qh [i] >> 3 *iqs) & 7 ) << 8 )];
362
368
grid32[1 ] = (grid32[0 ] >> 4 ) & 0x0f0f0f0f ;
@@ -370,6 +376,38 @@ __device__ __forceinline__ void vec_dot_iq1_s_r4_q8_1(
370
376
}
371
377
}
372
378
379
+ __device__ __forceinline__ void vec_dot_iq1_m_r4_q8_1 (
380
+ const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & kbx, const int & iqs, float * result) {
381
+
382
+ const half * dptr = (const half *)vbq;
383
+ const block_iq1_m_r4 * bq1 = (const block_iq1_m_r4 *)(dptr + 4 ) + kbx;
384
+
385
+ // iqs is 0 or 2
386
+ const float d8 = __low2float (bq8_1->ds );
387
+ const int32_t * q8 = (const int *)bq8_1->qs ;
388
+
389
+ int32_t grid32[2 ];
390
+ const int * igrid = (const int *)grid32;
391
+
392
+ int minus1 = ggml_cuda_dp4a (0x01010101 , q8[4 *(iqs/2 )+0 ], ggml_cuda_dp4a (0x01010101 , q8[4 *(iqs/2 )+1 ], 0 ));
393
+ int minus2 = ggml_cuda_dp4a (0x01010101 , q8[4 *(iqs/2 )+2 ], ggml_cuda_dp4a (0x01010101 , q8[4 *(iqs/2 )+3 ], 0 ));
394
+
395
+ for (int i = 0 ; i < 4 ; ++i) {
396
+ float dl = __half2float (dptr[i])*((bq1->scales [i] >> 4 *(iqs/2 )) & 0xf ) * d8;
397
+ float ml1 = dl * (bq1->qh [4 *(iqs/2 )+i] & 0x08 ? -1 -IQ1M_DELTA : -1 +IQ1M_DELTA);
398
+ float ml2 = dl * (bq1->qh [4 *(iqs/2 )+i] & 0x80 ? -1 -IQ1M_DELTA : -1 +IQ1M_DELTA);
399
+ grid32[0 ] = iq1s_grid_gpu[bq1->qs [4 *iqs+i] | ((bq1->qh [4 *(iqs/2 )+i] & 0x07 ) << 8 )];
400
+ grid32[1 ] = (grid32[0 ] >> 4 ) & 0x0f0f0f0f ;
401
+ grid32[0 ] &= 0x0f0f0f0f ;
402
+ int sumi = ggml_cuda_dp4a (igrid[0 ], q8[4 *(iqs/2 )+0 ], ggml_cuda_dp4a (igrid[1 ], q8[4 *(iqs/2 )+1 ], 0 ));
403
+ grid32[0 ] = iq1s_grid_gpu[bq1->qs [4 *iqs+i+4 ] | ((bq1->qh [4 *(iqs/2 )+i] & 0x70 ) << 4 )];
404
+ grid32[1 ] = (grid32[0 ] >> 4 ) & 0x0f0f0f0f ;
405
+ grid32[0 ] &= 0x0f0f0f0f ;
406
+ sumi = ggml_cuda_dp4a (igrid[0 ], q8[4 *(iqs/2 )+2 ], ggml_cuda_dp4a (igrid[1 ], q8[4 *(iqs/2 )+3 ], sumi));
407
+ result[i] += dl * sumi + ml1 * minus1 + ml2*minus2;
408
+ }
409
+ }
410
+
373
411
#define VDR_IQ4_KS_Q8_1_MMVQ 4
374
412
#define VDR_IQ4_KS_Q8_1_MMQ 4
375
413
@@ -1131,6 +1169,14 @@ void mul_mat_vec_iq1_s_r4_q8_1_cuda(
1131
1169
iqk_mul_mat_vec_q_cuda<GGML_TYPE_IQ1_S_R4, 2 , vec_dot_iq1_s_r4_q8_1, 4 >(vx, vy, dst, ids_data, ncols_x, nrows_x, nrows_y, ncols_y, nrows_dst, ne2, nb02, nb12, nb2, ids_nb0, stream);
1132
1170
}
1133
1171
1172
+ void mul_mat_vec_iq1_m_r4_q8_1_cuda (
1173
+ const void * vx, const void * vy, float * dst, const char * ids_data,
1174
+ const int ncols_x, const int nrows_x, const int nrows_y, const int ncols_y, const int nrows_dst,
1175
+ const int ne2, const uint64_t nb02, const uint64_t nb12, const uint64_t nb2, int64_t ids_nb0, cudaStream_t stream) {
1176
+
1177
+ iqk_mul_mat_vec_q_cuda<GGML_TYPE_IQ1_M_R4, 2 , vec_dot_iq1_m_r4_q8_1, 4 >(vx, vy, dst, ids_data, ncols_x, nrows_x, nrows_y, ncols_y, nrows_dst, ne2, nb02, nb12, nb2, ids_nb0, stream);
1178
+ }
1179
+
1134
1180
void mul_mat_vec_iq5_k_r4_q8_1_cuda (
1135
1181
const void * vx, const void * vy, float * dst, const char * ids_data,
1136
1182
const int ncols_x, const int nrows_x, const int nrows_y, const int ncols_y, const int nrows_dst,
0 commit comments