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

Safety make_zero! on repeated Enzyme calls with caches #1067

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ DiffEqNoiseProcess = "5.19"
Distributed = "1"
Distributions = "0.25"
EllipsisNotation = "1"
Enzyme = "0.12"
Enzyme = "0.12.22"
FiniteDiff = "2"
ForwardDiff = "0.10"
FunctionProperties = "0.1"
Expand Down
6 changes: 5 additions & 1 deletion src/derivative_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,8 @@ function _vecjacobian!(dλ, y, λ, p, t, S::TS, isautojacvec::EnzymeVJP, dgrad,
ytmp = _tmp5
end

tmp1 .= 0 # should be removed for dλ
tmp1 .= 0
#Enzyme.make_zero!(tmp1) # should be removed for dλ
ytmp .= y

#if dgrad !== nothing
Expand All @@ -699,12 +700,15 @@ function _vecjacobian!(dλ, y, λ, p, t, S::TS, isautojacvec::EnzymeVJP, dgrad,
# tmp3 = dy
#else
tmp3 .= 0
#Enzyme.make_zero!(tmp3)
#end

vec(tmp4) .= vec(λ)

isautojacvec = get_jacvec(sensealg)

Enzyme.make_zero!(_tmp6)
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved

if inplace_sensitivity(S)
if W === nothing
Enzyme.autodiff(Enzyme.Reverse, Enzyme.Duplicated(S.diffcache.pf, _tmp6),
Expand Down
3 changes: 2 additions & 1 deletion src/gauss_adjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ function vec_pjac!(out, λ, y, t, S::GaussIntegrand)
tmp3, tmp4, tmp6 = paramjac_config
vtmp4 = vec(tmp4)
vtmp4 .= λ
out .= 0
Enzyme.make_zero!(out)
Enzyme.make_zero!(tmp6)
ChrisRackauckas marked this conversation as resolved.
Show resolved Hide resolved
Enzyme.autodiff(
Enzyme.Reverse, Enzyme.Duplicated(pf, tmp6), Enzyme.Const,
Enzyme.Duplicated(tmp3, tmp4),
Expand Down
3 changes: 2 additions & 1 deletion src/quadrature_adjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ function vec_pjac!(out, λ, y, t, S::AdjointSensitivityIntegrand)
elseif sensealg.autojacvec isa EnzymeVJP
tmp3, tmp4, tmp6 = paramjac_config
tmp4 .= λ
out .= 0
Enzyme.make_zero!(out)
Enzyme.make_zero!(tmp6)
Enzyme.autodiff(
Enzyme.Reverse, Enzyme.Duplicated(pf, tmp6), Enzyme.Const,
Enzyme.Duplicated(tmp3, tmp4),
Expand Down
Loading