Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / ml / src / main / rust / shaders / add_bcast.comp
add_bcast.comp32 lines · 1.3 KiBRaw
| 1 | #version 450 |
| 2 | //! `out[c][y][x] = a[c][y][x] + b[c]`, a per-channel shift. |
| 3 | //! |
| 4 | //! Four uses, one per main block of Supertonic's flow-matching sampler. Each block is |
| 5 | //! conditioned on the timestep by a `Linear` from the 64-dimensional time embedding to 512 |
| 6 | //! numbers, added to every position: `x = x + W t + b`. |
| 7 | //! |
| 8 | //! # Why the timestep side is not in the plan at all |
| 9 | //! |
| 10 | //! `W t + b` depends only on `current_step` and `total_step`, two scalars, so the host computes |
| 11 | //! all four 512-vectors and passes them in as one `[2048, 1, 1]` tensor that |
| 12 | //! `nets::Builder::slice_channels` cuts up. A sinusoidal embedding and a two-layer MLP for |
| 13 | //! 2,048 numbers is not worth a dispatch, let alone the `Sin` and `Cos` shaders it would need. |
| 14 | //! |
| 15 | //! # The mirror of `mul_bcast.comp` |
| 16 | //! |
| 17 | //! Same indexing, and for the same reason the two operands are separate push constants: the |
| 18 | //! shift is a tensor in its own right rather than a slice of the one being shifted. |
| 19 | |
| 20 | #include "common.glsl" |
| 21 | |
| 22 | void main() { |
| 23 | uint index = global_index(); |
| 24 | if (index >= p.count) { |
| 25 | return; |
| 26 | } |
| 27 | uint oc, oy, ox; |
| 28 | unpack(index, oc, oy, ox); |
| 29 | float value = float(arena[p.in0 + index]); |
| 30 | float shift = float(arena[p.in1 + oc]); |
| 31 | arena[p.out_at + index] = float16_t(value + shift); |
| 32 | } |