Add 64-bit indexing fallback for large multi_tensor_l2norm kernels#1989
Open
SongXiaoXi wants to merge 3 commits intoNVIDIA:masterfrom
Open
Add 64-bit indexing fallback for large multi_tensor_l2norm kernels#1989SongXiaoXi wants to merge 3 commits intoNVIDIA:masterfrom
SongXiaoXi wants to merge 3 commits intoNVIDIA:masterfrom
Conversation
Signed-off-by: Xiaoxi Song <song_xiaoxi@126.com>
for more information, see https://pre-commit.ci
crcrpar
reviewed
Mar 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a safe 64-bit indexing fallback for Apex’s multi-tensor L2-norm CUDA kernels when tensor sizes exceed INT_MAX, preventing incorrect results and potential OOB accesses while preserving the existing int32 fast path for typical tensor sizes.
Changes:
- Introduces a shared host-side helper to detect when any tensor list requires 64-bit indexing.
- Templates the L2-norm kernel functors on an
index_tand dispatches toint64_tonly when needed. - Adds large-tensor regression tests covering
multi_tensor_l2norm,multi_tensor_l2norm_mp, andmulti_tensor_l2norm_scale.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/L0/run_optimizers/test_large_tensor_l2norm.py | Adds regression tests for tensors with numel() > INT_MAX across the L2-norm kernel family. |
| csrc/multi_tensor_l2norm_scale_kernel.cu | Adds index_t-templated functor + runtime dispatch to int64 indexing for large tensors. |
| csrc/multi_tensor_l2norm_kernel_mp.cu | Adds index_t-templated functor + runtime dispatch to int64 indexing for large tensors. |
| csrc/multi_tensor_l2norm_kernel.cu | Adds index_t-templated functors + runtime dispatch (including unscale + norm_out paths). |
| csrc/multi_tensor_apply.cuh | Adds tensor_lists_require_64bit_indexing(...) helper used by updated kernels. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Summary
This PR adds a 64-bit indexing fallback for the multi_tensor_l2norm kernel family when any input tensor has numel() above INT_MAX.
The existing int32 fast path is preserved for normal tensor sizes, while large tensors are dispatched to an int64-indexed path.
Problem
Apex's multi-tensor metadata stores tensor sizes in int64, but the l2norm family still narrows sizes and chunk indexing to int32 inside the device functors.
For tensors larger than INT_MAX elements, this can produce incorrect norm results and may also lead to out-of-bounds accesses once chunk offsets overflow 32-bit indexing.
Fix
Affected ops
Testing
Added large-tensor regression tests covering:
The new tests verify correctness for tensors larger than INT_MAX elements while keeping the existing small/normal tensor path unchanged.