Repository navigation
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
Runtime Error
Component
cuda.core
Describe the bug
BAR1MemoryInfo subclasses MemoryInfo but declares its own cdef object _memory_info. The subclass methods use the new slot. The reserved property it inherits from MemoryInfo reads the base class's slot, which is never set. So Device.bar1_memory_info.reserved exists (it's in dir(), and isinstance(bar1, MemoryInfo) is true) but raises an internal AttributeError on None:
cuda-python/cuda_core/cuda/core/system/_memory.pxi
Lines 36 to 51 in ba7dcd0
| @property | |
| def reserved(self) -> int: | |
| """ | |
| Device memory (in bytes) reserved for system use (driver or firmware) | |
| """ | |
| return self._memory_info.reserved | |
| cdef class BAR1MemoryInfo(MemoryInfo): | |
| """ | |
| BAR1 Memory allocation information for a device. | |
| """ | |
| cdef object _memory_info | |
| def __init__(self, memory_info: nvml.BAR1Memory): | |
| self._memory_info = memory_info |
Code that handles a MemoryInfo generically (for example, logging total/used/free/reserved for both memory_info and bar1_memory_info) crashes on the BAR1 object.
How to Reproduce
from cuda.core import system
dev = system.Device(index=0)
bar1 = dev.bar1_memory_info
print(type(bar1).__mro__)
print("total:", bar1.total, "free:", bar1.free, "used:", bar1.used)
print("reserved:", bar1.reserved)Output:
(<class 'cuda.core.system._device.BAR1MemoryInfo'>, <class 'cuda.core.system._device.MemoryInfo'>, <class 'object'>)
total: 8589934592 free: 8589934592 used: 0
Traceback (most recent call last):
File "repro.py", line 7, in <module>
print("reserved:", bar1.reserved)
^^^^^^^^^^^^^
File "cuda/core/system/_memory.pxi", line 41, in cuda.core.system._device.MemoryInfo.reserved.__get__
AttributeError: 'NoneType' object has no attribute 'reserved'
Expected behavior
BAR1MemoryInfo shouldn't expose a reserved attribute that can only crash. nvmlBAR1Memory_t has no reserved field, so either BAR1MemoryInfo stops inheriting from MemoryInfo, or it overrides reserved with a clear NotSupportedError/AttributeError. Either way, the shadowed _memory_info slot should go.
Operating System
Linux container (python:3.12-slim) on Windows 11 / WSL2 with the NVIDIA container runtime. The bug is in the Cython class layout, so the OS shouldn't matter.
nvidia-smi output
| NVIDIA-SMI 610.59 KMD Version: 610.91 CUDA UMD Version: 13.3 |
| 0 NVIDIA GeForce RTX 3050 ... On | 00000000:01:00.0 Off | N/A |
Python 3.12.16. Packages:
cuda-bindings 13.5.0
cuda-core 1.3.0
cuda-pathfinder 1.9.0
cuda-toolkit 13.5.0
cupy-cuda13x 14.2.0
numpy 2.5.4
nvidia-cuda-nvrtc 13.5.37
nvidia-cufile 1.20.0.107
nvidia-nvfatbin 13.5.37
nvidia-nvjitlink 13.5.37
nvidia-nvvm 13.5.37
The file is unchanged between cuda-core-v1.3.0 and current main (ba7dcd0).
Happy to send a fix if that helps.
Activity
lxcxjxhx commentedon Nov 18, 2026
Reproduced on a 4060 Laptop (sm_89),
cuda-corefrom wheels, Windows:Same failure, and there is a second cause behind the one in the report that changes which fix is right.
The slot shadowing is real.
BAR1MemoryInfore-declarescdef object _memory_infoin_memory.pxi, so Cython gives the subclass its own field;__init__writes the subclass field, the inheritedreservedreads the base field, which is unset.total,freeandusedare shadowed in the subclass and work.But the base field would not help.
nvml.BAR1Memoryhas noreservedat all:compared with
Memory_v2, which does. So removing the duplicatecdeffixes the shadowing and still leavesreservedraising — with a different message (BAR1Memoryhas no attributereserved) instead of aNoneTypeone. Theisinstance(bar1, MemoryInfo)claim is also wrong in a way the report only half-states:BAR1MemoryInfogenuinely is aMemoryInfoby Cython type, but the thing it wraps is not aMemoryInfo-shaped struct.Two options, and I would take the first:
reserved. Drop the duplicatecdef(so all four readers use one field) and overridereservedto return0, documented as "BAR1 has no driver- or firmware-reserved region". Generic code that logstotal/used/free/reservedthen works unchanged, which is what the report asks for, and 0 is the truthful value rather than a placeholder.BAR1MemoryInfostops subclassingMemoryInfo;isinstancebecomes false and generic code has to branch. Correct but a breaking change for anything that already relies on the current (lying) type relationship.One thing I cannot settle from the outside: whether option 1's
0should instead beNone, to signal "not applicable" the wayNVML_VALUE_NOT_AVAILABLEis handled in #3468. That is a decision for whoever owns the API.Happy to open a PR for whichever you prefer — say the word and I will send it, given #3480 is in your queue.