Skip to content

PTX: make FMA contraction a PTXCompilerTarget option - #1134

Open
gcol33 wants to merge 1 commit into
JuliaGPU:mainfrom
gcol33:fma-contraction
Open

gcol33 wants to merge 1 commit into
JuliaGPU:mainfrom
gcol33:fma-contraction

Conversation

@gcol33

@gcol33 gcol33 commented Nov 29, 2026 •

Copy link
Copy Markdown

Closes #1133.

PTX code generation always let the back-end contract multiply-add pairs, as nvcc does, so kernels could not reproduce CPU results bit for bit. The only workaround was redefining mcgen, which the compiler cache cannot see.

PTXCompilerTarget gets fma_contraction::Bool = true. With false, the NVPTX back-end is called with fma_contraction=false and libNVVM with -fma=0. Plain multiplies and adds are then emitted with .rn, so ptxas cannot fuse them either, while operations the IR marks contractable (muladd, @fastmath) are still fused, as on the CPU. The field is part of the target's hash and of the cache owner, so kernels compiled with and without contraction don't share cached results.

How to expose the option is up to the back-end packages. With CUDA.jl, @cuda fma_contraction=false already works, because extra keywords are forwarded to the target.

Tests in test/ptx.jl cover both back-ends: the PTX with contraction off uses mul.rn/sub.rn and no fma, an explicit muladd still gives fma.rn, and the target hash and cache owner differ from the default.

@maleadt maleadt changed the title PTX: FMA contraction as a PTXCompilerTarget option, part of the cache key PTX: make FMA contraction a PTXCompilerTarget option Dec 2, 2026
@maleadt

maleadt commented Dec 2, 2026

Copy link
Copy Markdown
Member

Thanks. Rebased, and I removed the preference; GPUCompiler.jl is not user-facing, so the back-end should drive this.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.31%. Comparing base (51de390) to head (6e400b3).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/ptx.jl 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1134      +/-   ##
==========================================
- Coverage   92.99%   87.31%   -5.68%     
==========================================
  Files          32       32              
  Lines        8574     8525      -49     
==========================================
- Hits         7973     7444     -529     
- Misses        601     1081     +480     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

PTX code generation always let the back-end contract multiply-add pairs, as
nvcc does, so kernels could not reproduce CPU results bit for bit. The new
`fma_contraction` field (default true) controls this for both the NVPTX and
NVVM back-ends. It is part of the target's hash and therefore of the cache
owner, so kernels compiled with and without contraction don't share 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.

PTX: FMA contraction as a PTXCompilerTarget option, part of the cache key

2 participants