NVIDIA / NVIDIA/cuvs

[BUG] cuvsDatasetMakePadded rejects an already-aligned device tensor

Open
#2,482 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Cuda
Stars
854
Forks
236
Avg merge
3d 3h
Merged PRs (30d)
62

Description

Describe the bug

cuvsDatasetMakePadded fails when handed a device tensor whose rows already sit at CAGRA's required stride. The refusal makes sense since it avoids a redundant copy. However, it is not documented in the API, and the C API exposes no way to predict it.

Steps/Code to reproduce bug

  1. Allocate a contiguous float32 device matrix whose dimension is a multiple of 4 — e.g. 64 rows × 128 dims. (Contiguous means rowStride == columns, which for 4-byte elements is already the 16-byte-aligned width CAGRA requires.)
  2. Wrap it in a DLManagedTensor with device type kDLCUDA.
  3. Call cuvsDatasetMakePadded(res, tensor, CUVS_DATASET_MEM_TYPE_DEVICE, &out).
  4. Repeat with 127 dims instead of 128 — it succeeds. The boundary is dim % 4 == 0 for float32.

Expected behavior

The dataset contents are copied into newly allocated padded storage, as documented at https://github.com/NVIDIA/cuvs/blob/2140532c5274dfbd9ba1d18c7bbdac15cc7ea93a/c/include/cuvs/core/dataset.h#L62-L63

Actual behavior

CUVS_ERROR, with cuvsGetLastErrorText() returning:

RAFT failure at cpp/include/cuvs/neighbors/common.hpp:1162:
source is device and stride is already correct.
Use make_device_padded_dataset_view() to get a view instead.

Environment details

Not environment specific. Present on main and release/26.08:
https://github.com/NVIDIA/cuvs/blob/2140532c5274dfbd9ba1d18c7bbdac15cc7ea93a/cpp/include/cuvs/neighbors/common.hpp#L1161-L1166

Additional context

The Python workaround is probably the clearest signal that the API is missing something:
https://github.com/NVIDIA/cuvs/blob/2140532c5274dfbd9ba1d18c7bbdac15cc7ea93a/python/cuvs/cuvs/common/dataset.pyx#L73-L89

It matches on the error text, so any rewording of that message turns the workaround into a crash. Rust, Go, and Java have no equivalent workaround and propagate the failure.

Might be related: #2402 (Dataset API C++, C, and language wrapper follow-up), #2394 (Remove dataset views from language wrappers).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cpp/include/cuvs/neighbors/common.hpp:1161-1166 and the C API declaration in c/include/cuvs/core/dataset.h:62-63. Compare the Python handling in python/cuvs/cuvs/common/dataset.pyx:73-89 and review related issues #2402 and #2394. Done should leave the aligned-device-tensor behavior predictable through the API and avoid wrappers depending on matching error text.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, go, java, python, rust
Domain
backend-api-design, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.