NanoVDB: handle empty partitions in the distributed merge path search#2248
Open
harrism wants to merge 2 commits into
Open
NanoVDB: handle empty partitions in the distributed merge path search#2248harrism wants to merge 2 commits into
harrism wants to merge 2 commits into
Conversation
mergePath's bounds checks compare against (keys1Count - 1) and (keys2Count - 1) on size_t counts, so a zero count underflows to SIZE_MAX and the guards never fire; the binary search then reads the empty array (and past either array) and produces wrong or garbage intervals. An empty partition is reachable from radixSortAsync's ceil-split whenever a device receives no items, e.g. sorting a single element across two devices. Return the trivial split before the search: with an empty side, every element up to the diagonal comes from the non-empty side. New single-GPU test MergePathEmptyPartition covers the empty-right, empty-left, both-empty, and non-empty control cases; the empty cases fail deterministically without the fix (inverted split / underflow garbage) and run clean under compute-sanitizer with it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Mark Harris <mharris@nvidia.com>
matthewdcong
reviewed
Jul 7, 2026
| using key_type = typename ::cuda::std::iterator_traits<KeyIteratorIn>::value_type; | ||
|
|
||
| const size_t combinedIndex = intervalIndex * (keys1Count + keys2Count) / 2; | ||
|
|
Contributor
There was a problem hiding this comment.
Do we need to launch the kernel if either keys1Count or keys2Count is 0? I think this condition could be moved into the host code prior to kernel launch.
Contributor
Author
There was a problem hiding this comment.
Good call — done in 3a8f760. The launch site now skips the kernel when either count is zero and computes the trivial split on the host (mergePathTrivial, kept as a small named function so the unit test can exercise it directly); mergePath reverts to the unguarded search with the non-empty precondition documented. The test's empty cases are now pure host calls, with the device search kept as the non-empty control. Verified: nanovdb_test_mgpu 8/8 (single GPU), compute-sanitizer clean.
An empty side needs no merge path search, so skip the kernel launch: the trivial split (everything up to the diagonal comes from the non-empty side) is computed on the host by mergePathTrivial at the launch site. mergePath reverts to the unguarded search and documents that both inputs must be non-empty. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Mark Harris <mharris@nvidia.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.
What
tools::cuda::DistributedPointsToGrid's merge path search (mergePath) mishandles an empty partition. Its bounds checks compare againstkeys1Count - 1/keys2Count - 1onsize_tcounts, so a zero count underflows toSIZE_MAXand the guards never fire; the binary search then reads the empty array (and out of bounds past either array) and returns wrong or garbage intervals — an inverted split in one direction, underflow garbage in the other.An empty partition is reachable from
radixSortAsync's ceil-split whenever a device receives no items — e.g. sorting a single element across two devices gives counts[1, 0].The fix returns the trivial split before the search: with an empty side, every element up to the diagonal comes from the non-empty side.
Testing
New test
TestNanoVDBMultiGPU.MergePathEmptyPartition— runs on a single GPU (mergePathKernelis a plain kernel over pointers), covering empty-right, empty-left, both-empty, and a non-empty control at the median diagonal. The adjacent memory is filled with controlled sentinels so the out-of-bounds search fails deterministically rather than by luck:(0, 2)instead of(2, 0); empty-left returns underflow garbage in both intervals.compute-sanitizer --tool memcheckreports 0 errors.nanovdb_test_mgpusuite: 8/8 pass (single GPU; RTX 6000 Ada, CUDA 12.6).Found while investigating the (environmental, since closed) multi-GPU failures in #2245 — this defect is independent of that machine issue and affects any multi-GPU sort with an empty partition.
Non-CUDA builds
No impact on
NANOVDB_USE_CUDA=OFF— the change is confined to a CUDA-only header and the multi-GPU test.🤖 Generated with Claude Code