interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / workloads / reduce_max / kernel.cl

34 lines · 1158 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Pass 1: each work-group of 256 takes the max of its slice in a local-memory tree.
3// Pass 2: one work-group takes the max of the nb partials into y[0]. Padding is -INFINITY.
4__kernel void rmax_part(__global const float *x, __global float *part, const int n, __local float *s)
5{
6 int l = get_local_id(0);
7 int i = get_global_id(0);
8 s[l] = i < n ? x[i] : -INFINITY;
9 barrier(CLK_LOCAL_MEM_FENCE);
10 for (int k = get_local_size(0) / 2; k > 0; k >>= 1) {
11 if (l < k)
12 s[l] = fmax(s[l], s[l + k]);
13 barrier(CLK_LOCAL_MEM_FENCE);
14 }
15 if (l == 0)
16 part[get_group_id(0)] = s[0];
17}
18
19__kernel void rmax_fin(__global const float *part, __global float *y, const int nb, __local float *s)
20{
21 int l = get_local_id(0);
22 float a = -INFINITY;
23 for (int j = l; j < nb; j += get_local_size(0))
24 a = fmax(a, part[j]);
25 s[l] = a;
26 barrier(CLK_LOCAL_MEM_FENCE);
27 for (int k = get_local_size(0) / 2; k > 0; k >>= 1) {
28 if (l < k)
29 s[l] = fmax(s[l], s[l + k]);
30 barrier(CLK_LOCAL_MEM_FENCE);
31 }
32 if (l == 0)
33 y[0] = s[0];
34}