Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / ml / src / main / rust / shaders / mul.comp
mul.comp22 lines · 936 BRaw
| 1 | #version 450 |
| 2 | //! Elementwise product of two equally-shaped tensors. |
| 3 | //! |
| 4 | //! Distinct from `mul_channel`, which broadcasts a `[C, 1, 1]` tensor over height and width for |
| 5 | //! a squeeze-excite block. This one needs both operands to be the same shape, which is what |
| 6 | //! Supertonic's four nets want: 241 `Mul` nodes in its flow-matching sampler alone, gating and |
| 7 | //! scaling whole activations rather than whole channels. |
| 8 | //! |
| 9 | //! Not fused into the producing convolution, for the same reason `add.comp` is not: both |
| 10 | //! operands are read elsewhere too, so a fused form would need a second input binding and a |
| 11 | //! flag on the convolution shader to save one pass over data already in cache. |
| 12 | |
| 13 | #include "common.glsl" |
| 14 | |
| 15 | void main() { |
| 16 | uint index = global_index(); |
| 17 | if (index >= p.count) { |
| 18 | return; |
| 19 | } |
| 20 | float product = float(arena[p.in0 + index]) * float(arena[p.in1 + index]); |
| 21 | arena[p.out_at + index] = float16_t(product); |
| 22 | } |