Skip to content

Commit

Permalink
fix missing Const
Browse files Browse the repository at this point in the history
  • Loading branch information
aelligp committed Oct 8, 2024
1 parent aa08f08 commit 408977d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/ParallelKernel/EnzymeExt/autodiff_gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,25 @@ import Enzyme
# end
# end

function promoto_to_const(args...)
ntuple(length(args)) do i
@inbounds
if !(args[i] isa Enzyme.Annotation)
return Enzyme.Const(args[i])
else
return args[i]
end
end
end

function ParallelStencil.ParallelKernel.AD.autodiff_deferred!(arg, args...) # NOTE: minimal specialization is used to avoid overwriting the default method
args = promote_to_const(args...)
Enzyme.autodiff_deferred(arg, args...)
return
end

function ParallelStencil.ParallelKernel.AD.autodiff_deferred_thunk!(arg, args...) # NOTE: minimal specialization is used to avoid overwriting the default method
args = promote_to_const(args...)
Enzyme.autodiff_deferred_thunk(arg, args...)
return
end
Expand Down
6 changes: 3 additions & 3 deletions test/ParallelKernel/test_parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ import Enzyme
return
end
# Enzyme requires explicit argument annotation, PS injects arguments without annotation
# @parallel configcall=f!(A, B, a) AD.autodiff_deferred!(Enzyme.Reverse, Const(f!), DuplicatedNoNeed(A, Ā), DuplicatedNoNeed(B, B̄), Const(a))
@parallel configcall=f!(A, B, a) AD.autodiff_deferred!(Enzyme.Reverse, Const(f!), DuplicatedNoNeed(A, Ā), DuplicatedNoNeed(B, B̄), Const(a))
Enzyme.autodiff_deferred(Enzyme.Reverse, Const(g!), DuplicatedNoNeed(A_ref, Ā_ref), DuplicatedNoNeed(B_ref, B̄_ref), Const(a))
# @test Array(Ā) ≈ Ā_ref
# @test Array(B̄) ≈ B̄_ref
@test Array(Ā) Ā_ref
@test Array(B̄) B̄_ref
end
end
@testset "@parallel_indices" begin
Expand Down

0 comments on commit 408977d

Please sign in to comment.