Skip to content

Commit 98487f2

Browse files
Only duplicate and make_zero! if enzyme func is non-constant
1 parent b0b9421 commit 98487f2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: src/derivative_wrappers.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,16 @@ function _vecjacobian!(dλ, y, λ, p, t, S::TS, isautojacvec::EnzymeVJP, dgrad,
707707

708708
isautojacvec = get_jacvec(sensealg)
709709

710-
Enzyme.make_zero!(_tmp6)
710+
if Core.Compiler.isconstType(_tmp6)
711+
Enzyme.make_zero!(_tmp6)
712+
_f = Enzyme.Duplicated(S.diffcache.pf, _tmp6)
713+
else
714+
_f = S.diffcache.pf
715+
end
711716

712717
if inplace_sensitivity(S)
713718
if W === nothing
714-
Enzyme.autodiff(Enzyme.Reverse, Enzyme.Duplicated(S.diffcache.pf, _tmp6),
719+
Enzyme.autodiff(Enzyme.Reverse, _f,
715720
Enzyme.Const, Enzyme.Duplicated(tmp3, tmp4),
716721
Enzyme.Duplicated(ytmp, tmp1),
717722
dup,

0 commit comments

Comments
 (0)