When I run the following I get an error. I am on Julia 1.8.0, Enzyme 0.10.4 and CUDA 3.12.0.
using Enzyme, CUDA, StaticArrays
struct Atom{T}
σ::T
ϵ::T
end
function force(c1, c2, a1, a2)
dr = c2 - c1
invr2 = inv(sum(abs2, dr))
σ = (a1.σ + a2.σ) / 2
ϵ = sqrt(a1.ϵ * a2.ϵ)
six_term = (σ^2 * invr2) ^ 3
f = (24 * ϵ * invr2) * (2 * six_term ^ 2 - six_term)
return f * dr
end
function kernel(C, A)
i = threadIdx().x
if i <= (length(C) - 1)
f = force(C[i], C[i+1], A[i], A[i+1])
end
return nothing
end
function grad_kernel(C, dC, A, dA)
Enzyme.autodiff_deferred(kernel, Const, Duplicated(C, dC), Duplicated(A, dA))
return nothing
end
C = cu(rand(SVector{3, Float32}, 10))
dC = cu(zero(C))
A = cu([Atom(1.0f0, 1.0f0) for _ in 1:10])
dA = cu([Atom(0.0f0, 0.0f0) for _ in 1:10])
@cuda threads=length(C) grad_kernel(C, dC, A, dA)
Interestingly if I replace the ϵ = sqrt(a1.ϵ * a2.ϵ) line with ϵ = sqrt(a1.ϵ) or ϵ = sqrt(a2.ϵ) then it works.
When I run the following I get an error. I am on Julia 1.8.0, Enzyme 0.10.4 and CUDA 3.12.0.
Interestingly if I replace the
ϵ = sqrt(a1.ϵ * a2.ϵ)
line withϵ = sqrt(a1.ϵ)
orϵ = sqrt(a2.ϵ)
then it works.The error is: