@@ -37,6 +37,14 @@ typedef struct {
37
37
} block_q4_3;
38
38
static_assert (sizeof (block_q4_3) == 2 * sizeof(ggml_fp16_t ) + QK4_3 / 2, "wrong q4_3 block size/padding");
39
39
40
+ #define QK5_0 32
41
+ typedef struct {
42
+ __half d; // delta
43
+ uint8_t qh[4 ]; // 5-th bit of quants
44
+ uint8_t qs[QK5_0 / 2 ]; // nibbles / quants
45
+ } block_q5_0;
46
+ static_assert (sizeof (block_q5_0) == sizeof(ggml_fp16_t ) + sizeof(uint32_t ) + QK5_0 / 2, "wrong q5_0 block size/padding");
47
+
40
48
#define QK5_1 32
41
49
typedef struct {
42
50
__half d; // delta
@@ -147,6 +155,35 @@ static __global__ void dequantize_block_q4_3(const void * vx, float * y) {
147
155
}
148
156
}
149
157
158
+ static __global__ void dequantize_block_q5_0 (const void * vx, float * y) {
159
+ const block_q5_0 * x = (const block_q5_0 *) vx;
160
+
161
+ const int i = blockIdx .x ;
162
+
163
+ const float d = x[i].d ;
164
+
165
+ const uint8_t * pp = x[i].qs ;
166
+
167
+ uint32_t qh;
168
+ memcpy (&qh, x[i].qh , sizeof (qh));
169
+
170
+ for (int l = 0 ; l < QK5_0; l += 2 ) {
171
+ const uint8_t vi = pp[l/2 ];
172
+
173
+ const int8_t vh0 = ((qh & (1 << (l + 0 ))) >> (l + 0 )) << 4 ;
174
+ const int8_t vh1 = ((qh & (1 << (l + 1 ))) >> (l + 1 )) << 4 ;
175
+
176
+ const int8_t vi0 = ((vi & 0xf ) | vh0);
177
+ const int8_t vi1 = ((vi >> 4 ) | vh1);
178
+
179
+ const float v0 = (vi0 - 16 )*d;
180
+ const float v1 = (vi1 - 16 )*d;
181
+
182
+ y[i*QK5_0 + l + 0 ] = v0;
183
+ y[i*QK5_0 + l + 1 ] = v1;
184
+ }
185
+ }
186
+
150
187
static __global__ void dequantize_block_q5_1 (const void * vx, float * y) {
151
188
const block_q5_1 * x = (const block_q5_1 *) vx;
152
189
@@ -212,6 +249,11 @@ void dequantize_row_q4_3_cuda(const void * vx, float * y, int k, cudaStream_t st
212
249
dequantize_block_q4_3<<<nb, 1 , 0 , stream>>> (vx, y);
213
250
}
214
251
252
+ void dequantize_row_q5_0_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
253
+ const int nb = k / QK5_0;
254
+ dequantize_block_q5_0<<<nb, 1 , 0 , stream>>> (vx, y);
255
+ }
256
+
215
257
void dequantize_row_q5_1_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
216
258
const int nb = k / QK5_1;
217
259
dequantize_block_q5_1<<<nb, 1 , 0 , stream>>> (vx, y);
0 commit comments