Skip to main content

Module shaders

Module shaders 

Source
Expand description

Compute-shader sources for the GPU optimizer steps, in WGSL and MSL.

§Why these shaders exist instead of scirs2_core’s registry kernels

scirs2-core 0.6.5 registers adam_optimizer, sgd_optimizer, rmsprop_optimizer, adagrad_optimizer and lamb_optimizer with real WGSL bodies, but they are not drivable-as-correct through the public API:

  • every hyper-parameter lives in a multi-field var<uniform> block, and the wgpu backend packs those scalars by iterating a HashMap<String, KernelParam> (gpu/backends/wgpu.rs, create_bind_group_from_params). The byte order of the resulting uniform buffer is therefore the map’s iteration order — effectively random per process — and there is no public set_bytes to bypass it;
  • their metal_source is empty, so a Metal context resolves them to an empty shader.

The shaders here carry every scalar in a storage buffer bound by name, which is deterministic on both backends, and are compiled through scirs2_core::gpu::GpuCompiler::compile (real naga validation on wgpu, a real MTLLibrary on Metal).

§The buffer naming convention

The Metal backend binds buffers to argument-table indices by looking their names up in the fixed list ["x", "y", "a", "b", "result", "output"] and only then falls back to a non-deterministic hash-map order. Every kernel below therefore uses only those six names, in that order, so the binding indices are fully determined. The wgpu backend binds by name against the WGSL declarations, so the same names work there unchanged.

The per-kernel meaning of each name is documented on each source constant.

§Scalar packing convention

Every kernel takes a hyper-parameter buffer of f32. Integer fields are carried through it bit-for-bit (bitcast<u32> in WGSL, as_type<uint> in MSL) so element counts above 2^24 stay exact.

Modules§

msl
Metal Shading Language sources for the optimizer kernels.
wgsl
WGSL sources for the optimizer kernels (WebGPU backend).

Enums§

CollectiveKernel
Kernels used by crate::multi_gpu for collective (cross-device) operations. Kept as a sibling to OptimizerKernel rather than folded into it: a reduction is not an optimizer step, and giving it its own type keeps that honest at the API level.
OptimizerKernel
The optimizer kernels this crate ships.

Constants§

WORKGROUP_SIZE
Threads per workgroup / threadgroup used by every optimizer kernel.