src/device/quirks.jl copies Base's sind and cosd bodies verbatim (#1041) so that the inline DomainError, which boxes its untyped val field and drags in the malloc hostcall, can be replaced with @gpu_throw. Base had no overridable helper for those two, so copying was the only lever.
JuliaLang/julia#62842 adds a shared throw_finite_domainerror(f::Symbol, x) in base/math.jl and routes all ten "only defined for finite x" trig sites through it: sin, cos, tan, sincos, sinpi, cospi, sincospi, tanpi, sind and cosd. Once it merges, the copied bodies and our existing sincos_domain_error override collapse into one method:
@static if isdefined(Base.Math, :throw_finite_domainerror)
@device_override Base.Math.throw_finite_domainerror(f::Symbol, x) =
@gpu_throw "DomainError: argument is not finite"
else
# current copied bodies plus the sincos_domain_error override
end
The reason string has to stay a literal: @gpu_throw maps its prefix to an ExceptionCode at macro expansion time and falls back to UNKNOWN for anything interpolated, so the function name cannot be spliced into it.
Feature detection rather than a VERSION check, so it keeps working if the change is ever backported.
The helper lands in 1.14, so the copied bodies stay until our compat floor passes 1.14. The @static branch gets exercised by the Julia nightly CI step as soon as the Base PR merges.
src/device/quirks.jlcopies Base'ssindandcosdbodies verbatim (#1041) so that the inlineDomainError, which boxes its untypedvalfield and drags in the malloc hostcall, can be replaced with@gpu_throw. Base had no overridable helper for those two, so copying was the only lever.JuliaLang/julia#62842 adds a shared
throw_finite_domainerror(f::Symbol, x)inbase/math.jland routes all ten "only defined for finite x" trig sites through it:sin,cos,tan,sincos,sinpi,cospi,sincospi,tanpi,sindandcosd. Once it merges, the copied bodies and our existingsincos_domain_erroroverride collapse into one method:The reason string has to stay a literal:
@gpu_throwmaps its prefix to anExceptionCodeat macro expansion time and falls back toUNKNOWNfor anything interpolated, so the function name cannot be spliced into it.Feature detection rather than a
VERSIONcheck, so it keeps working if the change is ever backported.The helper lands in 1.14, so the copied bodies stay until our compat floor passes 1.14. The
@staticbranch gets exercised by theJulia nightlyCI step as soon as the Base PR merges.