Skip to content

Commit d708547

Browse files
mdboomgithub-actions[bot]
authored andcommitted
Fix #1336: Correct CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL type (#1451)
(cherry picked from commit abf7ff8)
1 parent 563cd83 commit d708547

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

cuda_bindings/cuda/bindings/_lib/utils.pxd.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ cdef class _HelperCUpointer_attribute:
5050
# Return values
5151
cdef driver.CUcontext _ctx
5252
cdef unsigned int _uint
53+
cdef int _int
5354
cdef driver.CUdeviceptr _devptr
5455
cdef void** _void
5556
cdef driver.CUDA_POINTER_ATTRIBUTE_P2P_TOKENS _token

cuda_bindings/cuda/bindings/_lib/utils.pxi.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,14 @@ cdef class _HelperCUpointer_attribute:
248248
else:
249249
self._cptr = <void*><void_ptr>init_value.getPtr()
250250
elif self._attr in ({{if 'CU_POINTER_ATTRIBUTE_MEMORY_TYPE'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_MEMORY_TYPE,{{endif}}
251-
{{if 'CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,{{endif}}
252251
{{if 'CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES,{{endif}}
253252
{{if 'CU_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE,{{endif}}
254253
{{if 'CU_POINTER_ATTRIBUTE_ACCESS_FLAGS'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_ACCESS_FLAGS,{{endif}}):
255254
self._uint = init_value
256255
self._cptr = <void*>&self._uint
256+
elif self._attr in ({{if 'CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,{{endif}}):
257+
self._int = init_value
258+
self._cptr = <void*>&self._int
257259
elif self._attr in ({{if 'CU_POINTER_ATTRIBUTE_DEVICE_POINTER'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_DEVICE_POINTER,{{endif}}
258260
{{if 'CU_POINTER_ATTRIBUTE_RANGE_START_ADDR'}}cydriver.CUpointer_attribute_enum.CU_POINTER_ATTRIBUTE_RANGE_START_ADDR,{{endif}}):
259261
if self._is_getter:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.. SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
.. SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
3+
4+
.. module:: cuda.bindings
5+
6+
``cuda-bindings`` 13.1.X Release notes
7+
======================================
8+
9+
Highlights
10+
----------
11+
12+
Experimental
13+
------------
14+
15+
Bugfixes
16+
--------
17+
18+
* Fixed an issue where the ``CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL`` attribute was
19+
retrieved as an unsigned int, rather than a signed int.
20+
(`PR #1336 <https://github.com/NVIDIA/cuda-python/pull/1336>`_)
21+
22+
Known issues
23+
------------
24+
25+
* Updating from older versions (v12.6.2.post1 and below) via ``pip install -U cuda-python`` might not work. Please do a clean re-installation by uninstalling ``pip uninstall -y cuda-python`` followed by installing ``pip install cuda-python``.
26+
* The graphics APIs in ``cuda.bindings.runtime`` are inadvertently disabled in 13.0.2. Users needing these APIs should update to 13.0.3.

cuda_bindings/tests/test_cuda.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,22 @@ def test_cuda_pointer_attr():
450450
assert err == cuda.CUresult.CUDA_SUCCESS
451451

452452

453+
@pytest.mark.skipif(
454+
driverVersionLessThan(11030) or not supportsManagedMemory(), reason="When new attributes were introduced"
455+
)
456+
def test_pointer_get_attributes_device_ordinal():
457+
attributes = [
458+
cuda.CUpointer_attribute.CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
459+
]
460+
461+
attrs = cuda.cuPointerGetAttributes(len(attributes), attributes, 0)
462+
463+
# device ordinals are always small numbers. A large number would indicate
464+
# an overflow error.
465+
466+
assert abs(attrs[1][0]) < 256
467+
468+
453469
@pytest.mark.skipif(not supportsManagedMemory(), reason="When new attributes were introduced")
454470
def test_cuda_mem_range_attr():
455471
(err,) = cuda.cuInit(0)

0 commit comments

Comments
 (0)