diff --git a/docs/src/user/advanced.md b/docs/src/user/advanced.md index a304ff9e..aa7a5128 100644 --- a/docs/src/user/advanced.md +++ b/docs/src/user/advanced.md @@ -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 diff --git a/src/prelude.jl b/src/prelude.jl index 2c91fbdd..1a5d0cfa 100644 --- a/src/prelude.jl +++ b/src/prelude.jl @@ -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) @@ -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]