Skip to content

Fix CUDA issue with irrational constant #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2023
Merged

Fix CUDA issue with irrational constant #75

merged 1 commit into from
Aug 18, 2023

Conversation

devmotion
Copy link
Member

I think upstream fixes for #73 might take a while. Since we only use a heuristic here, it should be fine to just promote the irrational to the same (floating-point) type of the input x before comparing it with x.

@Red-Portal can you confirm that this PR fixes your issue? Seemed to be the case for me at least.

@Red-Portal
Copy link

Red-Portal commented Aug 17, 2023

Yes, can confirm!

julia> @eval LogExpFunctions begin
           function log1mexp(x::Real)
           # Use explicit `oftype(..)` instead of just `loghalf` to avoid CUDA issues:
           # https://github.com/JuliaStats/LogExpFunctions.jl/issues/73
           if x < oftype(float(x), IrrationalConstants.loghalf)
               return log1p(-exp(x))
           else
               return log(-expm1(x))
           end
       end
       end
log1mexp (generic function with 1 method)

julia> log1mexp.(CUDA.randn(3))
3-element CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}:
  -0.4460078
  -0.6540878
 NaN

@devmotion devmotion merged commit cbd1bbe into master Aug 18, 2023
@devmotion devmotion deleted the dw/cuda branch August 18, 2023 08:30
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.

3 participants