PTX: lower @fastmath sqrt to NVPTX approx intrinsics (for LLVM 18)#805
Merged
Conversation
Add `PTXFSqrtFastPass` alongside `PTXFDivFastPass`. It rewrites
`afn`-flagged `llvm.sqrt.f{32,64}` to `llvm.nvvm.sqrt.approx{,.ftz}.f`
(f32) and `rcp(rsqrt(x))` (f64), which is the same sequences NVPTX'
`getSqrtEstimate` emits on LLVM 21+, where per-instruction `afn` and the
function `unsafe-fp-math` attribute are honored. Like `PTXFDivFastPass`'s
f32 path, both sqrt paths are temporary backports for LLVM 18, which only
consults `TargetMachine.Options.UnsafeFPMath` (unreachable through LLVM.jl).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #805 +/- ##
==========================================
+ Coverage 75.69% 75.95% +0.25%
==========================================
Files 25 25
Lines 3983 4026 +43
==========================================
+ Hits 3015 3058 +43
Misses 968 968 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
maleadt
added a commit
to JuliaGPU/CUDA.jl
that referenced
this pull request
May 21, 2026
Building on JuliaGPU/GPUCompiler.jl#805, JuliaGPU/GPUCompiler.jl#804, JuliaGPU/GPUCompiler.jl#800, avoid some of the uses of `libdevice`'s intrinsics, instead emitting vanilla LLVM IR and having GPUCompiler.jl post-process it into what we need in PTX. This has many advantages, including (potentially) better optimization, compatibility with LLVM tools like Enzyme, etc. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Add
PTXFSqrtFastPassalongsidePTXFDivFastPass. It rewritesafn-flaggedllvm.sqrt.f{32,64}tollvm.nvvm.sqrt.approx{,.ftz}.f(f32) andrcp(rsqrt(x))(f64), which is the same sequences NVPTX'getSqrtEstimateemits on LLVM 21+ where per-instructionafnand the functionunsafe-fp-mathattribute are honored. LikePTXFDivFastPass's f32 path, both sqrt paths are temporary backports for LLVM 18, which only consultsTargetMachine.Options.UnsafeFPMath(unreachable through LLVM.jl).This will allow us to get rid of most of libdevice in CUDA.jl.