Skip to content

[WIP] cuTENSOR blocksparse implementation - #510

Draft
lkdvos wants to merge 4 commits into
mainfrom
cutensor-blocksparse
Draft

[WIP] cuTENSOR blocksparse implementation#510
lkdvos wants to merge 4 commits into
mainfrom
cutensor-blocksparse

Conversation

@lkdvos

@lkdvos lkdvos commented Aug 19, 2026

Copy link
Copy Markdown
Member

This is an initial implementation of calling into cuTENSOR's blocksparse contraction, which should be able to speed up our UniqueFusion code. There is still a bit of annoyance for supporting conjugation flags, and non-trivial F or R symbol coefficients, where this has to be handled in pre/postprocessing, but it seems at least from my initial local benchmarks that this is still competitive and outperforms our naive implementation.

Still requires quite a bit of cleanup, and there is one design question that I am still unsure about, which considers whether or not we should keep the "BlockSparseStructure" as something cuTENSOR specific moved into the extension, or as a generic thing backends can hook into.
On the one hand nothing about that is cuTENSOR specific, and there is a case to be made that we could even on CPU do this strategy which merges permutation and multiplication, (maybe someone has a RUST library somewhere that he is working on 😉) but unfortunately the annoying thing is that cuTENSOR is really particular about what integer types have to be where.

Anyways, I'll keep working on this but already wanted to open this up to let everyone know this is in progress.

lkdvos and others added 4 commits August 18, 2026 10:28
`TensorOperations.tensorcontract!` now delegates to `_tensorcontract!`, the
designated hook for backends implementing a contraction by a route other than
the default fusion-tree/BLAS path. Hooking there rather than at `contract!`
keeps `conjA`/`conjB` as plain `Bool`s, since `_generic_tensorcontract!` folds
them into `AdjointTensorMap`s whose data layout no longer matches the subblock
structure of their own space.

Also normalize the subblock strides in `degeneracystructure`, so that the
don't-care strides of extent-1 axes come out monotone by construction.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Map a symmetric tensor contraction of CUDA-backed `TensorMap`s onto a single
cuTENSOR block-sparse contraction of the underlying storage: the index tuples
only determine mode labels, so there is no fusion tree transformation, no
intermediate permutation and no temporary. Opt-in, since NVIDIA documents the
block-sparse API as a public beta with no guarantee of stability.

`blocksparse_compatible` gates the sector types this applies to. Fermionic
sectors qualify: their raw block contraction differs from the categorical one
by a per-block sign, which `blocksparse_contract_signs` derives in factorized
form and the extension applies by scaling blocks. `plan_contract` hoists the
data-independent part out of a hot loop; plans are also cached automatically.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`test/other/blocksparse.jl` pins down the host-side reasoning the backend
relies on without needing a GPU: the sector ordering, the dual-space
convention, the stride canonicalization, and the per-block sign correction,
including a guard that each of its factors is load-bearing.

`test/cuda/blocksparse.jl` compares the block-sparse path against the default
one on raw flat data, sweeping output partitions, scalars, element types and
conjugations, and checks that unsupported cases fall back silently but throw
under `strict`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Add a manual page covering the contraction backends, block-sparse plan reuse
and the block schedulers, and pull the corresponding docstrings into the
library reference. Also refresh the stale `CuArrays.jl` note in the tensor
manual, since GPU storage is now supported by loading CUDA.jl or AMDGPU.jl.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kshyatt
kshyatt self-requested a review August 19, 2026 13:10
@kshyatt

kshyatt commented Aug 19, 2026

Copy link
Copy Markdown
Member

maybe someone has a RUST library somewhere that he is working on 😉

Crab gang rise up!!

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