← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
quantize_row_q8_k_avx512.c File Reference

AVX-512 entrypoint for exact Q8_K row quantization. More...

Go to the source code of this file.

Functions

void quantize_row_q8_k_avx512 (const float *x, void *vy, int k)
 
void quantize_row_q8_k_ref (const float *x, void *vy, int k)
 

Detailed Description

AVX-512 entrypoint for exact Q8_K row quantization.

Definition in file quantize_row_q8_k_avx512.c.

Function Documentation

◆ quantize_row_q8_k_avx512()

void quantize_row_q8_k_avx512 ( const float *  x,
void *  vy,
int  k 
)

Definition at line 8 of file quantize_row_q8_k_avx512.c.

8 {
9 /*
10 * Q8_K bytes are part of the numerical ABI consumed by Q4_K/Q6_K dots.
11 * Keep AVX-512 on the reference contract until a vector implementation is
12 * byte-exact for every block, including multi-block activation rows.
13 */
14 quantize_row_q8_k_ref(x, vy, k);
15}
void quantize_row_q8_k_ref(const float *x, void *vy, int k)

References quantize_row_q8_k_ref().

Referenced by quantize_row_q8_k().

◆ quantize_row_q8_k_ref()

void quantize_row_q8_k_ref ( const float *  x,
void *  vy,
int  k 
)

Definition at line 66 of file gemm_kernels_q4k_q8k.c.

66 {
67 if (!x || !vy || k <= 0) {
68 return;
69 }
70 assert(k % QK_K == 0);
71 const int nb = k / QK_K;
72 block_q8_K *y = (block_q8_K *)vy;
73
74 for (int i = 0; i < nb; ++i) {
75 float max = 0.0f;
76 float amax = 0.0f;
77 for (int j = 0; j < QK_K; ++j) {
78 float ax = fabsf(x[j]);
79 if (ax > amax) {
80 amax = ax;
81 max = x[j];
82 }
83 }
84 if (!amax) {
85 y[i].d = 0.0f;
86 memset(y[i].qs, 0, sizeof(y[i].qs));
87 memset(y[i].bsums, 0, sizeof(y[i].bsums));
88 x += QK_K;
89 continue;
90 }
91
92 const float iscale = -127.0f / max;
93 for (int j = 0; j < QK_K; ++j) {
94 /* llama.cpp rounds the multiply before adding nearest_int's magic
95 * constant. Contracting both operations changes Q8_K tie cases. */
96 float scaled = iscale * x[j];
97 int v = ck_nearest_int(scaled);
98 if (v > 127) {
99 v = 127;
100 }
101 if (v < -128) {
102 v = -128;
103 }
104 y[i].qs[j] = (int8_t)v;
105 }
106
107 for (int j = 0; j < QK_K / 16; ++j) {
108 int sum = 0;
109 const int8_t *qs = &y[i].qs[j * 16];
110 for (int ii = 0; ii < 16; ++ii) {
111 sum += qs[ii];
112 }
113 y[i].bsums[j] = (int16_t)sum;
114 }
115
116 y[i].d = 1.0f / iscale;
117 x += QK_K;
118 }
119}
#define QK_K
static int ck_nearest_int(float fval)
int8_t qs[256]
int16_t bsums[256/16]

References block_q8_K::bsums, ck_nearest_int(), block_q8_K::d, QK_K, and block_q8_K::qs.

Referenced by quantize_row_q8_k(), and quantize_row_q8_k_avx512().