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 aHashMap<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 publicset_bytesto bypass it; - their
metal_sourceis 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§
- Collective
Kernel - Kernels used by
crate::multi_gpufor collective (cross-device) operations. Kept as a sibling toOptimizerKernelrather than folded into it: a reduction is not an optimizer step, and giving it its own type keeps that honest at the API level. - Optimizer
Kernel - The optimizer kernels this crate ships.
Constants§
- WORKGROUP_
SIZE - Threads per workgroup / threadgroup used by every optimizer kernel.