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.
📝 Summary
Priority: Change: Bug fix Merge Risk:
|
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.
-
| def test_managed_memory_resource_allocate_rejects_graph_builder(init_cuda): | ||
| device = init_cuda | ||
| skip_if_managed_memory_unsupported(device) | ||
| mr = create_managed_memory_resource_or_skip(ManagedMemoryResourceOptions(preferred_location=device.device_id)) |
There was a problem hiding this comment.
important: Close the owned managed memory resource. ManagedMemoryResourceOptions(...) creates an owned pool, but the finally block closes only gb. If the assertion fails and pytest retains the test frame, mr can remain live through fixture teardown and trigger an unreleased-resource failure. Close mr in a finally block that also covers graph-builder creation. As per coding guidelines, “Release what you construct regardless”. As per path instructions, “Release constructed resources; use context managers where suitable”.
Sources: Coding guidelines, Path instructions
Replaces the 14 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.S101is enforced forcuda_core/cuda/core/**only, because enabling it everywhere outsidetests/flags about 180 asserts in pathfinder, the samples and the test helpers. The two in_ipc.pyxstay with #2704.Closes #3202