Expand description
The scalar twin of crate::q8_0_shader, and the byte→word packing
both the twin and the real upload path share.
§What this is for
This repo’s rule for a kernel it cannot run is the one every
unsafe SIMD arm here already follows and that ferrox-cuda’s
mul_mm_ref follows for CUDA: a scalar twin implementing identical
arithmetic, held against an independent reference.
matvec_reference is not “a Q8_0 matvec that should agree”. It is
a transcription of the shader: same word-indexed byte extraction,
same integer f16 decode, same (d * q) * x term shape, same
block-ascending then element-ascending accumulation order, same
row < rows guard. Read it beside emit_main; a line here with no
counterpart there is a bug in one of them.
Two independent references check it, and neither shares any code with it:
f16_to_f32against thehalfcrate, over all 65,536 f16 bit patterns.- the whole matvec against
ferrox_quant::dequant_q8_0followed by a plain dot product – a different unpacker, a different f16 decoder, and the same numbers.
What that does not establish is that the emitted SPIR-V says what
this file says; the two are hand-transcribed from each other. On a
machine with a Vulkan driver, crate::device closes that gap by
running the real shader and comparing. See the crate docs for
whether that has happened.
Functions§
- f16_
to_ f32 - The shader’s integer f16 decode, in Rust.
- matvec_
reference - Host emulation of the Q8_0 matvec shader.
- pack_
words - Pack raw bytes into the
uint[]a storage buffer holds, zero-padding the tail.