@@ -22,11 +22,20 @@ static_assert(sizeof(block_q4_1) == sizeof(float) * 2 + QK4_1 / 2, "wrong q4_1 b
2222
2323#define QK4_2 16
2424typedef struct {
25- __half d; // delta
25+ __half d; // delta
2626 uint8_t qs[QK4_2 / 2 ]; // nibbles / quants
2727} block_q4_2;
2828static_assert (sizeof (block_q4_2) == sizeof (ggml_fp16_t ) + QK4_2 / 2 , " wrong q4_2 block size/padding" );
2929
30+ #define QK4_3 16
31+ typedef struct {
32+ __half d; // delta
33+ __half m; // min
34+ uint8_t qs[QK4_3 / 2 ]; // nibbles / quants
35+ } block_q4_3;
36+ static_assert (sizeof (block_q4_3) == 2 * sizeof (ggml_fp16_t ) + QK4_3 / 2 , " wrong q4_3 block size/padding" );
37+
38+
3039
3140static __global__ void dequantize_block_q4_0 (const void * vx, float * y) {
3241 const block_q4_0 * x = (const block_q4_0 *) vx;
@@ -98,6 +107,30 @@ static __global__ void dequantize_block_q4_2(const void * vx, float * y) {
98107 }
99108}
100109
110+ static __global__ void dequantize_block_q4_3 (const void * vx, float * y) {
111+ const block_q4_3 * x = (const block_q4_3 *) vx;
112+
113+ const int i = blockIdx .x ;
114+
115+ const float d = x[i].d ;
116+ const float m = x[i].m ;
117+
118+ const uint8_t * pp = x[i].qs ;
119+
120+ for (int l = 0 ; l < QK4_3; l += 2 ) {
121+ const uint8_t vi = pp[l/2 ];
122+
123+ const int8_t vi0 = vi & 0xf ;
124+ const int8_t vi1 = vi >> 4 ;
125+
126+ const float v0 = vi0*d + m;
127+ const float v1 = vi1*d + m;
128+
129+ y[i*QK4_3 + l + 0 ] = v0;
130+ y[i*QK4_3 + l + 1 ] = v1;
131+ }
132+ }
133+
101134extern " C" {
102135 __host__ void dequantize_row_q4_0_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
103136 const int nb = k / QK4_0;
@@ -113,4 +146,9 @@ extern "C" {
113146 const int nb = k / QK4_2;
114147 dequantize_block_q4_2<<<nb, 1 , 0 , stream>>> (vx, y);
115148 }
149+
150+ __host__ void dequantize_row_q4_3_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
151+ const int nb = k / QK4_3;
152+ dequantize_block_q4_3<<<nb, 1 , 0 , stream>>> (vx, y);
153+ }
116154}
0 commit comments