Repository navigation
Add a fastmath option to CUDABackend - #3282
Merged
Merged
Conversation
Forward an opt-in backend setting to compilation and Enzyme jobs while preserving the default IEEE atomic behavior. Document why global Float32 atomic additions use CAS loops with LLVM 23 and why expression-level @fastmath does not change their denormal mode.
Member
Author
|
Oh wait, I just saw llvm/llvm-project#206154 now. I'll just backport that to fix the performance regression, but this PR seems useful regardless to give people full control. |
Contributor
CUDA.jl BenchmarksDetails
This comment was automatically generated by workflow using github-action-benchmark. |
NVPTX_LLVM_Backend_jll 23.1.2+0 backports llvm/llvm-project#206154, which lowers global Float32 atomic additions to native, subnormal-flushing atom.add.f32 regardless of the kernel's denormal mode. Fast math therefore no longer changes atomic lowering, and the tests that expected a CAS loop (and preserved subnormals) in IEEE mode fail. Probe the option with a plain addition instead, which selects add.ftz.f32 under fast math, drop the atomic lowering tests, and remove the atomics motivation from the performance tutorial.
vchuravy
approved these changes
Sep 22, 2026
Member
Author
|
CI failure unrelated, will be handled by #3283. |
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a
fastmathoption toCUDABackend, so that KernelAbstractions kernels can opt into the same kernel-wide floating-point relaxations as@cuda fastmath=true: fast-math flags on every floating-point instruction, less precise square roots, and flushing ofFloat32subnormals to sign-preserving zero.Like
@cuda, the default follows Julia's--math-modesetting. The existing positionalCUDABackend(prefer_blocks, always_inline)constructor keeps working, and the option is also forwarded to the compiler job used by Enzyme (EnzymeCore.compiler_job_from_backend).An earlier version of this PR motivated the option with global-memory
Float32atomic additions, which LLVM 23.1.1 lowered to a CAS loop in IEEE mode. That no longer applies: NVPTX_LLVM_Backend_jll 23.1.2 backports llvm/llvm-project#206154, so these atomics lower to the native (subnormal-flushing)atom.add.f32regardless of fast math, and the atomics tests and documentation have been dropped accordingly.