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/rmsnorm/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 / rmsnorm / kernel.cu` 31 lines ยท 913 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 #include 3 4 #define NT 128 5 6 // one block of NT threads per row 7 __global__ void rmsnorm(const float *x, const float *w, float *y, long long D) 8 { 9 __shared__ float red[NT]; 10 int t = threadIdx.x; 11 const float *xr = x + (long long)blockIdx.x * D; 12 float *yr = y + (long long)blockIdx.x * D; 13 float acc = 0.0f; 14 for (long long k = t; k < D; k += NT) 15 acc += xr[k] * xr[k]; 16 red[t] = acc; 17 __syncthreads(); 18 for (int h = NT / 2; h > 0; h >>= 1) { 19 if (t < h) 20 red[t] += red[t + h]; 21 __syncthreads(); 22 } 23 float rs = 1.0f / sqrtf(red[0] / (float)D + 1e-6f); 24 for (long long k = t; k < D; k += NT) 25 yr[k] = xr[k] * rs * w[k]; 26 } 27 28 void oal_launch(const long long *p, void *const *buf) 29 { 30 rmsnorm<<<(unsigned)p[0], NT>>>((const float *)buf[0], (const float *)buf[1], (float *)buf[2], p[1]); 31 }