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/argmax.wgsl

37 lines
765 B

struct MatrixBatch {
size: vec4<u32>,
data: array<f32>,
}
struct FVectorBatch {
size: vec4<u32>,
data: array<f32>,
}
struct UVectorBatch {
size: vec4<u32>,
data: array<u32>,
}
@group(0) @binding(0)
var<storage, read> ps: MatrixBatch;
@group(0) @binding(1)
var<storage, read_write> result: UVectorBatch;
@compute @workgroup_size(1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
result.size.x = ps.size.y;
result.size.z = ps.size.z;
var mi = 0u;
var mp = 0f;
var pi = global_id.z * ps.size.y * ps.size.x + global_id.x * ps.size.x;
for (var i = 0u; i < ps.size.x; i++) {
if (ps.data[pi] > mp) {
mi = i;
mp = ps.data[pi];
}
pi++;
}
result.data[global_id.z * result.size.x + global_id.x] = mi;
}