diff --git a/python/cuvs/cuvs/common/mg_resources.pyx b/python/cuvs/cuvs/common/mg_resources.pyx index 4b9e65df61..6aa3b8ab36 100644 --- a/python/cuvs/cuvs/common/mg_resources.pyx +++ b/python/cuvs/cuvs/common/mg_resources.pyx @@ -1,12 +1,13 @@ # -# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION. # SPDX-License-Identifier: Apache-2.0 # # cython: language_level=3 -from cuda.bindings.cyruntime cimport cudaStream_t +from libc.stdint cimport uintptr_t from cuvs.common.c_api cimport ( + cudaStream_t, cuvsMultiGpuResourcesCreate, cuvsMultiGpuResourcesCreateWithDeviceIds, cuvsMultiGpuResourcesDestroy, @@ -84,11 +85,12 @@ cdef class MultiGpuResources: else: check_cuvs(cuvsMultiGpuResourcesCreate(&self.c_obj)) - if stream: - check_cuvs(cuvsStreamSet(self.c_obj, stream)) + if stream is not None: + check_cuvs(cuvsStreamSet( + self.c_obj, stream)) def sync(self): - check_cuvs(cuvsStreamSync(self.c_obj)) + check_cuvs(cuvsStreamSync(self.c_obj)) def set_memory_pool(self, percent_of_free_memory): """ diff --git a/python/cuvs/cuvs/common/resources.pyx b/python/cuvs/cuvs/common/resources.pyx index cf6f3284a6..9b1c129485 100644 --- a/python/cuvs/cuvs/common/resources.pyx +++ b/python/cuvs/cuvs/common/resources.pyx @@ -1,14 +1,15 @@ # -# SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION. # SPDX-License-Identifier: Apache-2.0 # # cython: language_level=3 import functools -from cuda.bindings.cyruntime cimport cudaStream_t +from libc.stdint cimport uintptr_t from cuvs.common.c_api cimport ( + cudaStream_t, cuvsResources_t, cuvsResourcesCreate, cuvsResourcesDestroy, @@ -54,8 +55,8 @@ cdef class Resources: def __cinit__(self, stream=None): check_cuvs(cuvsResourcesCreate(&self.c_obj)) - if stream: - check_cuvs(cuvsStreamSet(self.c_obj, stream)) + if stream is not None: + check_cuvs(cuvsStreamSet(self.c_obj, stream)) def sync(self): check_cuvs(cuvsStreamSync(self.c_obj)) diff --git a/python/cuvs/cuvs/tests/test_resources.py b/python/cuvs/cuvs/tests/test_resources.py new file mode 100644 index 0000000000..1dc5d8547c --- /dev/null +++ b/python/cuvs/cuvs/tests/test_resources.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION. +# SPDX-License-Identifier: Apache-2.0 + + +import cupy as cp + +from cuvs.common import Resources + + +def test_resources_syncs_cupy_stream_pointer(): + # gh-issue: 1836 should not segfault when syncing a stream pointer from cupy + stream = cp.cuda.Stream() + resources = Resources(stream=stream.ptr) + + resources.sync()