1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var<workgroup> scratch: array<f32, 64>;
struct Params {
count: u32,
scale: f32,
}
@group(0) @binding(0) var<storage, read_write> params: Params;
struct DataBuffer {
values: array<f32, 64>,
}
@group(0) @binding(1) var<storage, read_write> data: DataBuffer;
@compute @workgroup_size(64, 1, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>, @builtin(local_invocation_id) local_id: vec3<u32>) {
let idx = local_id.x;
scratch[idx] = (data.values[idx] * params.scale);
workgroupBarrier();
if ((idx < 32)) {
scratch[idx] = (scratch[idx] + scratch[(idx + 32)]);
}
workgroupBarrier();
data.values[idx] = scratch[idx];
}