wai-quantum 0.6.2: the HIP matrix-instruction kernel and the Metal tensor-operation kernel #280
Loading…
Reference in a new issue
No description provided.
Delete branch "wai/quantum-wmma"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Two matrix paths, released together as wai-quantum 0.6.2 (additive; every pinned digest unchanged):
1. The HIP matrix-instruction kernel
wmma_limbs.hipis a second HIP kernel for the gate, for the gfx11 architectures. Every product is formed by the wavefront-of-32 16 × 16 × 16 bf16 matrix instruction, accumulated in f32, in the instruction's own operand layout. One wavefront multiplies sixteen pairs' limbs by the gate's limb weights in seven 16-column steps.What the instruction does with negative terms
This instruction's f32 accumulation is not exact once a negative term enters a sum. I measured it on gfx1151 with the instruction alone, in a standalone program:
1·1 + (−1)·00.99999994(1 − 2^-24)1·1 + (−1)·1−5.96e-08(−2^-24)128 − 6463.9999924−8988 + 8120 − 868−1736.00024255² + 255²1300501·1 + 1·01The CUDA kernel's signed top limb therefore fails the probe on this GPU. One coefficient comes out off by one, because the kernel truncates
0.99999994to 0.The fix is to make every operand non-negative:
x + 2^31, so all four 8-bit limbs are unsigned.(e + 2^31)·(a + 2^31)exactly.e·a = (e+2^31)(a+2^31) − 2^31(e+a) − 2^62, modulo2^64.After the fix, every case that had failed is exact. The non-integer results that IREE's HIP build gave for this GPU (0.6.0) are consistent with this behaviour, but I didn't check which instruction that build chose.
API (additive, 0.6.2)
hip::WMMA_SOURCE,WMMA_IMPLEMENTATION,wmma_implementation_id{,_of},WMMA_MUTANTS,wmma_mutate,WMMA_THREADS_PER_ITEM,DeviceIdentity::has_wmma.HipMember::wmma(): the same device and member id, under its own implementation id (hip-wmma-limbs8/…). It is probed before it is returned.HipError::Unsupported(new) for an architecture outside gfx11.Mutants (8)
2^282^62removed at half its valueMeasured
On framework-128gb's integrated GPU (gfx1151, silicon):
hip_wmmapasses 9/9: 66020 probe pairs agree, all four pinned certificates reproduce, circuits up to 22 qubits match native, and 8 of 8 mutants are killed.hip_member(9/9, 6 of 6 mutants) andhip_sv(3/3, pinb7d129d0…) pass unchanged on the same tree.On the build host, which has no HIP library,
hip_wmmaandhip_membereach pass 9/9 over no device. Clippy is clean, and I checked the new workflow step's greps against the real report.CI
wai-quantum-hip, linux-amd job: a new step that requires 9 passed, the member line, 4hip-wmma-limbs8certificates and 8 of 8 mutants.2. The Metal tensor-operation kernel
tensor_ops.metal(metal-tensor-ops-limbs8/…,MetalMember::tensor_ops()) forms every product with the shading language's 4.0 tensor operation (matmul2d: bf16 inputs, f32 accumulation). The platform maps that operation to the GPU's matrix hardware where it has it.MetalError::Unsupported.Measured (silicon)
macosrunner)The M5 run used test binaries built on the build host and run once, niced, on the dev Mac, the fleet's only M5. Memory stayed at 56% free throughout.
With signed limbs instead, a throwaway diagnostic shows the tensor op agrees on all 66020 pairs on both generations. So Apple's path is exact with negative terms; AMD's instruction is not. The platform chooses where the operation runs, and that placement isn't observed here.
On Linux all three Metal suites pass over no device, and clippy is clean on macOS and Linux.
CI
wai-quantum-metalgains a tensor-operation step on themacosrunner (family 1009): 9 passed, the member line, 4 certificates and 8 of 8 mutants. Its absent leg now runs all three suites. Family 1010 has no CI runner, so it was measured by hand.All repo checks are clean: prose, vanity metrics, tests-in-CI, concurrency, lockfiles, orphans and public names (including the
.hipfile).🤖 Generated with Claude Code
wai-quantum 0.6.2: the HIP member's matrix-instruction kernelto wai-quantum 0.6.2: the HIP matrix-instruction kernel and the Metal tensor-operation kernel