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/docs/source/api.rst b/cuda_core/docs/source/api.rst index 99a4dca6e77..41ff5f179ed 100644 --- a/cuda_core/docs/source/api.rst +++ b/cuda_core/docs/source/api.rst @@ -282,16 +282,14 @@ Types system.Device system.NvlinkInfo -.. module:: cuda.core.utils - Utility functions ----------------- .. autosummary:: :toctree: generated/ - args_viewable_as_strided_memory + utils.args_viewable_as_strided_memory :template: autosummary/cyclass.rst - StridedMemoryView + utils.StridedMemoryView 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 ----------------------- 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 # --------------------------------------------------------------------------- diff --git a/cuda_core/tests/test_graphics.py b/cuda_core/tests/test_graphics.py index 12184815b02..4358a0c7b38 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.utils import StridedMemoryView # --------------------------------------------------------------------------- # GL context + buffer helpers diff --git a/cuda_core/tests/test_memory.py b/cuda_core/tests/test_memory.py index 3ae6960fc29..d6ad6ac3320 100644 --- a/cuda_core/tests/test_memory.py +++ b/cuda_core/tests/test_memory.py @@ -1603,3 +1603,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) diff --git a/cuda_core/tests/test_tensor_map.py b/cuda_core/tests/test_tensor_map.py index 9ca8790d2b8..2596a9daf82 100644 --- a/cuda_core/tests/test_tensor_map.py +++ b/cuda_core/tests/test_tensor_map.py @@ -8,7 +8,6 @@ from cuda.core import ( Device, ManagedMemoryResourceOptions, - StridedMemoryView, TensorMapDescriptor, system, ) @@ -23,6 +22,7 @@ TensorMapSwizzle, _require_view_device, ) +from cuda.core.utils import StridedMemoryView @pytest.fixture