Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/openaccel-lab/blob/main/workloads/quant_int8/kernel.cu # openaccel-lab aien-dev/openaccel-lab Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `openaccel-lab / workloads / quant_int8 / kernel.cu` 27 lines ยท 889 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 #include 3 4 // One thread per row: absmax, scale = absmax / 127, q = clamp(rint(x / scale), -127, 127). 5 __global__ void quant_int8(const float *x, signed char *q, float *s, int R, int C) 6 { 7 int r = blockIdx.x * blockDim.x + threadIdx.x; 8 if (r >= R) 9 return; 10 float amax = 0.0f; 11 for (int c = 0; c < C; c++) 12 amax = fmaxf(amax, fabsf(x[r * C + c])); 13 float sc = amax / 127.0f; 14 s[r] = sc; 15 for (int c = 0; c < C; c++) { 16 float y = sc > 0.0f ? x[r * C + c] / sc : 0.0f; 17 float v = fminf(fmaxf(rintf(y), -127.0f), 127.0f); 18 q[r * C + c] = (signed char)(int)v; 19 } 20 } 21 22 void oal_launch(const long long *p, void *const *buf) 23 { 24 int R = (int)p[0]; 25 int C = (int)p[1]; 26 quant_int8<<<(R + 63) / 64, 64>>>((const float *)buf[0], (signed char *)buf[1], (float *)buf[2], R, C); 27 }