// 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 x: array; @group(0) @binding(1) var w: array; @group(0) @binding(2) var order: array; @group(0) @binding(3) var flag: array; @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]; } }