Skip to content
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

CUDA.jl kernel errors with Julia 1.9.0-rc3 #746

Closed
jgreener64 opened this issue Apr 20, 2023 · 5 comments
Closed

CUDA.jl kernel errors with Julia 1.9.0-rc3 #746

jgreener64 opened this issue Apr 20, 2023 · 5 comments
Labels

Comments

@jgreener64
Copy link
Contributor

I am on main (4c30ed8) and CUDA 4.1.4. I have a GPU kernel where gradients work on Julia 1.8.5 and error on Julia 1.9.0-rc2.

The error is attached as error.txt due to the size limit. If required I can minimise but it depends on other packages so maybe there is a quicker fix.

@wsmoses
Copy link
Member

wsmoses commented Apr 20, 2023

Yeah I think we need the code that produces this.

@jgreener64
Copy link
Contributor Author

Minimal reproducer below. This is on Julia 1.9.0-rc3, Enzyme main (4a0cb2b), CUDA 4.2.0 and StaticArrays 1.5.24.

It does not error on Julia 1.8.5 and also if you replace T = Float32 with T = Float64, suggesting some issue with Float32 in static arrays.

using Enzyme, CUDA, StaticArrays, LinearAlgebra

function force(coord_i, coord_j)
    ab = coord_j - coord_i
    c = norm(ab) - 1.0
    f = c * normalize(ab)
    return f
end

function kernel!(fs, coords, is, js)
    inter_i = (blockIdx().x - 1) * blockDim().x + threadIdx().x
    @inbounds if inter_i <= length(is)
        i, j = is[inter_i], js[inter_i]
        f = force(coords[i], coords[j])
        fs[1, i] += f[1]
    end
    return nothing
end

function grad_kernel!(fs, d_fs, coords, d_coords, is, js)
    autodiff_deferred(
        Reverse,
        kernel!,
        Const,
        Duplicated(fs, d_fs),
        Duplicated(coords, d_coords),
        Const(is),
        Const(js),
    )
    return nothing
end

T = Float32
coords = CuArray(rand(SVector{3, T}, 10))
fs = CuArray(zeros(3, 10))
is = CuArray([Int32(i) for i in 1:9])
js = CuArray([Int32(i) for i in 2:10])
d_coords = zero(coords)
d_fs = zero(fs)

CUDA.@sync @cuda threads=10 blocks=1 grad_kernel!(fs, d_fs, coords, d_coords, is, js)

Error in error.txt.

@jgreener64 jgreener64 changed the title CUDA.jl kernel errors with Julia 1.9.0-rc2 CUDA.jl kernel errors with Julia 1.9.0-rc3 May 2, 2023
@wsmoses
Copy link
Member

wsmoses commented May 4, 2023

@vchuravy this feels like a version of #683 per the sqrtf. However we should hypothetically have resolved this already in preservenvvm from the llvm level.

@jgreener64
Copy link
Contributor Author

Also an issue with Julia 1.9.0, Enzyme main (96ddde3), CUDA 4.2.0 and StaticArrays 1.5.25. Error in error.txt.

@vchuravy
Copy link
Member

@wsmoses tells me this might be fixed by EnzymeAD/Enzyme#1233

@wsmoses wsmoses closed this as completed May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants