Skip to content

Avoid boxing the views captured by the threaded BLAS multiplication - #94

Merged
lkdvos merged 2 commits into
mainfrom
ld-threaded-blas-box
Oct 14, 2026
Merged

lkdvos merged 2 commits into
mainfrom
ld-threaded-blas-box

Conversation

@lkdvos

@lkdvos lkdvos commented Oct 13, 2026

Copy link
Copy Markdown
Member

Chead, Ahead and Bhead are assigned in both branches of _threaded_blas_mul! and captured by the Threads.@spawn closure, so Julia boxes them. The boxes (3 × 16 B) are allocated on every call, including the single-threaded path taken by small multiplications. Interpolating them into Threads.@spawn avoids the capture.

This is one of the two sources of the allocation reported in QuantumKitHub/TensorOperations.jl#273. With this change (and the corresponding TensorOperations fix), the StridedBLAS contraction from that issue no longer allocates.

The blas multiplication tests pass with 4 threads, both single-threaded, multi-threaded, and with enable_threaded_mul().

🤖 Generated with Claude Code

`Chead`, `Ahead` and `Bhead` are assigned in both branches of `_threaded_blas_mul!` and
captured by the closure of `Threads.@spawn`, which makes Julia box them. These boxes are
allocated whenever the function is called, also when it takes the single-threaded path.
Interpolating the variables into `Threads.@spawn` avoids capturing them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lkdvos

lkdvos commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

Test failures are just the inference checks that have now been resolved through StridedViews 0.5.5, I can rerun them but don't want to overburden the queueueueue

@Jutho

Jutho commented Oct 14, 2026

Copy link
Copy Markdown
Member

Is it worth (if feasible) adding an allocation test?

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lkdvos
lkdvos merged commit 6a94ba6 into main Oct 14, 2026
1 of 12 checks passed
@lkdvos
lkdvos deleted the ld-threaded-blas-box branch October 14, 2026 22:03
lkdvos referenced this pull request Oct 15, 2026
* Extend GPUArrays compat to 12 and JLArrays compat to 0.4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Compare device math approximately in single-element GPU tests

`abs` and `abs2` of complex numbers may round differently on the device
(e.g. AMDGPU's `hypot`), so compare those reductions with `≈`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants