Repository navigation
Conversation
python -O strips assert statements, and Cython drops them too, so the
checks they carried vanished in optimized runs. Values that come from a
caller, a DLPack or CUDA Array Interface producer, or an NVML payload
now raise ValueError or TypeError naming the value. Internal invariants
raise RuntimeError("internal cuda.core error, please report: ...").
The unmatched-capsule branch in view_as_dlpack was an assert False, but
a producer reaches it by returning anything other than an unconsumed
DLPack capsule, so it raises ValueError rather than the internal error.
Enforce ruff S101 for cuda_core/cuda/core only. Enabling it for
everything outside tests would flag about 180 asserts in pathfinder,
the samples and the shared test helpers.
The two asserts in _memory/_ipc.pyx are handled by NVIDIA#2704.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
CUDA and interop validation cuda_core/cuda/core/_device.pyx, cuda_core/cuda/core/_memory/*, cuda_core/cuda/core/_memoryview.pyx, cuda_core/tests/test_memory.py, cuda_core/tests/test_utils.py, cuda_core/tests/test_utils_dlpack.py, ruff.toml |
Device, memory, and interop checks now raise explicit exceptions for invalid states or inputs. Tests cover invalid stream types, DLPack device IDs and capsules, and CUDA Array Interface stream values. Ruff’s global S101 ignore is removed, but the per-file ignore still applies to cuda_core/cuda/core/**. |
Program and cache checks cuda_core/cuda/core/_module.pyx, cuda_core/cuda/core/_program.pyx, cuda_core/cuda/core/utils/_program_cache/*, cuda_core/tests/test_module.py |
Unsupported code types, missing architecture values, and missing program-cache exceptions now raise explicit errors. A test checks rejection of an unsupported code type. |
System value validation cuda_core/cuda/core/system/*, cuda_core/cuda/core/_layout.pyx, cuda_core/tests/system/*, cuda_core/docs/source/release/1.3.0-notes.rst |
P-state bounds, field-value and event counts, and an axis-count invariant now raise explicit errors. Tests check rejection of multiple field values and events. Release notes describe the exception changes. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
Replace the remaining library assertions with explicit errors [#3202] |
✅ | |
Enable Ruff S101 for library code and limit the per-file ignore to tests [#3202] |
❌ | The per-file ignore still applies to cuda_core/cuda/core/**, including library code. |
Suggested labels: bug
Suggested reviewers: mdboom, andy-jost, cpcloud
Priority:
Change: Bug fix
Merge Risk: 
Minimal · up to 00e3d
-
The changes are ready to merge subject to normal checks.
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: NVIDIA/cuda-python
- Branch: main
- File: .coderabbit.yaml
- Commit: a2fb804
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Enterprise
- Run ID:
80a8bc3b-f982-42c6-b3de-45e71db0863c
Files selected for processing: 18-
cuda_core/cuda/core/_device.pyxcuda_core/cuda/core/_memory/_managed_buffer.pycuda_core/cuda/core/_memory/_managed_memory_resource.pyxcuda_core/cuda/core/_memoryview.pyxcuda_core/cuda/core/_module.pyxcuda_core/cuda/core/_program.pyxcuda_core/cuda/core/system/_device.pyxcuda_core/cuda/core/system/_field_values.pxicuda_core/cuda/core/system/_system_events.pyxcuda_core/cuda/core/utils/_program_cache/_file_stream.pycuda_core/cuda/core/utils/_program_cache/_keys.pycuda_core/tests/system/test_system_device.pycuda_core/tests/system/test_system_events.pycuda_core/tests/test_memory.pycuda_core/tests/test_module.pycuda_core/tests/test_utils.pycuda_core/tests/test_utils_dlpack.pyruff.toml
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
-
|
/ok to test 35983fa |
@Andy-Jost, there was an error processing your request: See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/ |
Andy-Jost
left a comment
There was a problem hiding this comment.
Thanks for taking this on, @fedonman. The conversions follow the rules in #3202, the exception types match who can trigger each check, and the new tests check the right things. Three items before this merges.
-
cuda_core/cuda/core/_layout.pyx, line 1185. One library assert remains:assert in_i == ndiminunsqueeze_extents. The inventory on #2697 filed every_layout.pyxhit as a doctest line. This one is code. It is an internal invariant on the layout math, so underpython -Othe check vanishes. The function already raises undernogilat lines 1164 and 1167, so a raise is legal here. Please replace it with the internal-invariant form:if in_i != ndim: raise RuntimeError( f"internal cuda.core error, please report: unsqueeze_extents consumed {in_i} of {ndim} input axes" )
Please also update the PR description. The count is 15, not 14. The fifth
_memoryview.pyxhit that the issue counts is an example inside theargs_viewable_as_strided_memorydocstring and stays as text. -
cuda_core/docs/source/release/1.3.0-notes.rst, line 104. Please add a "Fixes and enhancements" entry. Callers now seeValueErrororTypeErrorwhere they sawAssertionErrorbefore, or nothing underpython -O. The affected entry points areStridedMemoryView.from_dlpack(producer reports a bad device id, or__dlpack__returns a non-capsule),StridedMemoryView.from_cuda_array_interface(CAIstreamof 0),ManagedMemoryResource.allocate(non-Streamargument),ObjectCodeunpickling (unknown code type), andsystem.FieldValue/system.SystemEvent(payload length other than 1). Internal invariants now raiseRuntimeErrorwith the "internal cuda.core error, please report" prefix. Please reference #3202. The 1.3.0 notes already record exception-type changes of this kind, anderror_handling.rstdocuments the contract these now follow. -
cuda_core/tests/test_memory.py, line 1158 (nit).test_managed_memory_resource_allocate_rejects_graph_builderclosesgbbut notmr. The test guide asks that each test release what it constructs. Please createmrandgbinside onetryand close both infinally. CodeRabbit raised the same point.
I am setting the labels, milestone, and assignees and starting CI now; the diff touches library sources, tests, and ruff.toml only. Once the three items are in and CI is green, this is ready to merge.
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.
|
Thanks @Andy-Jost, all three are done, and the description now says 15. The release note also covers |
|
/ok to test 00e3dd4 |
|
|
Thanks, @fedonman: the three items are in and look right. Two more things before this can merge, both found by CI on 00e3dd4:
After the push I will start CI again and merge when it is green. |
Replaces the 15 remaining
assertstatements incuda_core/cuda/corewith explicit errors, following the rules in the issue: a value from a caller, a DLPack or CAI producer, or an NVML payload raisesValueErrororTypeErrornaming the value, and an internal invariant raises the "internal cuda.core error, please report"RuntimeError. Theassert Falseinview_as_dlpackgets aValueErrorinstead, since a producer reaches it by returning anything other than an unconsumed capsule. The issue's fifth_memoryview.pyxhit is a docstring example and stays; the fifteenth is the one inunsqueeze_extentsin_layout.pyx. A 1.3.0 release note lists the entry points whose exception type changes.S101is enforced forcuda_core/cuda/core/**only, because enabling it everywhere outsidetests/flags about 180 asserts in pathfinder, the samples and the test helpers. Ruff does not read.pyxfiles, so it does not cover the Cython asserts. The two in_ipc.pyxstay with #2704.Closes #3202