← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
packed_q3_k_dot.h File Reference
#include "ckernel_quant.h"

Go to the source code of this file.

Data Structures

struct  ck_block_q3_k

Functions

static float ck_dot_q3_k_q8_k (size_t blocks, const ck_block_q3_k *weights, const block_q8_K *input)

Function Documentation

◆ ck_dot_q3_k_q8_k()

float ck_dot_q3_k_q8_k ( size_t blocks,
const ck_block_q3_k * weights,
const block_q8_K * input )
inlinestatic

Definition at line 13 of file packed_q3_k_dot.h.

15{
16 float sums[8] = {0};
17 for (size_t b = 0; b < blocks; ++b) {
18 const ck_block_q3_k *w = weights + b;
19 const block_q8_K *x = input + b;
20 int32_t weighted[8] = {0};
21 for (unsigned g = 0; g < QK_K / 16; ++g) {
22 const unsigned lo = (w->scales[g % 8] >> (4 * (g / 8))) & 15;
23 const unsigned hi = (w->scales[8 + g % 4] >> (2 * (g / 4))) & 3;
24 const int scale = (int)(lo | (hi << 4)) - 32;
25 const unsigned base = (g % 2) * 16;
26 const unsigned mask = 1u << (g / 2);
27 const unsigned shift = 2 * ((g / 2) % 4);
28 for (unsigned j = 0; j < 16; ++j) {
29 const int q = (w->low[32 * (g / 8) + base + j] >> shift) & 3;
30 const int signed_q = q - ((w->high[base + j] & mask) ? 0 : 4);
31 weighted[j % 8] += scale * signed_q * x->qs[g * 16 + j];
32 }
33 }
34 const float d = CK_FP16_TO_FP32(w->d) * x->d;
35 for (unsigned i = 0; i < 8; ++i) {
36 const volatile float contribution = d * (float)weighted[i];
37 sums[i] += contribution;
38 }
39 }
40 float result = 0;
41 for (unsigned i = 0; i < 8; ++i) result += sums[i];
42 return result;
43}
#define CK_FP16_TO_FP32(x)
#define QK_K
int8_t qs[256]
uint8_t scales[12]
uint8_t high[QK_K/8]
uint8_t low[QK_K/4]
int32_t int32_t int32_t int32_t int32_t mask
Definition tokenizer.h:235

References CK_FP16_TO_FP32, block_q8_K::d, ck_block_q3_k::d, ck_block_q3_k::high, ck_block_q3_k::low, mask, QK_K, block_q8_K::qs, and ck_block_q3_k::scales.

Referenced by q3_k_expert_matvec().