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 7 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 16 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
"""
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

"""
unsafe_to_pointer

Expand Down Expand Up @@ -260,8 +276,3 @@ end
end

export codegen_world_age





2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Aqua.test_all(Enzyme, unbound_args=false, piracies=false, deps_compat=false)

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

@static if Enzyme.EnzymeRules.issupported()
include("rules.jl")
Expand Down Expand Up @@ -3516,4 +3517,3 @@ end


end

10 changes: 10 additions & 0 deletions test/utils.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