Spaces:
Running

File size: 1,098 Bytes
1d919a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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];
  }
}