@@ -37,6 +37,15 @@ 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
+ __half m; // min
44
+ int32_t qh; // 5-th bit of quants
45
+ uint8_t qs[QK5_0 / 2 ]; // nibbles / quants
46
+ } block_q5_0;
47
+ static_assert (sizeof (block_q5_0) == 2 * sizeof(ggml_fp16_t ) + sizeof(int32_t ) + QK5_0 / 2, "wrong q5_0 block size/padding");
48
+
40
49
#define QK8_0 32
41
50
typedef struct {
42
51
float d; // delta
@@ -138,6 +147,35 @@ static __global__ void dequantize_block_q4_3(const void * vx, float * y) {
138
147
}
139
148
}
140
149
150
+ static __global__ void dequantize_block_q5_0 (const void * vx, float * y) {
151
+ const block_q5_0 * x = (const block_q5_0 *) vx;
152
+
153
+ const int i = blockIdx .x ;
154
+
155
+ const float d = x[i].d ;
156
+ const float m = x[i].m ;
157
+
158
+ const uint8_t * pp = x[i].qs ;
159
+
160
+ const uint32_t qh = x[i].qh ;
161
+
162
+ for (int l = 0 ; l < QK5_0; l += 2 ) {
163
+ const uint8_t vi = pp[l/2 ];
164
+
165
+ const int8_t vh0 = ((qh & (1 << (l + 0 ))) >> (l + 0 )) << 4 ;
166
+ const int8_t vh1 = ((qh & (1 << (l + 1 ))) >> (l + 1 )) << 4 ;
167
+
168
+ const int8_t vi0 = (vi & 0xf ) | vh0;
169
+ const int8_t vi1 = (vi >> 4 ) | vh1;
170
+
171
+ const float v0 = vi0*d + m;
172
+ const float v1 = vi1*d + m;
173
+
174
+ y[i*QK5_0 + l + 0 ] = v0;
175
+ y[i*QK5_0 + l + 1 ] = v1;
176
+ }
177
+ }
178
+
141
179
static __global__ void dequantize_block_q8_0 (const void * vx, float * y) {
142
180
const block_q8_0 * x = (const block_q8_0 *) vx;
143
181
@@ -174,6 +212,11 @@ void dequantize_row_q4_3_cuda(const void * vx, float * y, int k, cudaStream_t st
174
212
dequantize_block_q4_3<<<nb, 1 , 0 , stream>>> (vx, y);
175
213
}
176
214
215
+ void dequantize_row_q5_0_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
216
+ const int nb = k / QK5_0;
217
+ dequantize_block_q5_0<<<nb, 1 , 0 , stream>>> (vx, y);
218
+ }
219
+
177
220
void dequantize_row_q8_0_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
178
221
const int nb = k / QK8_0;
179
222
dequantize_block_q8_0<<<nb, 1 , 0 , stream>>> (vx, y);
0 commit comments