Repository navigation
Fix stream handle cast in Resources and MultiGpuResources - #2946
Conversation
Resources(stream=...) takes the stream as an integer handle, for example cupy.cuda.Stream().ptr, but cast the Python object directly to cudaStream_t. Cython then passes the address of the Python int object instead of its value, so the handle got an invalid stream and sync() segfaulted. Convert through uintptr_t first. Signed-off-by: Artsem Lebiadzevich <artyomlebedevich@gmail.com>
|
Could a maintainer add the |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Stream conversion and external-stream test python/cuvs/cuvs/common/mg_resources.pyx, python/cuvs/cuvs/common/resources.pyx, python/cuvs/cuvs/tests/test_resources.py |
Both constructors convert truthy stream handles through uintptr_t before casting them to cudaStream_t. The test synchronizes a Resources instance created with a CuPy stream, builds and searches a brute-force index, and checks the returned neighbors. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested labels: bug, non-breaking
Suggested reviewers: viclafargue, benfred, achirkin
Merge Risk: 
Minimal · previous review d4f2d
-
The reported stream-handle crash is addressed in both resource classes, with targeted external-stream coverage added.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the main change: fixing the stream handle cast in the Resources and MultiGpuResources classes. The raw summary and objectives both describe this cast fix as the primary change, so the title is specific and on-topic.
Full details: Description check
-
Explanation
The description states the bug (the Python object address was passed instead of the integer handle value), the fix (converting through uintptr_t in both classes), the added test, and the testing performed. It directly matches the changeset and linked issue
#1863.
Full details: Linked Issues check
-
Explanation
Issue
#1863requiresResources(stream=stream.ptr)to synchronize without a segmentation fault.resources.pyxnow converts the Python handle throughuintptr_tbefore casting it tocudaStream_t. The newtest_resources_with_external_streamcreates a CuPy stream, constructsResourceswithstream.ptr, callsres.sync(), and uses the resource for brute-force operations before synchronizing again.
Full details: Out of Scope Changes check
-
Explanation
The changes are limited to the related stream-handle conversion in
ResourcesandMultiGpuResources, plus an automated regression test. TheMultiGpuResourcesfix applies the same defect correction to the related class named in the PR intent. The test directly exercises the linked issue behavior and stream use.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (2 skipped: 2 unsupported.)
-
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
…m-cast Signed-off-by: Artsem Lebiadzevich <artyomlebedevich@gmail.com>
|
@viclafargue @cjnolet gentle ping: could one of you review this when you have time? Passing a CUDA stream to the resources wrapper can segfault. I've merged the latest |
|
/ok to test 04e1b6e |
viclafargue
left a comment
There was a problem hiding this comment.
LGTM! Thanks for fixing the stream handle cast in both resource classes and adding a regression test.
|
/merge |
|
/ok to test aa394dd |
aamijar
left a comment
There was a problem hiding this comment.
Nice! I remember opening that issue a while back
Closes #1863
Resources(stream=...)andMultiGpuResources(stream=...)take the stream as an integer handle (theResourcesdocstring passescupy.cuda.Stream().ptr). Both calledwhere
streamis a Python object. Cython casts a Python object to a pointer type by taking the object's own address, so cuVS got the address of the Pythonintas the stream. The first call that used the stream then crashed. In the issue that call isres.sync().The fix converts the value through
uintptr_tfirst (<cudaStream_t><uintptr_t>stream) in both classes.Tests: added
python/cuvs/cuvs/tests/test_resources.py. It createsResourcesfrom a CuPy stream handle, syncs it, and runs a small brute-force build and search on that handle.How I tested (RTX 5070 Ti, CUDA 13 driver): I installed the
cuvs-cu1326.10 wheels, applied this change to theirresources.pyxandmg_resources.pyx, and rebuilt the two modules with Cython againstlibcuvs_c. Thepyxchange is the same as onmain. I could not buildmain's Python package against the 26.10 C library, becausemainuses newer C API functions.ResourcesandMultiGpuResources(single GPU), andtest_resources.py,test_memory_tracking.pyandtest_brute_force.pyall pass.