From 2064215a5eeef43f97470c9cba6eeeb36d7296a8 Mon Sep 17 00:00:00 2001 From: lassepe Date: Sat, 23 Apr 2022 16:38:19 +0200 Subject: [PATCH 1/2] DEFAULT_CHUNK_THRESHOLD is configurable via Preferences.jl --- src/prelude.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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] From e123625b0019e852e146de9e4ddd7a30b3b8172d Mon Sep 17 00:00:00 2001 From: lassepe Date: Sun, 7 Aug 2022 21:20:14 +0200 Subject: [PATCH 2/2] Add docs --- docs/src/user/advanced.md | 6 ++++++ 1 file changed, 6 insertions(+) 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