Skip to content

cuda: add opt-in instance-scoped full-F32 matmul precision - #861

Closed
mirek190 wants to merge 1 commit into
0xShug0:mainfrom
mirek190:agent/cuda-f32-matmul-policy-20261010
Closed

mirek190 wants to merge 1 commit into
0xShug0:mainfrom
mirek190:agent/cuda-f32-matmul-policy-20261010

Conversation

@mirek190

@mirek190 mirek190 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

CUDA may round F32 inputs through TF32 or quantize/round activations in other matmul paths, even when a model requests F32 accumulation. Phonon-2's duration decisions exposed this: text could match while word boundaries shifted by 80–240 ms.

This adds ggml_backend_cuda_set_f32_matmul(backend, true), an opt-in policy owned by one CUDA backend context. It disables TF32 on that context's existing/future cuBLAS handles and selects existing F32 computation instead of paths that round or quantize activations. Configure it before graph preparation; policy changes after CUDA graph capture are rejected. Other instances retain their previous math mode and dispatch.

No CUDA kernel implementation is replaced. HIP/MUSA retain their existing math-mode branch and reject this NVIDIA-specific control. Those platforms were not built/tested locally. This support is separate from the Phonon model PR, as CONTRIBUTING.md requires for GGML/backend changes.

Validation on Windows, MSVC 14.43, CUDA 12.4, RTX 3090:

  • cuda_matmul_precision_test passes with F32, BF16 and Q8 weights at 8/64-column shapes; strict results match a double-accumulation reference within relative L2 1e-5 (measured approximately 7e-8–1.2e-7).
  • A second, default backend produces bit-identical results before and after strict inference on the first instance.
  • Downstream Phonon integration: F32/Q8 original-reference text and word timing match on 20/20 clips on CUDA. Before this work the ten-clip suite had F32/Q8 CUDA timing matches of 9/10. Disabling only TF32 left additional Q8 holdout failures; avoiding activation quantization removes those too.
  • The stricter arithmetic has a latency cost. Separate-pass warm HTTP medians for a 11.9925 s clip, excluding loading: F32 approximately 44 ms before / 46 ms after; Q8 approximately 40 ms before / 50 ms after. These are not a controlled speedup experiment.

Reproduce the GPU probe (the model is not needed):

cmake -S . -B build/cuda-precision -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=parakeet_tdt \
  -DENGINE_ENABLE_CUDA=ON -DENGINE_ENABLE_VULKAN=ON \
  -DENGINE_BUILD_TESTS=ON -DCMAKE_CUDA_ARCHITECTURES=86
cmake --build build/cuda-precision --parallel 6 --target cuda_matmul_precision_test
ctest --test-dir build/cuda-precision -R '^cuda_matmul_precision_test$' --output-on-failure

Local evidence: outputs/phonon2-pr-20261010/, including the integration matrix and combined-build CTest log. The separate Phonon model PR is #863; it contains the converter, real-weight/reference checks, timestamps, package documentation and measured memory use. Merge this support before enabling that model's strict CUDA path. Its committed validation report and portable JSON evidence record the downstream integration results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant