From 5b2098e4ef41acbd82bbb9c028030dd94cde9a38 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 5 May 2026 17:09:32 -0400 Subject: [PATCH 1/8] Fix #2027: Remove StridedMemoryView etc. from public API --- cuda_core/cuda/core/__init__.py | 4 ---- cuda_core/tests/test_graphics.py | 2 +- cuda_core/tests/test_tensor_map.py | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cuda_core/cuda/core/__init__.py b/cuda_core/cuda/core/__init__.py index d4042aefcfb..56027d41fe3 100644 --- a/cuda_core/cuda/core/__init__.py +++ b/cuda_core/cuda/core/__init__.py @@ -57,10 +57,6 @@ def _import_versioned_module(): VirtualMemoryResource, VirtualMemoryResourceOptions, ) -from cuda.core._memoryview import ( - StridedMemoryView, - args_viewable_as_strided_memory, -) from cuda.core._module import Kernel, ObjectCode from cuda.core._program import Program, ProgramOptions from cuda.core._stream import ( diff --git a/cuda_core/tests/test_graphics.py b/cuda_core/tests/test_graphics.py index 12184815b02..717703e9e87 100644 --- a/cuda_core/tests/test_graphics.py +++ b/cuda_core/tests/test_graphics.py @@ -17,8 +17,8 @@ Buffer, Device, GraphicsResource, - StridedMemoryView, ) +from cuda.core._memoryview import StridedMemoryView # --------------------------------------------------------------------------- # GL context + buffer helpers diff --git a/cuda_core/tests/test_tensor_map.py b/cuda_core/tests/test_tensor_map.py index 9ca8790d2b8..195841650b8 100644 --- a/cuda_core/tests/test_tensor_map.py +++ b/cuda_core/tests/test_tensor_map.py @@ -8,11 +8,11 @@ from cuda.core import ( Device, ManagedMemoryResourceOptions, - StridedMemoryView, TensorMapDescriptor, system, ) from cuda.core._dlpack import DLDeviceType +from cuda.core._memoryview import StridedMemoryView from cuda.core._tensor_map import ( TensorMapDataType, TensorMapDescriptorOptions, From 2b9fc72c6f07dc8e5b6dcf2601ae3a5114baa6cb Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 5 May 2026 17:14:10 -0400 Subject: [PATCH 2/8] Add regression tests --- cuda_core/tests/test_memory.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cuda_core/tests/test_memory.py b/cuda_core/tests/test_memory.py index fb99895616d..658fadd5a74 100644 --- a/cuda_core/tests/test_memory.py +++ b/cuda_core/tests/test_memory.py @@ -1595,3 +1595,27 @@ def test_memory_resource_alloc_zero_bytes(init_cuda, memory_resource_factory): assert buffer.handle >= 0 assert buffer.size == 0 assert buffer.device_id == mr.device_id + + +def test_strided_memory_view_not_in_top_level_namespace(): + # Regression test for issue #2027: StridedMemoryView and + # args_viewable_as_strided_memory must only be exposed via + # cuda.core.utils, not the top-level cuda.core namespace. + import cuda.core + import cuda.core.utils + + assert not hasattr(cuda.core, "StridedMemoryView") + assert not hasattr(cuda.core, "args_viewable_as_strided_memory") + + assert hasattr(cuda.core.utils, "StridedMemoryView") + assert hasattr(cuda.core.utils, "args_viewable_as_strided_memory") + + +def test_top_level_namespace_excludes_known_leaks(): + # Hardening test: lock the public top-level namespace against + # accidental re-introduction of known-leaked symbols. + import cuda.core + + public = {n for n in dir(cuda.core) if not n.startswith("_")} + leaked = {"StridedMemoryView", "args_viewable_as_strided_memory"} + assert not (public & leaked) From a879e983520c85c8aa4b06898d39d6a0eb8a8c09 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 5 May 2026 18:54:06 -0400 Subject: [PATCH 3/8] Update cuda_core/tests/test_graphics.py Co-authored-by: Leo Fang --- cuda_core/tests/test_graphics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_core/tests/test_graphics.py b/cuda_core/tests/test_graphics.py index 717703e9e87..4358a0c7b38 100644 --- a/cuda_core/tests/test_graphics.py +++ b/cuda_core/tests/test_graphics.py @@ -18,7 +18,7 @@ Device, GraphicsResource, ) -from cuda.core._memoryview import StridedMemoryView +from cuda.core.utils import StridedMemoryView # --------------------------------------------------------------------------- # GL context + buffer helpers From 0c35479605d49b18d42cda03fc5182109f2d5456 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 5 May 2026 18:54:13 -0400 Subject: [PATCH 4/8] Update cuda_core/tests/test_tensor_map.py Co-authored-by: Leo Fang --- cuda_core/tests/test_tensor_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_core/tests/test_tensor_map.py b/cuda_core/tests/test_tensor_map.py index 195841650b8..a0be794f3d6 100644 --- a/cuda_core/tests/test_tensor_map.py +++ b/cuda_core/tests/test_tensor_map.py @@ -12,7 +12,7 @@ system, ) from cuda.core._dlpack import DLDeviceType -from cuda.core._memoryview import StridedMemoryView +from cuda.core.utils import StridedMemoryView from cuda.core._tensor_map import ( TensorMapDataType, TensorMapDescriptorOptions, From 0263f6ef04322ef49e56036db3576d772dad4b84 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 6 May 2026 07:51:44 -0400 Subject: [PATCH 5/8] Move to utils --- cuda_core/docs/source/api.rst | 4 ++-- cuda_core/examples/tma_tensor_map.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cuda_core/docs/source/api.rst b/cuda_core/docs/source/api.rst index 582f2140903..469c2e73041 100644 --- a/cuda_core/docs/source/api.rst +++ b/cuda_core/docs/source/api.rst @@ -287,8 +287,8 @@ Utility functions .. autosummary:: :toctree: generated/ - args_viewable_as_strided_memory + cuda.core.utils.args_viewable_as_strided_memory :template: autosummary/cyclass.rst - StridedMemoryView + cuda.core.utils.StridedMemoryView diff --git a/cuda_core/examples/tma_tensor_map.py b/cuda_core/examples/tma_tensor_map.py index 879632ad90d..8c048d4a15d 100644 --- a/cuda_core/examples/tma_tensor_map.py +++ b/cuda_core/examples/tma_tensor_map.py @@ -37,9 +37,9 @@ LaunchConfig, Program, ProgramOptions, - StridedMemoryView, launch, ) +from cuda.core.utils import StridedMemoryView from cuda.pathfinder import get_cuda_path_or_home # --------------------------------------------------------------------------- From a9a42074148798e1dea7300985bd72a801f83ccf Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 6 May 2026 08:26:00 -0400 Subject: [PATCH 6/8] Add release note --- cuda_core/docs/source/release/1.0.0-notes.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cuda_core/docs/source/release/1.0.0-notes.rst b/cuda_core/docs/source/release/1.0.0-notes.rst index 7f0ced8c10b..a0f1de1a121 100644 --- a/cuda_core/docs/source/release/1.0.0-notes.rst +++ b/cuda_core/docs/source/release/1.0.0-notes.rst @@ -125,6 +125,11 @@ Breaking changes - :obj:`cuda.core.typing.DevicePointerT` -> :obj:`cuda.core.typing.DevicePointerType` - :obj:`cuda.core.typing.IsStreamT` -> :obj:`cuda.core.typing.IsStreamType` +- :func:`args_viewable_as_strided_memory` and :class:`StridedMemoryView` are now + longer at the top-level in :mod:`cuda.core`. They are available publicly from the + :mod:`cuda.core.utils` module. + (`#2028 `__) + Fixes and enhancements ----------------------- From bd9210bb5f90d747a7ef1b59eb6642e9bbc32bc9 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 6 May 2026 10:16:48 -0400 Subject: [PATCH 7/8] Fix import sort --- cuda_core/tests/test_tensor_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_core/tests/test_tensor_map.py b/cuda_core/tests/test_tensor_map.py index a0be794f3d6..2596a9daf82 100644 --- a/cuda_core/tests/test_tensor_map.py +++ b/cuda_core/tests/test_tensor_map.py @@ -12,7 +12,6 @@ system, ) from cuda.core._dlpack import DLDeviceType -from cuda.core.utils import StridedMemoryView from cuda.core._tensor_map import ( TensorMapDataType, TensorMapDescriptorOptions, @@ -23,6 +22,7 @@ TensorMapSwizzle, _require_view_device, ) +from cuda.core.utils import StridedMemoryView @pytest.fixture From edc1e8bc875ca1cee458d904e7675ee27b512302 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 6 May 2026 10:20:49 -0400 Subject: [PATCH 8/8] Fix renames --- cuda_core/docs/source/api.rst | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cuda_core/docs/source/api.rst b/cuda_core/docs/source/api.rst index 469c2e73041..0252413c6ee 100644 --- a/cuda_core/docs/source/api.rst +++ b/cuda_core/docs/source/api.rst @@ -279,16 +279,14 @@ Types system.Device system.NvlinkInfo -.. module:: cuda.core.utils - Utility functions ----------------- .. autosummary:: :toctree: generated/ - cuda.core.utils.args_viewable_as_strided_memory + utils.args_viewable_as_strided_memory :template: autosummary/cyclass.rst - cuda.core.utils.StridedMemoryView + utils.StridedMemoryView