|
| 1 | +# Precompilation |
| 2 | + |
| 3 | +Since version `v5.1.5`, TensorOperations.jl has some support for precompiling commonly called functions. |
| 4 | +The guiding philosophy is that often, tensor contractions are (part of) the bottlenecks of typical workflows, |
| 5 | +and as such we want to maximize performance. As a result, we are choosing to specialize many functions which |
| 6 | +may lead to a rather large time-to-first-execution (TTFX). In order to mitigate this, some of that work can |
| 7 | +be moved to precompile-time, avoiding the need to re-compile these specializations for every fresh Julia session. |
| 8 | + |
| 9 | +Nevertheless, TensorOperations is designed to work with a large variety of input types, and simply enumerating |
| 10 | +all of these tends to lead to prohibitively large precompilation times, as well as large system images. |
| 11 | +Therefore, there is some customization possible to tweak the desired level of precompilation, trading in |
| 12 | +faster precompile times for fast TTFX for a wider range of inputs. |
| 13 | + |
| 14 | +## Defaults |
| 15 | + |
| 16 | +By default, precompilation is enabled for "tensors" of type `Array{T,N}`, where `T` and `N` range over the following values: |
| 17 | + |
| 18 | +* `T` is either `Float64` or `ComplexF64` |
| 19 | +* `tensoradd!` is precompiled up to `N = 5` |
| 20 | +* `tensortrace!` is precompiled up to `4` free output indices and `2` pairs of traced indices |
| 21 | +* `tensorcontract!` is precompiled up to `3` free output indices on both inputs, and `2` contracted indices |
| 22 | + |
| 23 | +## Custom settings |
| 24 | + |
| 25 | +The default precompilation settings can be tweaked to allow for more or less expansive coverage. This is achieved |
| 26 | +through a combination of `PrecompileTools`- and `Preferences`-based functionality. |
| 27 | + |
| 28 | +To disable precompilation altogether, for example during development or when you prefer to have small binaries, |
| 29 | +you can *locally* change the `"precompile_workload"` key in the preferences. |
| 30 | + |
| 31 | +```julia |
| 32 | +using TensorOperations, Preferences |
| 33 | +set_preferences!(TensorOperations, "precompile_workload" => false; force=true) |
| 34 | +``` |
| 35 | + |
| 36 | +Alternatively, you can keep precompilation enabled, change the settings above through the same machinery, via: |
| 37 | + |
| 38 | +* `"precomple_eltypes"`: a `Vector{String}` that evaluate to the desired values of `T<:Number` |
| 39 | +* `"precompile_add_ndims"`: an `Int` to specify the maximum `N` for `tensoradd!` |
| 40 | +* `"precompile_trace_ndims"`: a `Vector{Int}` of length 2 to specify the maximal number of free and traced indices for `tensortrace!`. |
| 41 | +* `"precompile_contract_ndims"`: a `Vector{Int}` of length 2 to specify the maximal number of free and contracted indices for `tensorcontract!`. |
| 42 | + |
| 43 | +!!! note "Backends" |
| 44 | + |
| 45 | + Currently, there is no support for precompiling methods that do not use the default backend. If this is a |
| 46 | + feature you would find useful, feel free to contact us or open an issue. |
0 commit comments