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

Implement pick_batchsize #1545

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions src/Enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ include("gradientutils.jl")
include("utils.jl")
include("compiler.jl")
include("internal_rules.jl")
include("sugar.jl")

import .Compiler: CompilationException

Expand Down
15 changes: 15 additions & 0 deletions src/sugar.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
pick_batchsize(totalsize, mode, ftype, return_activity, argtypes...)
Return a reasonable batch size for batched differentiation.
!!! warning
This function is experimental, and not part of the public API.
"""
function pick_batchsize(totalsize::Integer,
mode::Mode,
ftype::Type,
return_activity, ::Type{<:Annotation},
argtypes::Vararg{Type{<:Annotation},Nargs}) where {Nargs}
return min(totalsize, 16)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ end

include("abi.jl")
include("typetree.jl")
include("sugar.jl")

include("rules.jl")
include("rrules.jl")
Expand Down
10 changes: 10 additions & 0 deletions test/sugar.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Enzyme: Active, Duplicated, Forward, pick_batchsize
using Test

mode = Forward
ftype = typeof(sum)
argtypes = typeof.((Duplicated(ones(1), zeros(1)),))
@test pick_batchsize(1, mode, ftype, Active, argtypes...) == 1

argtypes = typeof.((Duplicated(ones(100), zeros(100)),))
@test pick_batchsize(100, mode, ftype, Active, argtypes...) == 16
Loading