Skip to content

Commit 57e2f35

Browse files
github-actions[bot]mdboomleofang
authored
[Backport 12.9.x] Fix #1336: Correct CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL type (#1479)
* Fix #1336: Correct CU_POINTER_ATTRIBUTE_DEVICE_ORDINAL type (#1451) (cherry picked from commit abf7ff8) * Delete cuda_bindings/docs/source/release/13.1.X-notes.rst --------- Co-authored-by: Michael Droettboom <mdboom@gmail.com> Co-authored-by: Leo Fang <leof@nvidia.com>
1 parent c41ba99 commit 57e2f35

3 files changed

Lines changed: 20 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:

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)