Spaces:
Running

EdgeAI / kernels /wedge.wgsl
encryptidai's picture
Encryptid EdgeAI from ai.encryptid.systems page, Hodge-5 weights from model repo
1d919a0 verified
Raw History Blame Contribute Delete
1.1 kB
// One residual face. The wedge is the sum over cells of (sum of the carry) times (sum of the write).
// flag[0] is 1 when that area is positive. The write is added either way: dropping it when the
// cell sums cancel removes the attention or the feed-forward and the reply comes apart.
// One thread, so the sum is the same order as the reference forward.
// No paper equation.
override DIM: u32;
override NCELL: u32;
override M: u32;
@group(0) @binding(0) var<storage, read_write> x: array<f32>;
@group(0) @binding(1) var<storage, read> w: array<f32>;
@group(0) @binding(2) var<storage, read> order: array<u32>;
@group(0) @binding(3) var<storage, read_write> flag: array<u32>;
@compute @workgroup_size(1)
fn main() {
var area = 0.0;
for (var c = 0u; c < NCELL; c++) {
var cs = 0.0;
var ws = 0.0;
let base = c * M;
for (var t = 0u; t < M; t++) {
let j = order[base + t];
cs += x[j];
ws += w[j];
}
area += cs * ws;
}
if (area > 0.0) {
flag[0] = 1u;
} else {
flag[0] = 0u;
}
for (var i = 0u; i < DIM; i++) {
x[i] += w[i];
}
}