Skip to content

Commit a18dfcd

Browse files
authored
DEFAULT_CHUNK_THRESHOLD is configurable via Preferences.jl (#582)
* DEFAULT_CHUNK_THRESHOLD is configurable via Preferences.jl * Add docs
1 parent 85f439e commit a18dfcd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

docs/src/user/advanced.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ julia> @time ForwardDiff.gradient!(out, rosenbrock, x, cfg);
8484
0.281853 seconds (4 allocations: 160 bytes)
8585
```
8686

87+
The underlying heuristic will compute a suitable chunk size smaller or equal
88+
to the `ForwardDiff.DEFAULT_CHUNK_THRESHOLD` constant. As of ForwardDiff
89+
v0.10.32 and Julia 1.6, this constant can be configured at load time via
90+
[Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl) by setting the
91+
`default_chunk_threshold` value.
92+
8793
If your input dimension is constant across calls, you should explicitly select a chunk size
8894
rather than relying on ForwardDiff's heuristic. There are two reasons for this. The first is
8995
that ForwardDiff's heuristic depends only on the input dimension, whereas in reality the

src/prelude.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@static if VERSION >= v"1.6"
22
const NANSAFE_MODE_ENABLED = @load_preference("nansafe_mode", false)
3+
const DEFAULT_CHUNK_THRESHOLD = @load_preference("default_chunk_threshold", 12)
34
else
45
const NANSAFE_MODE_ENABLED = false
6+
const DEFAULT_CHUNK_THRESHOLD = 12
57
end
68

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

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

13-
const DEFAULT_CHUNK_THRESHOLD = 12
14-
1515
struct Chunk{N} end
1616

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

0 commit comments

Comments
 (0)