Repository navigation
Conversation
Fixes #5660 `y`, `l`, `k` and `l_size` in cdist_backward_kernel_impl_func were `int`. For (b=2, r=1024, m=2048), r_size * m = 2^31 overflows, so `l * l_size` wraps and the buffer write lands out of bounds (GPU page fault, process abort). For (b=32, r=8192, m=1), count = dist.numel() = 2^31 and `y` itself truncates. Widening these to int64_t mirrors the CUDA fix in pytorch/pytorch#128791. `init`/`stride` stay `int`; they are bounded by the dim-0 global range, matching upstream. Test Plan: With @skipIfXpu removed locally from test_cdist_backward_large_index: cd pytorch/test pytest -q test_torch.py -k "test_cdist_backward_large_index and xpu" # 2 passed
DamJanusz
force-pushed
the
djanuszx/cdist_64bit_ind
branch
from
November 12, 2026 13:01
dfb6a9b to
159155f
Compare
dvrogozh
approved these changes
Nov 12, 2026
dvrogozh
left a comment
Contributor
There was a problem hiding this comment.
LGTM, @DamJanusz I've slightly modified PR description for the clarity.
Contributor
@DamJanusz , this comment does not belong to PR description as it will be used as a commit message (consider: what use will reader have from this message reading git log?). Leave a comment in #5660 or whatever issue you've meant as the one not to be closed. |
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 #5660
Root cause
cdist_backward_kernel_impl_funcheld its per-row indexy, batch indexl, in-batch indexkand per-batch buffer stridel_sizein 32-bitint. Two shapes overflow:(b=2, r=1024, m=2048):l_size = r1 * r2 * m = 2^31overflows, sol * l_sizewraps andbuff_ipoints outside the buffer.(b=32, r=8192, m=1):count = dist.numel() = 2^31, soyitself truncates.CUDA had the same bug pytorch/pytorch#128791 and fixed it in pytorch/pytorch#198452.
Changes
After this change the XPU index math matches
aten/src/ATen/native/cuda/DistanceKernel.cu(cdist_backward_kernel_cuda_impl)PR to remove
@skipIfXpuon upstream pytorch/pytorch#204593 needs to land after this change propagates to commit pin.Testing
The regression test lives in PyTorch, not torch-xpu-ops:
test/test_torch.py::TestTorchDeviceTypeXPU::test_cdist_backward_large_index_*is currently disabled on XPU with@skipIfXpu(msg=".../issues/5660"). Removing the skip before the pin bump would crash XPU CI with a GPU segfault.