Precompilation
TensorOperations.jl has some support for precompiling commonly called functions. The guiding philosophy is that often, tensor contractions are (part of) the bottlenecks of typical workflows, and as such we want to maximize performance. As a result, we are choosing to specialize many functions which may lead to a rather large time-to-first-execution (TTFX). In order to mitigate this, some of that work can be moved to precompile-time, avoiding the need to re-compile these specializations for every fresh Julia session.
Nevertheless, TensorOperations is designed to work with a large variety of input types, and simply enumerating all of these tends to lead to prohibitively large precompilation times, as well as large system images. Therefore, there is some customization possible to tweak the desired level of precompilation, trading in faster precompile times for fast TTFX for a wider range of inputs.
Precompilation support requires at least TensorOperations v5.2.0.
Defaults
By default, precompilation is enabled for "tensors" of type Array{T,N}
, where T
and N
range over the following values:
T
is eitherFloat64
orComplexF64
tensoradd!
is precompiled up toN = 5
tensortrace!
is precompiled up to4
free output indices and2
pairs of traced indicestensorcontract!
is precompiled up to3
free output indices on both inputs, and2
contracted indices
Custom settings
The default precompilation settings can be tweaked to allow for more or less expansive coverage. This is achieved through a combination of PrecompileTools
- and Preferences
-based functionality.
To disable precompilation altogether, for example during development or when you prefer to have small binaries, you can locally change the "precompile_workload"
key in the preferences.
using TensorOperations, Preferences
set_preferences!(TensorOperations, "precompile_workload" => false; force=true)
Alternatively, you can keep precompilation enabled, change the settings above through the same machinery, via:
"precomple_eltypes"
: aVector{String}
that evaluate to the desired values ofT<:Number
"precompile_add_ndims"
: anInt
to specify the maximumN
fortensoradd!
"precompile_trace_ndims"
: aVector{Int}
of length 2 to specify the maximal number of free and traced indices fortensortrace!
."precompile_contract_ndims"
: aVector{Int}
of length 2 to specify the maximal number of free and contracted indices fortensorcontract!
.
Currently, there is no support for precompiling methods that do not use the default backend. If this is a feature you would find useful, feel free to contact us or open an issue.