Skip to content

Commit

Permalink
batch active ret (#2098)
Browse files Browse the repository at this point in the history
* batch active ret

* Update rrules.jl

* Update rrules.jl
  • Loading branch information
wsmoses authored Nov 16, 2024
1 parent 292f43d commit b63f36f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/rules/customrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,10 @@ end
insert!(args, tape_idx, tape)
end
if RT <: Active
if width != 1
emit_error(B, orig, "Not yet supported: Enzyme custom rule of batch size=$width, and active return $RT")
return tapeV
end

llty = convert(LLVMType, RT)

Expand Down
26 changes: 26 additions & 0 deletions test/rrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ end
@test dx [102.0]
end

function augmented_primal(config::RevConfigWidth{2}, func::Const{typeof(f)}, ::Type{<:Active}, x::Active)
if needs_primal(config)
return AugmentedReturn(func.val(x.val), nothing, nothing)
else
return AugmentedReturn(nothing, nothing, nothing)
end
end

function reverse(config::RevConfigWidth{2}, ::Const{typeof(f)}, dret::Active, tape, x::Active)
return ((10+2*x.val*dret.val,100+2*x.val*dret.val,))
end

function fip_2(out, in)
out[] = f(in[])
nothing
end

@testset "Batch ActiveReverse Rules" begin
out = BatchDuplicated(Ref(0.0), (Ref(1.0), Ref(3.0)))
in = BatchDuplicated(Ref(2.0), (Ref(0.0), Ref(0.0)))
# TODO: Not yet supported: Enzyme custom rule of batch size=2, and active return EnzymeCore.Active{Float64}
@test_throws Enzyme.Compiler.EnzymeRuntimeException Enzyme.autodiff(Enzyme.Reverse, fip_2, out, in)
@test_broken in.dvals[1][] 104.0
@test_broken in.dvals[1][] 42.0
end

function alloc_sq(x)
return Ref(x*x)
end
Expand Down

2 comments on commit b63f36f

@wsmoses
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/119593

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.13.15 -m "<description of version>" b63f36f64f4f4b96e28e2e963817c024cdb22d86
git push origin v0.13.15

Please sign in to comment.