Repository navigation
Add overrides of Base methods that format exception messages - #43
Merged
Merged
Conversation
|
Documentation preview: https://juliagpu.github.io/GPUToolbox.jl/previews/PR43/ |
Julia 1.10 and 1.11 throw some `Rational` errors with a message that interpolates the integer type, which GPU compilers can't compile, so that `Rational` arithmetic fails to compile for most back-ends. Add a table with overrides of these helpers that throw the same exceptions with a constant message.
maleadt
force-pushed
the
tb/throw-overrides
branch
from
November 10, 2026 09:57
d9f45da to
859f7d7
Compare
This was referenced Nov 10, 2026
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.
On Julia 1.10,
Rationalarithmetic in a kernel fails to compile on most back-ends. Constructing aRational, which*and+do, can reachBase.__throw_rational_argerror_typemin(T), which interpolates the integer type into its message ("invalid rational: denominator can't be typemin($T)"). GPU compilers can't compile that formatting code: PoCL, oneAPI, OpenCL and AMDGPU report anInvalidIRErrorwith dynamic calls, and Metal crashes in LLVM's dead argument elimination. Negating aRationalhas the same problem through__throw_rational_numerator_typemin(T), on Julia 1.10 and 1.11. Julia 1.11 removed the first helper, and Julia 1.12 builds the second message with aLazyString. CUDA.jl overrides the first helper in its own quirks.This adds a third shared table,
throw_overrides, with overrides of these helpers that throw the same exception type with a constant message, which GPUCompiler can compile (it drops the exception and reports the throw through the back-end's exception runtime). Each override is only defined on the Julia versions whose Base needs it, so the table is empty on 1.12 and later. The table's reason is narrow: Base helpers whose message is built at run time. For now it only holds theRationalhelpers. Other helpers that interpolate values, likeBase._throw_dmrs(reached byreshape, and overridden by CUDA.jl and AMDGPU.jl) orBroadcast.throwdm, are left out of scope; they could be added later.The test infers each override and checks that it only constructs and throws the exception from literals, which Base's methods don't on 1.10 and 1.11. Stacking the table on KernelAbstractions' PoCL back end and on Metal makes a
Rational{Int}multiply-add kernel compile and produce the right results on Julia 1.10, and a typemin denominator raises aKernelException.