Skip to content

Keep normalizations of GPUTensorMaps from synchronizing - #615

Merged
kshyatt merged 2 commits into
mainfrom
ksh/gpu_norm
Nov 20, 2026
Merged

kshyatt merged 2 commits into
mainfrom
ksh/gpu_norm

Conversation

@kshyatt

@kshyatt kshyatt commented Nov 6, 2026

Copy link
Copy Markdown
Member

Right now we're doing a roundtrip when we normalize a tensor backed by a GPU array, because norm returns a host scalar which is then copied back to the GPU for the actual normalization. This is synchronizing also. I added some generic fallbacks as well as a hook for the 2-norm since some benchmarking showed that cuBLAS.nrm2 is ~6x as fast as my fallback and avoids overflows. Once a new AMDGPU is out we can support rocBLAS.nrm2 also.

@kshyatt
kshyatt requested a review from lkdvos November 6, 2026 12:46
@kshyatt
kshyatt marked this pull request as ready for review November 6, 2026 17:27
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ext/TensorKitCUDAExt/TensorKitCUDAExt.jl 100.00% <100.00%> (ø)
ext/TensorKitGPUArraysExt.jl 96.96% <100.00%> (+0.24%) ⬆️
src/tensors/linalg.jl 83.82% <ø> (+0.29%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kshyatt

kshyatt commented Nov 12, 2026 •

Copy link
Copy Markdown
Member Author

GPU fail isn't related and should be fixed by the next Mooncake release

@Jutho Jutho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite like abbreviations that consist of just removing a single letter :-), such as in _nrm2. I am fine keeping it like this for now (even though the argument order is opposite to (cu)BLAS.nrm2 so there is no benefit in giving it the same name), but I think the whole PR is probably a temporary solution that will need to be reconsidered if we have proper device scalar support, right? Maybe at a TODO about that.

@kshyatt

kshyatt commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

I think the normalize stuff will stay since the basic LinearAlgebra.jl one forces the norm scalar to round-trip. But some of the lower level wrappers would change.

Comment thread ext/TensorKitGPUArraysExt.jl Resolved
kshyatt and others added 2 commits November 18, 2026 13:27
Co-authored-by: Lander Burgelman <39218680+leburgel@users.noreply.github.com>
@kshyatt

kshyatt commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

I'm going to merge so this can go out in the next TK release and we can update when the Scalar stuff gets worked out in VectorInterface.jl

@kshyatt
kshyatt merged commit 7f0c873 into main Nov 20, 2026
35 checks passed
@kshyatt
kshyatt deleted the ksh/gpu_norm branch November 20, 2026 09:16
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.

3 participants