Skip to content

Commit 00e3dd4

Browse files
committed
cuda.core: replace the unsqueeze_extents assert, add release note
unsqueeze_extents in _layout.pyx still checked an internal invariant with assert, which python -O strips. It now raises the "internal cuda.core error, please report" RuntimeError. Add a 1.3.0 release note that lists the entry points whose failed checks now raise ValueError or TypeError instead of AssertionError. The managed memory allocate test now closes the resource as well as the graph builder.
1 parent 35983fa commit 00e3dd4

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

‎cuda_core/cuda/core/_layout.pyx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,10 @@ cdef inline int unsqueeze_extents(BaseLayout& out_layout, BaseLayout& in_layout,
11821182
out_layout.shape[i] = in_shape[in_i]
11831183
out_layout.strides[i] = in_strides[in_i]
11841184
in_i += 1
1185-
assert in_i == ndim
1185+
if in_i != ndim:
1186+
raise RuntimeError(
1187+
f"internal cuda.core error, please report: unsqueeze_extents consumed {in_i} of {ndim} input axes"
1188+
)
11861189
return 0
11871190

11881191

‎cuda_core/docs/source/release/1.3.0-notes.rst‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ Fixes and enhancements
321321
``repr`` now shows ``U`` for unified operands.
322322
(`#2649 <https://github.com/NVIDIA/cuda-python/issues/2649>`__)
323323

324+
- Checks that were ``assert`` statements now raise exceptions, so they also
325+
run under ``python -O``, which strips asserts from Python and Cython code.
326+
:meth:`~utils.StridedMemoryView.from_dlpack` raises ``ValueError`` when
327+
``__dlpack_device__()`` reports a negative device ID for a CUDA tensor or a
328+
nonzero one for a CPU tensor, or when ``__dlpack__()`` returns anything
329+
other than an unconsumed DLPack capsule.
330+
:meth:`~utils.StridedMemoryView.from_cuda_array_interface` raises
331+
``ValueError`` when the producer's ``stream`` is 0 or negative.
332+
:meth:`ManagedMemoryResource.allocate` raises ``TypeError`` when ``stream``
333+
is not a :class:`Stream`. Unpickling an :class:`ObjectCode` with an unknown
334+
code type raises ``ValueError``, as do :class:`~system._device.FieldValue`
335+
and :class:`~system._system_events.SystemEvent` when the NVML data does not
336+
hold exactly one entry, and :attr:`system.Device.performance_state` when
337+
NVML reports a P-state outside 0 to 15. Before, these raised
338+
``AssertionError``, or nothing under ``python -O``. A failed internal check
339+
now raises ``RuntimeError`` with a message that starts with "internal
340+
cuda.core error, please report".
341+
(`#3202 <https://github.com/NVIDIA/cuda-python/issues/3202>`__)
342+
324343
Deprecations
325344
------------
326345

‎cuda_core/tests/test_memory.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,13 +1155,18 @@ def test_managed_memory_resource_buffer_dlpack_device_type(init_cuda):
11551155
def test_managed_memory_resource_allocate_rejects_graph_builder(init_cuda):
11561156
device = init_cuda
11571157
skip_if_managed_memory_unsupported(device)
1158-
mr = create_managed_memory_resource_or_skip(ManagedMemoryResourceOptions(preferred_location=device.device_id))
1159-
gb = device.create_graph_builder()
1158+
mr = None
1159+
gb = None
11601160
try:
1161+
mr = create_managed_memory_resource_or_skip(ManagedMemoryResourceOptions(preferred_location=device.device_id))
1162+
gb = device.create_graph_builder()
11611163
with pytest.raises(TypeError, match="Only Stream is supported .*got GraphBuilder"):
11621164
mr.allocate(64, stream=gb)
11631165
finally:
1164-
gb.close()
1166+
if gb is not None:
1167+
gb.close()
1168+
if mr is not None:
1169+
mr.close()
11651170

11661171

11671172
@pytest.mark.parametrize("mr_kind", ["device", "pinned"])

0 commit comments

Comments
 (0)