interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / workloads / quant_int8 / kernel.cl

19 lines · 674 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// One work-item per row: absmax, scale = absmax / 127, q = clamp(rint(x / scale), -127, 127).
3__kernel void quant_int8(__global const float *x, __global char *q, __global float *s,
4 const int R, const int C)
5{
6 int r = get_global_id(0);
7 if (r >= R)
8 return;
9 float amax = 0.0f;
10 for (int c = 0; c < C; c++)
11 amax = fmax(amax, fabs(x[r * C + c]));
12 float sc = amax / 127.0f;
13 s[r] = sc;
14 for (int c = 0; c < C; c++) {
15 float y = sc > 0.0f ? x[r * C + c] / sc : 0.0f;
16 float v = fmin(fmax(rint(y), -127.0f), 127.0f);
17 q[r * C + c] = (char)(int)v;
18 }
19}