Skip to content

Commit

Permalink
DEFAULT_CHUNK_THRESHOLD is configurable via Preferences.jl (#582)
Browse files Browse the repository at this point in the history
* DEFAULT_CHUNK_THRESHOLD is configurable via Preferences.jl

* Add docs
  • Loading branch information
lassepe authored Aug 8, 2022
1 parent 85f439e commit a18dfcd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit a18dfcd

Please sign in to comment.