|
3 | 3 | ## `tblis_backend.jl` |
4 | 4 |
|
5 | 5 | Compares `TensorOperations.TBLISBackend()` against the built-in `StridedBLAS()` and |
6 | | -`StridedNative()` backends. BLAS and TBLIS are handed the same number of threads. |
| 6 | +`StridedNative()` backends. |
7 | 7 |
|
8 | 8 | ```console |
9 | 9 | $ julia --project=benchmarks -e 'using Pkg; Pkg.develop(path="."); Pkg.instantiate()' |
10 | | -$ julia --project=benchmarks benchmarks/tblis_backend.jl 16 |
| 10 | +$ julia --project=benchmarks --threads=16 benchmarks/tblis_backend.jl 16 |
11 | 11 | ``` |
12 | 12 |
|
13 | | -The optional argument is the thread count, defaulting to half of `Sys.CPU_THREADS`. |
| 13 | +The argument is the thread count handed to BLAS, TBLIS and Strided alike. `Strided.jl` |
| 14 | +parallelizes over Julia's own threads, so the process has to be *started* with `--threads`; |
| 15 | +the script refuses to run if `Threads.nthreads()` is below the requested count, because |
| 16 | +otherwise a threaded TBLIS is timed against a serial Strided and wins by several-fold for |
| 17 | +reasons that have nothing to do with the backends. |
14 | 18 |
|
15 | 19 | ### Reference numbers |
16 | 20 |
|
17 | | -2× Intel Xeon Gold 6244 (16 physical cores total), 16 threads for both OpenBLAS and TBLIS, |
18 | | -Julia 1.12.6, TensorOperations v5.7.0, TBLIS.jl v0.3.0, `tblis_jll` v1.3.0. Best of two runs |
19 | | -on a shared node; the TBLIS timings were stable to a few percent, the BLAS baselines drift by |
20 | | -up to ~20%. |
| 21 | +2× Intel Xeon Gold 6244 (16 physical cores total), 16 threads for OpenBLAS, TBLIS and |
| 22 | +Strided, Julia 1.12.6, TensorOperations v5.7.0, TBLIS.jl v0.3.0, `tblis_jll` v1.3.0. Best of |
| 23 | +three runs per cell on a shared node. |
21 | 24 |
|
22 | 25 | `eltype = Float64` |
23 | 26 |
|
24 | 27 | | case | StridedBLAS | StridedNative | TBLIS | speedup | |
25 | 28 | | :------------------------------------------ | ----------: | ------------: | -------: | ------: | |
26 | | -| matmul 2000³ | 25.41 ms | 5.52 s | 46.47 ms | 0.55× | |
27 | | -| contract aligned (48,48,1024)×(1024,48,48) | 20.19 ms | 4.25 s | 30.04 ms | 0.67× | |
28 | | -| contract permuted (48,1024,48)×(48,1024,48) | 58.51 ms | 4.13 s | 29.28 ms | 2.00× | |
29 | | -| MPS·MPO·env (χ=256, d=4, D=8) | 22.87 ms | 836.49 ms | 12.38 ms | 1.85× | |
30 | | -| permuted add 200³ | 41.05 ms | 41.30 ms | 4.81 ms | 8.53× | |
31 | | -| partial trace (128,32,128,32) | 288.0 μs | 287.7 μs | 87.0 μs | 3.31× | |
32 | | -| contract small 8³×8³ | 12.6 μs | 38.3 μs | 56.6 μs | 0.22× | |
| 29 | +| matmul 2000³ | 29.22 ms | 759.64 ms | 45.85 ms | 0.64× | |
| 30 | +| contract aligned (48,48,1024)×(1024,48,48) | 21.90 ms | 373.54 ms | 29.80 ms | 0.73× | |
| 31 | +| contract permuted (48,1024,48)×(48,1024,48) | 34.33 ms | 583.81 ms | 28.84 ms | 1.19× | |
| 32 | +| MPS·MPO·env (χ=256, d=4, D=8) | 11.95 ms | 419.41 ms | 12.71 ms | 0.94× | |
| 33 | +| permuted add 200³ | 5.68 ms | 5.75 ms | 4.22 ms | 1.35× | |
| 34 | +| partial trace (128,32,128,32) | 51.1 μs | 49.4 μs | 88.5 μs | 0.56× | |
| 35 | +| contract small 8³×8³ | 13.6 μs | 38.3 μs | 57.3 μs | 0.24× | |
33 | 36 |
|
34 | 37 | `eltype = ComplexF64` |
35 | 38 |
|
36 | 39 | | case | StridedBLAS | StridedNative | TBLIS | speedup | |
37 | 40 | | :-------------------------------------------- | ----------: | ------------: | --------: | ------: | |
38 | | -| matmul 2000³ | 116.22 ms | 16.49 s | 2.39 s | 0.05× | |
39 | | -| contract aligned (48,48,1024)×(1024,48,48) | 80.87 ms | 12.38 s | 1.75 s | 0.05× | |
40 | | -| contract permuted (48,1024,48)×(48,1024,48) | 187.10 ms | 11.73 s | 1.58 s | 0.12× | |
41 | | -| MPS·MPO·env (χ=256, d=4, D=8) | 48.23 ms | 2.43 s | 374.83 ms | 0.13× | |
42 | | -| permuted add 200³ | 53.49 ms | 54.06 ms | 10.25 ms | 5.22× | |
43 | | -| partial trace (128,32,128,32) | 2.46 ms | 2.47 ms | 107.0 μs | 23.0× | |
44 | | -| contract small 8³×8³ | 24.6 μs | 87.0 μs | 65.1 μs | 0.38× | |
45 | | -| contract conj(A) (48,1024,48)×(48,1024,48) | 186.47 ms | 11.75 s | 1.68 s | 0.11× | |
46 | | -| contract conj(A)conj(B) (48,1024,48)×(48,1024,48) | 207.53 ms | 12.39 s | 1.16 s | 0.18× | |
| 41 | +| matmul 2000³ | 117.87 ms | 2.23 s | 2.59 s | 0.05× | |
| 42 | +| contract aligned (48,48,1024)×(1024,48,48) | 77.46 ms | 1.19 s | 1.81 s | 0.04× | |
| 43 | +| contract permuted (48,1024,48)×(48,1024,48) | 114.58 ms | 1.59 s | 1.77 s | 0.06× | |
| 44 | +| MPS·MPO·env (χ=256, d=4, D=8) | 40.40 ms | 1.22 s | 379.67 ms | 0.11× | |
| 45 | +| permuted add 200³ | 10.48 ms | 10.84 ms | 12.75 ms | 0.82× | |
| 46 | +| partial trace (128,32,128,32) | 237.3 μs | 232.1 μs | 112.4 μs | 2.06× | |
| 47 | +| contract small 8³×8³ | 25.2 μs | 87.0 μs | 68.0 μs | 0.37× | |
| 48 | +| contract conj(A) (48,1024,48)×(48,1024,48) | 110.37 ms | 1.54 s | 1.77 s | 0.06× | |
| 49 | +| contract conj(A)conj(B) (48,1024,48)×(48,1024,48) | 124.44 ms | 1.63 s | 1.76 s | 0.07× | |
47 | 50 |
|
48 | 51 | `speedup` is the fastest built-in backend divided by TBLIS, so values above 1 mean TBLIS wins. |
49 | 52 |
|
50 | 53 | ### Reading the numbers |
51 | 54 |
|
52 | | -* Contractions that need a **permutation** before they can be handed to GEMM — the common |
53 | | - case in tensor-network codes — are about **2× faster** with TBLIS, which contracts the |
54 | | - strided memory directly instead of materializing permuted copies. |
55 | | -* **Additions and traces** are where TBLIS is furthest ahead (3–23×), since `Strided.jl` |
56 | | - loses to a blocked, threaded copy for these memory-bound shapes. |
57 | | -* Plain **GEMM-shaped** contractions stay OpenBLAS territory (TBLIS at 0.5–0.7×), and **small |
58 | | - tensors** are dominated by the per-call overhead of building the TBLIS descriptors. |
| 55 | +**On this machine TBLIS is not a throughput win.** Once all three thread pools are matched, |
| 56 | +the built-in backends are at least as fast almost everywhere: 0.64× on GEMM, 1.19× on a |
| 57 | +permutation-heavy real contraction, 0.94× on a DMRG-style network, 0.56× on a partial trace. |
| 58 | +The only clear wins are the real permuted add (1.35×) and the complex partial trace (2.06×). |
| 59 | + |
| 60 | +What TBLIS does buy is **memory**. For the permuted contraction above, `StridedBLAS` allocates |
| 61 | +76.6 MiB of permuted temporaries per call (against 18 MiB inputs and a 40.5 MiB output) while |
| 62 | +TBLIS allocates nothing at all, because it contracts the strided memory in place. For |
| 63 | +workloads that are allocation- or footprint-bound rather than FLOP-bound, that can matter more |
| 64 | +than the wall-clock column. |
| 65 | + |
| 66 | +Two further caveats: |
| 67 | + |
59 | 68 | * **Complex contractions are 8–20× slower than BLAS.** This is a property of the `tblis` |
60 | 69 | binaries, not of this extension: a bare `tblis_tensor_mult` on a 1000³ complex matrix |
61 | 70 | product reaches ~25 GFLOP/s against ~500 GFLOP/s for `mul!`, and `tblis_jll` v1.2.0 behaves |
62 | | - identically, so it is not a regression from the v1.3 bump. Complex `add`/`trace` are |
63 | | - unaffected. Prefer `StridedBLAS` for complex-valued contractions. |
| 71 | + identically, so it is not a regression from the v1.3 bump. |
| 72 | +* **Small tensors** are dominated by the per-call cost of building the TBLIS descriptors. |
| 73 | + |
| 74 | +Earlier revisions of this file reported speedups of up to 9× for the add and trace cases. |
| 75 | +Those were an artifact of running the harness with a single Julia thread, which left |
| 76 | +`Strided.jl` serial while TBLIS used all 16 cores; single-threaded, the permuted add takes |
| 77 | +46.80 ms with TBLIS against 45.79 ms with Strided. |
0 commit comments