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

use Enzyme make_zero #1054

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
9 changes: 2 additions & 7 deletions ext/DiffEqBaseEnzymeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
SciMLBase.EnzymeOriginator(), ntuple(arg_copy, Val(length(args)))...;
kwargs...)

dres = deepcopy(res[1])::RT
for v in dres.u
v .= 0
end
dres = Enzyme.make_zero(res[1])::RT

Check warning on line 31 in ext/DiffEqBaseEnzymeExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/DiffEqBaseEnzymeExt.jl#L31

Added line #L31 was not covered by tests
tup = (dres, res[2])
return Enzyme.EnzymeRules.AugmentedReturn{RT, RT, Any}(res[1], dres, tup::Any)
end
Expand All @@ -52,9 +49,7 @@
end
ptr.dval .+= darg
end
for v in dres.u
v .= 0
end
dres = Enzyme.make_zero(dres)

Check warning on line 52 in ext/DiffEqBaseEnzymeExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/DiffEqBaseEnzymeExt.jl#L52

Added line #L52 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisRackauckas this is incorrect.

It will not update the values of dres in place, instead allocating a new variable.

This will lead to correctness issues if the rule is called within a loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a make_zero!(v) we can use?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not yet, but I'll start making one. We haven't historically seen too much of a need for and always gottena way with the broadcast to zero (like here). But obviously generic structs need generic zeros

return ntuple(_ -> nothing, Val(length(args) + 4))
end

Expand Down
Loading