Repository navigation
Avoid boxing the BLAS-contractable inputs in _blas_contract! - #315
Merged
Merged
Conversation
`makeblascontractable` returns either its input or a permuted copy, whose types differ when the copy is allocated by an allocator such as Bumper's. The resulting union is not an `isbits` type and was therefore heap allocated on every contraction, even when no copy was required. `_blas_contract!` now makes the inputs BLAS-contractable one at a time, passing them on to the next step in each branch rather than returning them, such that the union is never materialized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #273, together with QuantumKitHub/Strided.jl#94, without inlining the call chain. Based on #314.
The 112 B per call in the reproducer of #273 (Julia 1.13.1) have two independent sources:
makeblascontractablereturns either its input or a permuted copy. With an allocator such as Bumper's, the copy has a different parent type, so the result is a union of twoStridedViewtypes. That union is notisbitsand was boxed on every contraction, even when no copy was made._blas_contract!now makes the inputs BLAS-contractable one at a time, and passes them on to the next step (_blas_contract_B!, then_blas_contract_C!) within each branch rather than returning them, so the union is never materialized. The copy itself is made by a small@inlinehelper: inlining it lets the compiler elide theArraywrapper of the copy, which otherwise costs an extra allocation per copy.Threads.@spawnclosure in_threaded_blas_mul!were boxed, fixed in Avoid boxing the views captured by the threaded BLAS multiplication Strided.jl#94.makeblascontractableitself is unchanged, since it is tested and possibly used elsewhere.Benchmarks
Allocations in the reproducer of #273 (
StridedBLAS, Bumper allocator), with the latest Strided and StridedViewsmain:mainFloat64ComplexF64ComplexF64,conjRuntime and compile time (minimum times, fresh processes):
mainComplexF32contractionPart of the speedup with the default allocator overlaps with the scalar type specialization of
makeblascontractablein #314, sincewithblascontractablealso specializes on it.🤖 Generated with Claude Code