I am on Julia 1.9.0, Enzyme 9487eb8349fd7d907403533b53c23822313897bb and StaticArrays v1.5.25. Apologies for the slightly strange example. This errors:
using Enzyme, StaticArrays
vector_1D(c1, c2, side_length) = c2 - c1
function f!(pe_vec, coords, boundary, n_threads, ::Val{T}) where T
pe_sum = zero(T)
if n_threads > 1 # This branch is not taken but the code in it still causes problems
pe_sum_chunks = [zero(T) for _ in 1:n_threads]
Threads.@threads for thread_id in 1:n_threads
dr = vector_1D.(c1, c2, boundary)
pe_sum_chunks[thread_id] += sum(dr)
end
pe_sum += sum(pe_sum_chunks)
end
pe_vec[1] = pe_sum
return nothing
end
T = Float32
pe_vec = [zero(T)]
coords = [SVector(T(1.0), T(1.0), T(1.0)), SVector(T(2.0), T(2.0), T(2.0))]
boundary = SVector(T(4.0), T(4.0), T(4.0))
n_threads = 1
autodiff(
Enzyme.Reverse,
f!,
Const,
Duplicated(pe_vec, [one(T)]),
Duplicated(coords, zero(coords)),
Const(boundary),
Const(n_threads),
Const(Val(T)),
)
I am on Julia 1.9.0, Enzyme 9487eb8349fd7d907403533b53c23822313897bb and StaticArrays v1.5.25. Apologies for the slightly strange example. This errors:
Any of the following removes the error:
T = Float64
instead.Threads.@threads
in the loop.boundary
in thevector_1D
function.c1 - c2
instead ofvector_1D.(c1, c2, boundary)
.