Repository navigation
[BUG]: register() accepts a mismatched UUID under python -O #2697
Copy link
Copy link
Open
Labels
P1Medium priority - Should doMedium priority - Should dobugSomething isn't workingSomething isn't workingcuda.coreEverything related to the cuda.core moduleEverything related to the cuda.core module
Milestone
Description
Is this a duplicate?
- I confirmed there appear to be no duplicate issues for this bug and that I agree to the Code of Conduct
Type of Bug
Silent Failure
Component
cuda.core
Describe the bug
DeviceMemoryResource.register() and PinnedMemoryResource.register() check that the UUID they are given matches the resource's own with a bare assert in MP_register, so the check is absent whenever CPython runs with -O. The call then registers the resource under the other key and rewrites the resource's UUID, and mr.uuid reports the new value from then on.
How to Reproduce
import uuid
from cuda.core import Device, DeviceMemoryResource, DeviceMemoryResourceOptions
dev = Device(); dev.set_current()
mr = DeviceMemoryResource(dev, DeviceMemoryResourceOptions(ipc_enabled=True))
try:
mr.register(uuid.UUID("00000000-0000-0000-0000-000000000001"))
except AssertionError:
print("rejected")
else:
print("accepted, uuid is now", mr.uuid)$ python repro.py
rejected
$ python -O repro.py
accepted, uuid is now 00000000-0000-0000-0000-000000000001
Expected behavior
register() should reject a UUID that is not the resource's own whether or not CPython was started with -O. Assertions are removed under -O, so the check as written does not exist in an optimized interpreter and the resource silently takes on the other key instead of raising.
Operating System
Ubuntu 26.04 LTS
nvidia-smi output
Tue Aug 25 15:01:31 2026
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 595.84 Driver Version: 595.84 CUDA Version: 13.2 |
+-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 3050 ... Off | 00000000:01:00.0 Off | N/A |
| N/A 59C P3 749W / 30W | 11MiB / 4096MiB | 8% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1Medium priority - Should doMedium priority - Should dobugSomething isn't workingSomething isn't workingcuda.coreEverything related to the cuda.core moduleEverything related to the cuda.core module
Activity
mdboom commentedon Aug 25, 2026
IMHO, we should remove all asserts from the library itself (tests are fine), since they have this behavioral issue with
-O. Maybe we clean all of them up and add someAGENTS.mdcontent to exclude them going forward?fedonman commentedon Aug 27, 2026
Here is the
assertinventory forcuda_core/cuda/coreonmain, split by whether-Ochanges what a caller sees.Guarding a value that comes from outside, so the behaviour differs under
-O:_memory/_ipc.pyx:295register()(this issue)_memory/_managed_memory_resource.pyx:125stream=keyword ofManagedMemoryResource.allocate_module.pyx:640code_typeinObjectCode._init, reached when unpickling_memoryview.pyx:1052,_memoryview.pyx:1059,_memoryview.pyx:1226__dlpack_device__()and__cuda_array_interface__system/_device.pyx:46_pstate_to_enumjust below rejects withValueErrorsystem/_field_values.pxi:15,system/_system_events.pyx:43__init__Internal invariants, where
-Oonly drops a debug check:_device.pyx:1646,_memory/_ipc.pyx:272,_memory/_managed_buffer.py:253,_memory/_virtual_memory_resource.py:246,_memoryview.pyx:1102,_program.pyx:1337,utils/_program_cache/_file_stream.py:113,utils/_program_cache/_keys.py:546.The 81 hits in
_layout.pyxand_layout.pyiare doctest lines, and thecuda_bindingsones are in generated output.cuda_pathfinderhas 13.Glad to convert the first group in one PR if that is the direction.
Andy-Jost commentedon Oct 23, 2026
#2704 covers the
register()check. @fedonman, thank you for the inventory and the offer: #3202 tracks the rest, and it is yours if you want it.