← 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 61 of file gemm_kernels_q4k_q8k.c.

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