Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
cov/c3 ▾

Modern-Apps.git / library / ml / src / main / rust / shaders / gemv_a_control.comp

gemv_a_control.comp43 lines · 1.8 KiBRaw
1#version 450
2//! VARIANT A — CONTROL. Byte-for-byte the body of `shaders/probe_ssbo.comp`.
3//!
4//! TEMPORARY probe shader for task 9. Source of truth is
5//! `analysis/gemv_probe/gemv_a_control.comp`; this copy exists only because `compileShaders`
6//! compiles `shaders/*.comp` and direct `glslc` invocation is unavailable in this
7//! environment. Not referenced by `pipeline.rs::SPIRV`, so it is compiled but not shipped.
8//! Delete both this and the other four `gemv_*.comp` when the experiment is done.
9//!
10//! One XOR per 16 bytes, one load in flight per lane. This is the shader that measured
11//! ~20 GB/s on the G715, and it is reproduced here rather than reused so that all five
12//! variants run through the identical harness. If A does not land on ~20 GB/s, the
13//! harness differs from `imageprobe::compare` and nothing else in the set is comparable.
14//!
15//! The accumulator is xored rather than added so no arithmetic can be strength-reduced
16//! away, and is written out under a condition that never fires so the loop cannot be
17//! eliminated as dead.
18
19layout(local_size_x = 64) in;
20
21layout(set = 0, binding = 0) readonly buffer Source { uvec4 data[]; };
22layout(set = 0, binding = 1) buffer Sink { uint sink[]; };
23// Binding 2 (activations) is declared in the descriptor set layout for every variant so
24// one layout serves all five. A shader that does not use it simply does not declare it,
25// which is legal.
26
27layout(push_constant) uniform Push {
28 /// `uvec4`s in the source.
29 uint quads;
30};
31
32void main() {
33 uint lane = gl_GlobalInvocationID.x;
34 uint stride = gl_NumWorkGroups.x * 64u;
35 uvec4 acc = uvec4(0u);
36 for (uint at = lane; at < quads; at += stride) {
37 acc ^= data[at];
38 }
39 uint folded = acc.x ^ acc.y ^ acc.z ^ acc.w;
40 if (folded == 0xFFFFFFFFu) {
41 sink[0] = folded;
42 }
43}