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/controls/reduce_drop_last/kernel.cl # 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 / controls / reduce_drop_last / kernel.cl` 35 lines ยท 1211 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // CONTROL (deliberately wrong): pass 1 reads x[0..n-2] only, dropping the last element. 3 // Pass 1: each work-group of 256 sums its slice in a local-memory tree and writes one partial. 4 // Pass 2: one work-group sums the nb partials (strided, then a tree) into y[0]. 5 __kernel void rsum_part(__global const float *x, __global float *part, const int n, __local float *s) 6 { 7 int l = get_local_id(0); 8 int i = get_global_id(0); 9 s[l] = i < n - 1 ? x[i] : 0.0f; 10 barrier(CLK_LOCAL_MEM_FENCE); 11 for (int k = get_local_size(0) / 2; k > 0; k >>= 1) { 12 if (l < k) 13 s[l] += s[l + k]; 14 barrier(CLK_LOCAL_MEM_FENCE); 15 } 16 if (l == 0) 17 part[get_group_id(0)] = s[0]; 18 } 19 20 __kernel void rsum_fin(__global const float *part, __global float *y, const int nb, __local float *s) 21 { 22 int l = get_local_id(0); 23 float a = 0.0f; 24 for (int j = l; j < nb; j += get_local_size(0)) 25 a += part[j]; 26 s[l] = a; 27 barrier(CLK_LOCAL_MEM_FENCE); 28 for (int k = get_local_size(0) / 2; k > 0; k >>= 1) { 29 if (l < k) 30 s[l] += s[l + k]; 31 barrier(CLK_LOCAL_MEM_FENCE); 32 } 33 if (l == 0) 34 y[0] = s[0]; 35 }