Skip to content

feat: support DuplicatedNoNeed as function annotation for Enzyme #805

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

Merged
merged 1 commit into from
May 26, 2025
Merged
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 DifferentiationInterface/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DifferentiationInterface"
uuid = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
authors = ["Guillaume Dalle", "Adrian Hill"]
version = "0.7.0"
version = "0.7.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
const AnyDuplicated = Union{
Duplicated,
MixedDuplicated,
BatchDuplicated,
BatchMixedDuplicated,
DuplicatedNoNeed,
BatchDuplicatedNoNeed,
}
const AnyDuplicated = Union{Duplicated,MixedDuplicated,BatchDuplicated,BatchMixedDuplicated}

const AnyDuplicatedNoNeed = Union{DuplicatedNoNeed,BatchDuplicatedNoNeed}

# until https://github.com/EnzymeAD/Enzyme.jl/pull/1545 is merged
function DI.pick_batchsize(::AutoEnzyme, N::Integer)
Expand Down Expand Up @@ -40,13 +35,25 @@
end
end

function get_f_and_df_prepared!(

Check warning on line 38 in DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl#L38

Added line #L38 was not covered by tests
df, f::F, ::AutoEnzyme{M,<:AnyDuplicatedNoNeed}, ::Val{B}
) where {F,M,B}
if B == 1
return DuplicatedNoNeed(f, df)

Check warning on line 42 in DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl#L41-L42

Added lines #L41 - L42 were not covered by tests
else
return BatchDuplicatedNoNeed(f, df)

Check warning on line 44 in DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl#L44

Added line #L44 was not covered by tests
end
end

function function_shadow(
::F, ::AutoEnzyme{M,<:Union{Const,Nothing}}, ::Val{B}
) where {M,B,F}
return nothing
end

function function_shadow(f::F, ::AutoEnzyme{M,<:AnyDuplicated}, ::Val{B}) where {F,M,B}
function function_shadow(

Check warning on line 54 in DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl

View check run for this annotation

Codecov / codecov/patch

DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/utils.jl#L54

Added line #L54 was not covered by tests
f::F, ::AutoEnzyme{M,<:Union{AnyDuplicated,AnyDuplicatedNoNeed}}, ::Val{B}
) where {F,M,B}
if B == 1
return make_zero(f)
else
Expand Down
2 changes: 1 addition & 1 deletion DifferentiationInterface/test/Back/Enzyme/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ backends = [

duplicated_backends = [
AutoEnzyme(; mode=Enzyme.Forward, function_annotation=Enzyme.Duplicated),
AutoEnzyme(; mode=Enzyme.Reverse, function_annotation=Enzyme.Duplicated),
AutoEnzyme(; mode=Enzyme.Reverse, function_annotation=Enzyme.DuplicatedNoNeed),
]

@testset "Checks" begin
Expand Down
Loading