interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / workloads / dot / kernel.cl

35 lines · 1174 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Pass 1: each work-group of 256 forms a[i]*b[i] and sums its slice in a local-memory tree.
3// Pass 2: one work-group sums the nb partials (strided, then a tree) into y[0].
4__kernel void dot_part(__global const float *a, __global const float *b, __global float *part, const int n,
5 __local float *s)
6{
7 int l = get_local_id(0);
8 int i = get_global_id(0);
9 s[l] = i < n ? a[i] * b[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 dot_fin(__global const float *part, __global float *y, const int nb, __local float *s)
21{
22 int l = get_local_id(0);
23 float acc = 0.0f;
24 for (int j = l; j < nb; j += get_local_size(0))
25 acc += part[j];
26 s[l] = acc;
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}