Skip to content

Conversation

TwentyPast4
Copy link

@TwentyPast4 TwentyPast4 commented Oct 1, 2025

When using any advanced indexing operations like IndexAdd, IndexSet, IndexGet with a boolean mask, the results are incorrect in the following case:

  • the tensor is on a CUDA device, and
  • the _data_ptr of the tensor is not equal to the start of the Blob data pointer (e.g. as a result of slicing)

The problems seems to be that inside NonZeroCuda.cu, GetBlob()->GetDataPtr() is being used, instead of just GetDataPtr.
There seems to be no other place such usage occurs, and other CUDA functions use Tensor::GetDataPtr(), so it seems to me it's very likely this is a bug.

See issue #7341

Type

Motivation and Context

In my application, I was using something like this (pseudocode):

Tensor a = someDataSet; // let's say this is of shape {N} or {N, 1}
Tensor mask = a.Ge(0);
Tensor subsetA = a.Slice(0, 10, 20);
Tensor maskSubRange = mask.Slice(0, 10, 20);

Tensor maskedSubsetPart = subsetA.IndexGet({maskSubRange}); // here NonZeroNumpy will be called to convert the boolean mask to a list of indices, but it will use the blob's data pointer instead of the tensor's data pointer as the start of the search
Tensor maskedFullSet = a.IndexGet({mask});

// now I would expect this to be equal, but it's not
EXPECT_EQ(maskedFullSet.Slice(0, 10, 20), maskedSubsetPart)

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

Copy link

update-docs bot commented Oct 1, 2025

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

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.

Advanced indexing with boolean masks on CUDA can be incorrect

1 participant