Skip to content

Commit 84afe18

Browse files
committed
Add documentation
1 parent 6ade3c1 commit 84afe18

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ makedocs(; modules=[TensorOperations],
1111
"man/interface.md",
1212
"man/backends.md",
1313
"man/autodiff.md",
14-
"man/implementation.md"],
14+
"man/implementation.md",
15+
"man/precompilation.md"],
1516
"Index" => "index/index.md"])
1617

1718
# Documenter can also automatically deploy documentation to gh-pages.

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## Table of contents
66

77
```@contents
8-
Pages = ["index.md", "man/indexnotation.md", "man/functions.md", "man/interface.md", "man/backends.md", "man/autodiff.md", "man/implementation.md"]
8+
Pages = ["index.md", "man/indexnotation.md", "man/functions.md", "man/interface.md", "man/backends.md", "man/autodiff.md", "man/implementation.md", "man/precompilation.md"]
99
Depth = 4
1010
```
1111

docs/src/man/precompilation.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.

src/precompile.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ function validate_trace_ndims(trace_ndims)
2929
end
3030

3131
function validate_contract_ndims(contract_ndims)
32-
contract_ndims isa Vector{Int} && length(contract_ndims) == 3 ||
33-
throw(ArgumentError("`precompile_contract_ndims` should be a `Vector{Int}` of length 3, got `$contract_ndims`"))
32+
contract_ndims isa Vector{Int} && length(contract_ndims) == 2 ||
33+
throw(ArgumentError("`precompile_contract_ndims` should be a `Vector{Int}` of length 2, got `$contract_ndims`"))
3434
all((0), contract_ndims) ||
3535
error("Invalid precompile_contract_ndims: `$contract_ndims`")
3636
return contract_ndims
@@ -45,7 +45,7 @@ const PRECOMPILE_ADD_NDIMS = validate_add_ndims(@load_preference("precompile_add
4545
const PRECOMPILE_TRACE_NDIMS = validate_trace_ndims(@load_preference("precompile_trace_ndims",
4646
[4, 2]))
4747
const PRECOMPILE_CONTRACT_NDIMS = validate_contract_ndims(@load_preference("precompile_contract_ndims",
48-
[3, 2, 3]))
48+
[4, 2]))
4949

5050
# Using explicit precompile statements here instead of @compile_workload:
5151
# Actually running the precompilation through PrecompileTools leads to longer compile times
@@ -90,7 +90,7 @@ if PrecompileTools.workload_enabled(@__MODULE__)
9090
# ---------------
9191
for T in PRECOMPILE_ELTYPES
9292
for N1 in 0:PRECOMPILE_CONTRACT_NDIMS[1], N2 in 0:PRECOMPILE_CONTRACT_NDIMS[2],
93-
N3 in 0:PRECOMPILE_CONTRACT_NDIMS[3]
93+
N3 in 0:PRECOMPILE_CONTRACT_NDIMS[1]
9494

9595
NA = N1 + N2
9696
NB = N2 + N3

0 commit comments

Comments
 (0)