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

Go to the source code of this file.

Data Structures

struct  ck_block_iq3_xxs

Functions

static float ck_dot_iq3_xxs_q8_k (size_t blocks, const ck_block_iq3_xxs *weights, const block_q8_K *input)

Function Documentation

◆ ck_dot_iq3_xxs_q8_k()

float ck_dot_iq3_xxs_q8_k ( size_t blocks,
const ck_block_iq3_xxs * weights,
const block_q8_K * input )
inlinestatic

Definition at line 16 of file packed_iq3_xxs_dot.h.

18{
19 float result = 0.0f;
20 for (size_t b = 0; b < blocks; ++b) {
21 const ck_block_iq3_xxs *w = weights + b;
22 const block_q8_K *x = input + b;
23#if defined(__AVX2__)
24 __m256i weighted_lanes = _mm256_setzero_si256();
25#else
26 int32_t weighted = 0;
27#endif
28 for (size_t group = 0; group < QK_K / 32; ++group) {
29 const uint8_t *meta = w->group_metadata + group * 4;
30 const uint32_t bits = (uint32_t)meta[0] | (uint32_t)meta[1] << 8
31 | (uint32_t)meta[2] << 16 | (uint32_t)meta[3] << 24;
32#if defined(__AVX2__)
33 const __m256i group_scale = _mm256_set1_epi32((int)(1 + 2 * (bits >> 28)));
34 for (size_t sub = 0; sub < 4; sub += 2) {
35 const uint8_t *codes = w->grid + group * 8 + sub * 2;
36 const uint64_t lo = ck_iq3_grid_pair(ck_iq3_xxs_codebook[codes[0]], ck_iq3_xxs_codebook[codes[1]]);
37 const uint64_t hi = ck_iq3_grid_pair(ck_iq3_xxs_codebook[codes[2]], ck_iq3_xxs_codebook[codes[3]]);
38 const unsigned s0 = ck_iq2_xs_signs((bits >> (7 * sub)) & 127);
39 const unsigned s1 = ck_iq2_xs_signs((bits >> (7 * (sub + 1))) & 127);
40 weighted_lanes = ck_iq3_accumulate_16(weighted_lanes, lo, hi, s0, s1,
41 x->qs + group * 32 + sub * 8, group_scale);
42 }
43#else
44 int32_t sum = 0;
45 for (size_t sub = 0; sub < 4; ++sub) {
46 const unsigned sign = ck_iq2_xs_signs((bits >> (7 * sub)) & 127);
47 const size_t offset = group * 8 + sub * 2;
48 for (size_t part = 0; part < 2; ++part) {
49 const uint32_t grid = ck_iq3_xxs_codebook[w->grid[offset + part]];
50 for (size_t j = 0; j < 4; ++j) {
51 const size_t lane = 4 * part + j;
52 const int mag = (int)((grid >> (8 * j)) & 255);
53 sum += x->qs[group * 32 + sub * 8 + lane] * ((sign & (1u << lane)) ? -mag : mag);
54 }
55 }
56 }
57 weighted += (int32_t)(1 + 2 * (bits >> 28)) * sum;
58#endif
59 }
60#if defined(__AVX2__)
61 const int32_t weighted = ck_iq3_sum_lanes(weighted_lanes);
62#endif
63 const float scale = CK_FP16_TO_FP32(w->d) * x->d;
64 const volatile float contribution = scale * (float)weighted;
65 result += contribution;
66 }
67 return result * 0.25f;
68}
#define CK_FP16_TO_FP32(x)
#define QK_K
static const uint32_t ck_iq3_xxs_codebook[256]
static uint8_t ck_iq2_xs_signs(unsigned code)
int8_t qs[256]
uint8_t group_metadata[QK_K/8]
uint8_t grid[QK_K/4]

References CK_FP16_TO_FP32, ck_iq2_xs_signs(), ck_iq3_xxs_codebook, block_q8_K::d, ck_block_iq3_xxs::d, ck_block_iq3_xxs::grid, ck_block_iq3_xxs::group_metadata, QK_K, and block_q8_K::qs.

Referenced by iq3_xxs_expert_matvec().