Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / ml / src / main / rust / shaders / mul_bcast.comp
mul_bcast.comp25 lines · 869 BRaw
| 1 | #version 450 |
| 2 | //! `out[c][y][x] = a[c][y][x] * b[c]`, the excite half of a squeeze-excite block. |
| 3 | //! |
| 4 | //! Ten uses, all in the selfie net, `b` always the `C x 1 x 1` output of `gap.comp` put |
| 5 | //! through a 1x1 convolution and a sigmoid. |
| 6 | //! |
| 7 | //! The broadcast is over H and W only, so the second operand is indexed by channel |
| 8 | //! alone. Four of the ten multiply a tensor that is **not** the one that was pooled — |
| 9 | //! see the note in `nets::selfie` — which is why the two operands are separate push |
| 10 | //! constants rather than one tensor read twice. |
| 11 | |
| 12 | #include "common.glsl" |
| 13 | |
| 14 | void main() { |
| 15 | uint index = global_index(); |
| 16 | if (index >= p.count) { |
| 17 | return; |
| 18 | } |
| 19 | uint oc, oy, ox; |
| 20 | unpack(index, oc, oy, ox); |
| 21 | |
| 22 | float value = float(arena[p.in0 + index]); |
| 23 | float gate = float(arena[p.in1 + oc]); |
| 24 | arena[p.out_at + index] = float16_t(value * gate); |
| 25 | } |