Skip to content

rft: make gamma(a,x) GPU compatible#520

Open
haakon-e wants to merge 1 commit intoJuliaMath:masterfrom
haakon-e:he/rft-make-gamma-a-x-gpu
Open

rft: make gamma(a,x) GPU compatible#520
haakon-e wants to merge 1 commit intoJuliaMath:masterfrom
haakon-e:he/rft-make-gamma-a-x-gpu

Conversation

@haakon-e
Copy link
Contributor

Purpose

This pull request refactors src/expint.jl, src/gamma.jl to make the upper incomplete gamma function gamma(a, x) GPU-compatible (verified on NVIDIA A100).

Summary of changes

src/expint.jl:

  • Added targeted type constraints in En_expand_origin_general, En_safe_expfact, En_expand_origin to ensure their return types are consistent with the least precise floating point type of either a or x. These functions are conditionally used by gamma(a,x) through the call chain: fn -> En_expand_origin -> _expint -> expint -> _gamma(a,x) -> gamma(a,x)
    • Note: An alternative to this approach, would be to let these inner functions remain unstable, then do type conversion at the top-level.
    • Note 2: I don't personally use gamma(a,x) with complex arguments, so would appreciate an extra pair of eyes to verify that the way I get the floating point type FT from the arguments is reasonable.
  • Added condition that guarantees termination of a while loop in _expint.
    • Note: This is an ad-hoc limit, which to my understanding, should never be reached mathematically.

src/gamma.jl:

test/gamma_inc.jl:

  • Added CI tests that verify that gamma(a, x) is type stable and allocation-free.
    • Note: Additional tests would be needed to verify that all runtime paths gamma(a,x) indeed do not allocate. I haven't done that in this PR

- improve type stability for En_expand_origin_general, En_safe_expfact, En_expand_origin
- this improves type stability for expint(a, x) and thus gamma(a, x)
- make gamma(n::Int) for n>20 call gamma(Float64(n)) for compatibility with CUDA.jl's device override of the gamma function
- manually inline single recursion in _zeta, _trigamma
- modify while loop in _expint to guarantee termination
- add related tests
@haakon-e haakon-e force-pushed the he/rft-make-gamma-a-x-gpu branch from 03fbbfd to 734535b Compare February 28, 2026 00:56
@codecov
Copy link

codecov bot commented Feb 28, 2026

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.19%. Comparing base (d71eddb) to head (734535b).

Files with missing lines Patch % Lines
src/expint.jl 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #520      +/-   ##
==========================================
+ Coverage   94.17%   94.19%   +0.01%     
==========================================
  Files          14       14              
  Lines        2971     2980       +9     
==========================================
+ Hits         2798     2807       +9     
  Misses        173      173              
Flag Coverage Δ
unittests 94.19% <95.45%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant