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
40
41
42
43
44
//! WGSL shader source constants for matmul, RMSNorm, copy, add, and related GPU kernels.
pub const MATMUL_BT_SHADER: &str = concat!;
pub const RMS_NORM_SHADER: &str = concat!;
pub const COPY_SHADER: &str = concat!;
pub const ADD_SHADER: &str = concat!;
pub const SILU_SHADER: &str = concat!;
pub const MUL_SHADER: &str = concat!;
pub const ROPE_SHADER: &str = concat!;
pub const ATTENTION_SCORES_SHADER: &str =
concat!;
// Guarantee scope (#795): the fail-closed
// zero-row contract below has been verified on this repository's native
// Metal-backed WGPU adapter (`GpuModelState::new`'s
// `wgpu::PowerPreference::HighPerformance` request, backend `Backends::all()`
// resolving to Metal on macOS CI/dev hosts). It is NOT a WGSL-portable
// guarantee: WGSL's Finite Math Assumption
// (https://www.w3.org/TR/WGSL/#finite-math-assumption) permits an
// implementation to assume NaN and infinities are absent during shader
// execution, so a different backend (Vulkan/DX12/browser WebGPU) may
// legally replace a poisoned value with an indeterminate finite-looking one
// at any point after it participates in WGSL floating-point arithmetic,
// before `is_non_finite`'s bitcast ever inspects it. Reading the raw score
// before the `* scale` multiply (below) narrows the window but cannot close
// it for backends whose compiler chooses to optimize on the assumption
// upstream of that read. The claim this kernel makes is therefore: "fails
// closed on the tested native backend". The CPU parity / differential
// (`e2e-parity.yml`, HF-vs-lattice greedy-token) and CPU-side
// `attention::softmax_row` gates define the reference semantics for future
// backend-specific differential coverage; detecting a defeated guard on an
// untested WGPU backend requires adding that backend to a differential run —
// those gates do not execute this shader on Vulkan/DX12/browser WebGPU today.
pub const ATTENTION_SOFTMAX_SHADER: &str =
concat!;
pub const ATTENTION_CONTEXT_SHADER: &str =
concat!;