Skip to content

Add TimerOutputs-based timers for internal kernels - #525

Open
lkdvos wants to merge 1 commit into
mainfrom
ld-timer
Open

Add TimerOutputs-based timers for internal kernels#525
lkdvos wants to merge 1 commit into
mainfrom
ld-timer

Conversation

@lkdvos

@lkdvos lkdvos commented Sep 2, 2026

Copy link
Copy Markdown
Member

Instruments the index manipulation, contraction and factorization kernels with @timeit_debug sections, compiled away by default and enabled via TensorKit.enable_timers!().

Section labels carry a category prefix (symmetry: / bookkeeping: / alloc: / dense:), and TensorKit.timer_summary() aggregates exclusive times into per-category totals that sum to the total measured time. The @cached macro times lookups separately from miss-path construction. While timing, get_num_*_threads() return 1 so that the (single-task) timer is never touched concurrently; the guard const-folds away when disabled, leaving production paths unchanged (verified via benchmark against main).

Adds TimerOutputs (1.x, for recursive enable_debug_timings) as a dependency, a "Profiling and timers" manual page, and tests.

🤖 Generated with Claude Code

Instrument the index manipulation, tensor contraction and factorization
kernels with `@timeit_debug` sections that are compiled away by default
and can be enabled with `TensorKit.enable_timers!()`. Section labels
carry a category prefix (`symmetry:` / `bookkeeping:` / `alloc:` /
`dense:`), and `TensorKit.timer_summary()` aggregates the exclusive time
of each section into per-category totals, to measure the split between
fusion tree manipulations, block structure bookkeeping, allocations and
the actual dense tensor kernels.

The `@cached` macro additionally times cache lookups separately from
miss-path construction for all memoized functions. While timers are
enabled, `taskforeach` regions run serially since a `TimerOutput` may
only be manipulated from a single task; the guard const-folds away when
timers are disabled, leaving the production paths unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lkdvos lkdvos linked an issue Sep 2, 2026 that may be closed by this pull request
@lkdvos

lkdvos commented Sep 2, 2026

Copy link
Copy Markdown
Member Author

Example output for a single (cold-cache) permute + svd_compact on an SU2Space(0 => 4, 1//2 => 4, 1 => 2) rank-4 tensor:

TensorKit.timer_summary()

    symmetry:  385μs ( 20.6%)   548KiB  39 sections
 bookkeeping:  195μs ( 10.5%)   159KiB  137 sections
       alloc: 25.4μs (  1.4%)   134KiB  3 sections
       dense: 1.19ms ( 63.8%)   228KiB  58 sections
       other: 70.7μs (  3.8%)  25.7KiB  3 sections
TensorKit.print_timers() — full call tree
 Section                                                  ncalls    time    %tot     avg
───────────────────────────────────────────────────────────────────────────────────────────
 svd_compact!                                                  1  1.20ms   64.2%  1.20ms
 ├─ dense: lapack                                              5  1.11ms   59.7%   223μs
 ├─ bookkeeping: cache sectorstructure                        24  19.8μs    1.1%   825ns
 │  └─ bookkeeping: compute sectorstructure                    1  2.15μs    0.1%  2.15μs
 └─ bookkeeping: cache degeneracystructure                    15  7.87μs    0.4%   525ns
 permute!                                                      1   579μs   31.0%   579μs
 └─ braid!                                                     1   579μs   31.0%   579μs
    ├─ bookkeeping: cache treebraider                          1   488μs   26.1%   488μs
    │  └─ symmetry: compute treebraider                        1   481μs   25.8%   481μs
    │     ├─ symmetry: recoupling matrices                     1   420μs   22.5%   420μs
    │     │  ├─ bookkeeping: cache fsbraid                    37   371μs   19.9%  10.0μs
    │     │  │  └─ symmetry: compute fsbraid                  37   347μs   18.6%  9.37μs
    │     │  └─ bookkeeping: repack                           37  16.0μs    0.9%   433ns
    │     ├─ bookkeeping: fusionblocks                         1  37.7μs    2.0%  37.7μs
    │     ├─ bookkeeping: cache sectorstructure                2  7.66μs    0.4%  3.83μs
    │     ├─ bookkeeping: cache degeneracystructure            2  6.41μs    0.3%  3.21μs
    │     └─ bookkeeping: sort                                 1  4.50μs    0.2%  4.50μs
    ├─ dense: tensoradd                                       29  36.9μs    2.0%  1.27μs
    ├─ dense: pack                                             8  21.4μs    1.1%  2.67μs
    ├─ dense: unpack                                           8  12.2μs    0.7%  1.53μs
    ├─ dense: recouple mul!                                    8  6.00μs    0.3%   750ns
    └─ alloc: buffers                                          1   735ns    0.0%   735ns
 alloc: initialize_output                                      1  50.6μs    2.7%  50.6μs
 └─ bookkeeping: cache degeneracystructure                     2  33.6μs    1.8%  16.8μs
 bookkeeping: cache degeneracystructure                        1  29.6μs    1.6%  29.6μs
 alloc: copy_input                                             1  9.30μs    0.5%  9.30μs

(some deeply nested sectorstructure/degeneracystructure sub-branches elided)

@lkdvos
lkdvos requested a review from leburgel September 2, 2026 09:36
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.93617% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/planar/planaroperations.jl 96.29% 1 Missing ⚠️
src/tensors/indexmanipulations.jl 97.50% 1 Missing ⚠️
src/tensors/treetransformers.jl 92.30% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/TensorKit.jl 17.24% <100.00%> (ø)
src/auxiliary/caches.jl 89.88% <100.00%> (+0.35%) ⬆️
src/auxiliary/timers.jl 100.00% <100.00%> (ø)
src/factorizations/factorizations.jl 84.61% <ø> (ø)
src/factorizations/matrixalgebrakit.jl 93.83% <100.00%> (+1.09%) ⬆️
src/tensors/linalg.jl 82.93% <100.00%> (+0.05%) ⬆️
src/tensors/tensoroperations.jl 96.55% <100.00%> (-0.83%) ⬇️
src/planar/planaroperations.jl 72.46% <96.29%> (-0.34%) ⬇️
src/tensors/indexmanipulations.jl 89.14% <97.50%> (-1.30%) ⬇️
src/tensors/treetransformers.jl 94.84% <92.30%> (-0.95%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support TimerOutputs.jl instrumentation

1 participant