Skip to content

Commit 8212401

Browse files
rparolinclaude
andcommitted
cuda.core: satisfy pre-commit (cython-lint, stubs, formatting)
- Drop unused `intptr_t` cimports in _mipmapped_array.pyx / _surface.pyx (flagged by cython-lint; the handle ints now go through as_intptr). - Regenerate the .pyi stubs (stubgen-pyx) to match the texture/surface .pyx after the resource-handle + copy-API changes. - isort/ruff-format fixups (cuda.core.textures import ordering, etc.). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ca73fb4 commit 8212401

9 files changed

Lines changed: 34 additions & 29 deletions

File tree

cuda_core/cuda/core/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ class _PatchedProperty(metaclass=_PatchedPropMeta):
113113
# Texture/surface types live under the cuda.core.textures namespace (not the
114114
# flat cuda.core namespace); import the subpackage so it is available as
115115
# `cuda.core.textures` after `import cuda.core`.
116-
import cuda.core.textures
117-
118116
# Must come after the cuda.core._* extension imports above: loading graph
119117
# earlier interacts badly with the merged-wheel __path__ rewrite and leaves
120118
# Graph/GraphBuilder/GraphCompleteOptions/GraphDebugPrintOptions missing from
121119
# cuda.core.graph.
122120
import cuda.core.graph
121+
import cuda.core.textures

cuda_core/cuda/core/_array.pyi

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ class CUDAArray:
4444
"""
4545

4646
def close(self):
47-
"""Destroy the underlying ``CUarray`` if owned by this object."""
47+
"""Release this object's reference to the underlying ``CUarray``.
48+
49+
Destruction (``cuArrayDestroy``) happens via the handle's deleter when
50+
the last reference is dropped; for a non-owning handle (graphics interop
51+
or a mipmap-level view) nothing is destroyed. Idempotent: a second call
52+
(or destruction after ``close()``) is a no-op.
53+
"""
4854

4955
def __init__(self, *args, **kwargs):
5056
...
@@ -77,9 +83,9 @@ class CUDAArray:
7783
"""Wrap an externally-allocated ``CUarray``.
7884
7985
Intended for graphics interop (``cuGraphicsSubResourceGetMappedArray``)
80-
where the array is owned by the graphics API. With ``owning=False``,
81-
:meth:`close` and ``__dealloc__`` will not free the handle. Shape,
82-
format, and channel count are queried from the driver.
86+
where the array is owned by the graphics API. With ``owning=False`` the
87+
underlying ``CUarray`` is never destroyed by this object. Shape, format,
88+
and channel count are queried from the driver.
8389
"""
8490

8591
@property
@@ -149,9 +155,6 @@ class CUDAArray:
149155
def size_bytes(self):
150156
"""Total bytes of array storage (``prod(shape) * element_size``)."""
151157

152-
def __dealloc__(self):
153-
...
154-
155158
def __enter__(self):
156159
...
157160

cuda_core/cuda/core/_mipmapped_array.pyi

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class MipmappedArray:
1717
"""
1818

1919
def close(self):
20-
"""Destroy the underlying ``CUmipmappedArray`` if owned.
20+
"""Release this object's reference to the underlying ``CUmipmappedArray``.
2121
22-
After ``close()`` any level :class:`CUDAArray` returned by :meth:`get_level`
23-
becomes invalid; callers must not access them.
22+
Destruction (``cuMipmappedArrayDestroy``) happens via the handle's
23+
deleter when the last reference is dropped. A level :class:`CUDAArray`
24+
from :meth:`get_level` holds its own reference to this mipmap's storage,
25+
so it stays valid until both it and this object are released. Idempotent.
2426
"""
2527

2628
def __init__(self, *args, **kwargs):
@@ -99,9 +101,6 @@ class MipmappedArray:
99101
def device(self):
100102
"""The :class:`Device` this mipmap was allocated on."""
101103

102-
def __dealloc__(self):
103-
...
104-
105104
def __enter__(self):
106105
...
107106

cuda_core/cuda/core/_mipmapped_array.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from __future__ import annotations
66

7-
from libc.stdint cimport intptr_t
87
from libc.string cimport memset
98

109
from cuda.bindings cimport cydriver

cuda_core/cuda/core/_resource_handles.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ NvrtcProgramHandle = shared_ptr
1919
NvvmProgramHandle = shared_ptr
2020
NvJitLinkHandle = shared_ptr
2121
CuLinkHandle = shared_ptr
22-
FileDescriptorHandle = shared_ptr
22+
FileDescriptorHandle = shared_ptr
23+
ArrayHandle = shared_ptr
24+
MipmappedArrayHandle = shared_ptr
25+
TexObjectHandle = shared_ptr
26+
SurfObjectHandle = shared_ptr

cuda_core/cuda/core/_surface.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ class SurfaceObject:
1919
"""
2020

2121
def close(self):
22-
"""Destroy the underlying ``CUsurfObject``."""
22+
"""Release this object's reference to the underlying ``CUsurfObject``.
23+
24+
Destruction (``cuSurfObjectDestroy``) and release of the backing array
25+
happen via the handle's deleter when the last reference is dropped.
26+
Idempotent.
27+
"""
2328

2429
def __init__(self, *args, **kwargs):
2530
...
@@ -55,9 +60,6 @@ class SurfaceObject:
5560
def device(self):
5661
...
5762

58-
def __dealloc__(self):
59-
...
60-
6163
def __enter__(self):
6264
...
6365

cuda_core/cuda/core/_surface.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from __future__ import annotations
66

7-
from libc.stdint cimport intptr_t
87
from libc.string cimport memset
98

109
from cuda.bindings cimport cydriver

cuda_core/cuda/core/_texture.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ class TextureObject:
209209
"""
210210

211211
def close(self):
212-
"""Destroy the underlying ``CUtexObject``."""
212+
"""Release this object's reference to the underlying ``CUtexObject``.
213+
214+
Destruction (``cuTexObjectDestroy``) and release of the backing resource
215+
happen via the handle's deleter when the last reference is dropped.
216+
Idempotent.
217+
"""
213218

214219
def __init__(self, *args, **kwargs):
215220
...
@@ -240,9 +245,6 @@ class TextureObject:
240245
def device(self):
241246
...
242247

243-
def __dealloc__(self):
244-
...
245-
246248
def __enter__(self):
247249
...
248250

cuda_core/tests/test_texture_surface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,7 @@ def test_texture_surface_close_is_idempotent(init_cuda):
620620
assert arr.handle == 0
621621
arr.close() # second close must not raise
622622

623-
mip = MipmappedArray.from_descriptor(
624-
shape=(8, 8), format=ArrayFormat.UINT8, num_channels=1, num_levels=2
625-
)
623+
mip = MipmappedArray.from_descriptor(shape=(8, 8), format=ArrayFormat.UINT8, num_channels=1, num_levels=2)
626624
mip.close()
627625
assert mip.handle == 0
628626
mip.close()

0 commit comments

Comments
 (0)