JuliaGPU / JuliaGPU/AMDGPU.jl

Adopt `Base.Math.throw_finite_domainerror` once JuliaLang/julia#62842 lands

Open
#1,043 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
344
Forks
79
Avg merge
2d 23h
Merged PRs (30d)
27

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/device/quirks.jl and check whether JuliaLang/julia#62842 has landed, then inspect the existing copied sind/cosd bodies and sincos_domain_error override. Use the Julia nightly CI step to exercise the feature-detected branch; done means the Base helper is overridden with the literal @gpu_throw message while the compatibility fallback remains until the 1.14 floor.

Written by the indexing model from the issue text.

Assessment

Domain
hpc
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.