Skip to content

Commit

Permalink
More info for dupnoneed
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Sep 27, 2024
1 parent bbafecf commit 99bf3b3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/EnzymeCore/src/EnzymeCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,27 @@ end
DuplicatedNoNeed(x, ∂f_∂x)
Like [`Duplicated`](@ref), except also specifies that Enzyme may avoid computing
the original result and only compute the derivative values.
the original result and only compute the derivative values. This creates opportunities
for improved performance.
```jldoctest dupnoneed
function square_byref(out, v)
out[] = v * v
nothing
end
out = Ref(0.0)
dout = Ref(1.0)
Enzyme.autodiff(Reverse, square_byref, DuplicatedNoNeed(out, dout), Active(1.0))
dout[]
# output
0.0
```
For example, marking the out variable as `DuplicatedNoNeed` instead of `Duplicated` allows
Enzyme to avoid computing `v * v`.
This should only be used if `x` is a write-only variable. Otherwise, if the differentiated
function stores values in `x` and reads them back in subsequent computations, using
Expand Down

0 comments on commit 99bf3b3

Please sign in to comment.