Skip to content

DEFAULT_CHUNK_THRESHOLD is configurable via Preferences.jl #582

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
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
6 changes: 6 additions & 0 deletions docs/src/user/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ julia> @time ForwardDiff.gradient!(out, rosenbrock, x, cfg);
0.281853 seconds (4 allocations: 160 bytes)
```

The underlying heuristic will compute a suitable chunk size smaller or equal
to the `ForwardDiff.DEFAULT_CHUNK_THRESHOLD` constant. As of ForwardDiff
v0.10.32 and Julia 1.6, this constant can be configured at load time via
[Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl) by setting the
`default_chunk_threshold` value.

If your input dimension is constant across calls, you should explicitly select a chunk size
rather than relying on ForwardDiff's heuristic. There are two reasons for this. The first is
that ForwardDiff's heuristic depends only on the input dimension, whereas in reality the
Expand Down
4 changes: 2 additions & 2 deletions src/prelude.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@static if VERSION >= v"1.6"
const NANSAFE_MODE_ENABLED = @load_preference("nansafe_mode", false)
const DEFAULT_CHUNK_THRESHOLD = @load_preference("default_chunk_threshold", 12)
else
const NANSAFE_MODE_ENABLED = false
const DEFAULT_CHUNK_THRESHOLD = 12
end

const AMBIGUOUS_TYPES = (AbstractFloat, Irrational, Integer, Rational, Real, RoundingMode)
Expand All @@ -10,8 +12,6 @@ const UNARY_PREDICATES = Symbol[:isinf, :isnan, :isfinite, :iseven, :isodd, :isr

const BINARY_PREDICATES = Symbol[:isequal, :isless, :<, :>, :(==), :(!=), :(<=), :(>=)]

const DEFAULT_CHUNK_THRESHOLD = 12

struct Chunk{N} end

const CHUNKS = [Chunk{i}() for i in 1:DEFAULT_CHUNK_THRESHOLD]
Expand Down