Skip to main content

nvfp4_matmul

Function nvfp4_matmul 

Source
pub fn nvfp4_matmul(
    m: usize,
    n: usize,
    k: usize,
    tensor_scale: f32,
) -> Result<Vec<u8>, QuantizedBuildError>
Expand description

Build output = activations @ decoded_weights.T * tensor_scale.

Slots: 0 FP32 activations [1, M, K]; 1 packed E2M1 bytes [1, NK/2]; 2 E4M3 block scales [1, NK/16]; 3 FP32 output [1, M, N]. Byte buffers use INT8 solely as a bit-preserving storage carrier. Low nibble is the first K element; each row has K/16 scales. Weights and scales remain runtime inputs, so changing a block does not require rebuilding the program. Scaling order matches Kore’s projection: multiply E2M1 by its block scale, accumulate the FP32 matrix product, then apply the separate FP32 tensor scale.