Transformer architecture implemented in TypeScript with WebGPU.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
nn/shader/normv.wgsl

29 lines
558 B

alias number = f32;
struct VectorBatch {
size: vec4<u32>,
data: array<number>,
}
struct ScalarBatch {
size: vec4<u32>,
data: array<number>,
}
@group(0) @binding(0)
var<storage, read> v: VectorBatch;
@group(0) @binding(1)
var<storage, read_write> result: ScalarBatch;
@compute @workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
result.size.z = v.size.z;
var s = 0f;
let lo = global_id.z * v.size.x;
for (var i = 0u; i < v.size.x; i++) {
s += v.data[lo + i];
}
result.data[global_id.z] = sqrt(s);
}