Repository navigation
Keep checked conversions out of the exception runtime - #568
Merged
Merged
Conversation
Without consistent overlays, the overlays on Base's throw paths keep the BigFloat-based `Float32(π, RoundDown)` from being evaluated at compile time, so comparing against `π` or `ℯ` in a kernel pulled MPFR calls into device code. Override these conversions with their precomputed values on 1.10, as Metal.jl does.
The exception runtime reached from the throw overlays performed checked integer conversions (`Int32(1)`, `UInt64(0)`, and `UInt32(1)` through the `1u32` literal in `get_local_id`/`get_group_id`), whose error paths lead back into `throw_inexacterror`. On Julia 1.12, inference merges the effects of all frames in such a cycle, so the inconsistent overlay reached through the runtime's atomics tainted Base's conversion methods and disabled concrete evaluation of any foldable code using them. For example, `x < π` pulled MPFR calls into the kernel. Same issue as JuliaGPU/Metal.jl#567.
maleadt
force-pushed
the
tb/consistent-runtime
branch
from
October 21, 2026 08:52
d1428ec to
68865aa
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #568 +/- ##
=======================================
Coverage 87.73% 87.73%
=======================================
Files 18 18
Lines 1737 1737
=======================================
Hits 1524 1524
Misses 213 213 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Same issue as JuliaGPU/Metal.jl#567, fixed there in JuliaGPU/Metal.jl#1070.
On Julia 1.12,
x < πin a kernel fails to compile: MPFR calls end up in device code because the BigFloat-basedFloat32(π, RoundDown)is not evaluated at compile time. The reason is an inference cycle through the exception runtime:Julia 1.12 merges the effects of all frames in a cycle. The runtime's atomics reach UnsafeAtomics'
is_native(), which is (correctly) not a consistent overlay, so that merge taintsInt32(::Int64),UInt32(::Int64)andUInt64(::Int64)and disables concrete evaluation of any foldable code that uses them.This PR keeps throwing calls out of the runtime: the constants are now written with
%, and SPIRVIntrinsics'1u32is interpolated so the value is built when the method is defined. With that, no cycle passes through an overlay any more. I checked on 1.12 and 1.13 with PoCL.The new
concrete evaluationtest fails on 1.12 without the fix.On 1.10, which lacks consistent overlays, the conversion can't be evaluated at compile time at all. SPIRVIntrinsics now overrides the
π/ℯconversions with their precomputed values there, as Metal.jl does.oneAPI.jl isn't affected today, because its exception runtime is a stub. It does use the same
get_local_idcode, though, so the SPIRVIntrinsics change is worth releasing.