Skip to content

[BUG]: register() accepts a mismatched UUID under python -O #2697

Open

Description

@fedonman

Is this a duplicate?

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 |
+-----------------------------------------+------------------------+----------------------+

Activity

  1. mdboom commented on Aug 25, 2026

    @mdboom
    Contributor

    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 some AGENTS.md content to exclude them going forward?

  2. fedonman commented on Aug 27, 2026

    @fedonman
    ContributorAuthor

    Here is the assert inventory for cuda_core/cuda/core on main, split by whether -O changes what a caller sees.

    Guarding a value that comes from outside, so the behaviour differs under -O:

    location guards
    _memory/_ipc.pyx:295 the UUID passed to register() (this issue)
    _memory/_managed_memory_resource.pyx:125 the stream= keyword of ManagedMemoryResource.allocate
    _module.pyx:640 code_type in ObjectCode._init, reached when unpickling
    _memoryview.pyx:1052, _memoryview.pyx:1059, _memoryview.pyx:1226 the device ordinal and stream a producer reports through __dlpack_device__() and __cuda_array_interface__
    system/_device.pyx:46 a P-state range that _pstate_to_enum just below rejects with ValueError
    system/_field_values.pxi:15, system/_system_events.pyx:43 the length of the NVML payload passed to __init__

    Internal invariants, where -O only 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.pyx and _layout.pyi are doctest lines, and the cuda_bindings ones are in generated output. cuda_pathfinder has 13.

    Glad to convert the first group in one PR if that is the direction.

  3. added this to the cuda.core 1.3.0 milestone on Sep 24, 2026
  4. added
    bugSomething isn't working
    cuda.coreEverything related to the cuda.core module
    and removed
    triageNeeds the team's attention
    on Sep 24, 2026
  5. Andy-Jost commented on Oct 23, 2026

    @Andy-Jost
    Contributor

    #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Medium priority - Should dobugSomething isn't workingcuda.coreEverything related to the cuda.core module

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions