Skip to content

Commit 5de2cb6

Browse files
authored
VMM: purge support of win32 + add warning (#1310)
* purge support of win32 + add warning * fix linter errors
1 parent df3c661 commit 5de2cb6

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

cuda_core/cuda/core/experimental/_memory/_virtual_memory_resource.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class VirtualMemoryResourceOptions:
7474
peers: Iterable[int] = field(default_factory=tuple)
7575
self_access: VirtualMemoryAccessTypeT = "rw"
7676
peer_access: VirtualMemoryAccessTypeT = "rw"
77-
win32_handle_metadata: int | None = 0
7877

7978
_a = driver.CUmemAccess_flags
8079
_access_flags = {"rw": _a.CU_MEM_ACCESS_FLAGS_PROT_READWRITE, "r": _a.CU_MEM_ACCESS_FLAGS_PROT_READ, None: 0}
@@ -128,6 +127,8 @@ def _location_type_to_driver(spec: str):
128127

129128
@staticmethod
130129
def _handle_type_to_driver(spec: str):
130+
if spec == "win32":
131+
raise NotImplementedError("win32 is currently not supported, please reach out to the CUDA Python team")
131132
handle_type = VirtualMemoryResourceOptions._handle_types.get(spec)
132133
if handle_type is None:
133134
raise ValueError(f"Unsupported handle_type: {spec!r}")
@@ -151,6 +152,13 @@ class VirtualMemoryResource(MemoryResource):
151152
152153
config : VirtualMemoryResourceOptions
153154
A configuration object for the VirtualMemoryResource
155+
156+
157+
Warning
158+
-------
159+
This is a low-level API that is provided only for convenience. Make sure you fully understand
160+
how CUDA Virtual Memory Management works before using this. Other MemoryResource subclasses
161+
in cuda.core should already meet the common needs.
154162
"""
155163

156164
def __init__(self, device_id: Device | int, config: VirtualMemoryResourceOptions = None):
@@ -217,7 +225,7 @@ def modify_allocation(self, buf: Buffer, new_size: int, config: VirtualMemoryRes
217225
prop.location.id = self.device.device_id
218226
prop.allocFlags.gpuDirectRDMACapable = 1 if self.config.gpu_direct_rdma else 0
219227
prop.requestedHandleTypes = VirtualMemoryResourceOptions._handle_type_to_driver(self.config.handle_type)
220-
prop.win32HandleMetaData = self.config.win32_handle_metadata if self.config.win32_handle_metadata else 0
228+
prop.win32HandleMetaData = 0
221229

222230
# Query granularity
223231
gran_flag = VirtualMemoryResourceOptions._granularity_to_driver(self.config.granularity)
@@ -505,7 +513,7 @@ def allocate(self, size: int, stream: Stream | None = None) -> Buffer:
505513
prop.location.id = self.device.device_id if config.location_type == "device" else -1
506514
prop.allocFlags.gpuDirectRDMACapable = 1 if config.gpu_direct_rdma else 0
507515
prop.requestedHandleTypes = VirtualMemoryResourceOptions._handle_type_to_driver(config.handle_type)
508-
prop.win32HandleMetaData = self.config.win32_handle_metadata if self.config.win32_handle_metadata else 0
516+
prop.win32HandleMetaData = 0
509517

510518
# ---- Query and apply granularity ----
511519
# Choose min vs recommended granularity per config

cuda_core/tests/test_memory.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import ctypes
55
import sys
6-
from ctypes import wintypes
76

87
try:
98
from cuda.bindings import driver
@@ -325,23 +324,8 @@ def test_device_memory_resource_initialization(use_device_object):
325324

326325

327326
def get_handle_type():
328-
def get_sa():
329-
class SECURITY_ATTRIBUTES(ctypes.Structure):
330-
_fields_ = [
331-
("nLength", wintypes.DWORD),
332-
("lpSecurityDescriptor", wintypes.LPVOID),
333-
("bInheritHandle", wintypes.BOOL),
334-
]
335-
336-
sa = SECURITY_ATTRIBUTES()
337-
sa.nLength = ctypes.sizeof(sa)
338-
sa.lpSecurityDescriptor = None
339-
sa.bInheritHandle = False # TODO: why?
340-
341-
return sa
342-
343327
if IS_WINDOWS:
344-
return (("win32", get_sa()), ("win32_kmt", None))
328+
return (("win32", None), ("win32_kmt", None))
345329
else:
346330
return (("posix_fd", None),)
347331

@@ -362,17 +346,17 @@ def test_vmm_allocator_basic_allocation(use_device_object, handle_type):
362346
pytest.skip("Virtual memory management is not supported on this device")
363347

364348
handle_type, security_attribute = handle_type # unpack
365-
win32_handle_metadata = ctypes.addressof(security_attribute) if security_attribute else 0
366-
options = VirtualMemoryResourceOptions(
367-
handle_type=handle_type,
368-
win32_handle_metadata=win32_handle_metadata,
369-
)
349+
options = VirtualMemoryResourceOptions(handle_type=handle_type)
370350
# Create VMM allocator with default config
371351
device_arg = device if use_device_object else device.device_id
372352
vmm_mr = VirtualMemoryResource(device_arg, config=options)
373353

374354
# Test basic allocation
375-
buffer = vmm_mr.allocate(4096)
355+
try:
356+
buffer = vmm_mr.allocate(4096)
357+
except NotImplementedError:
358+
assert handle_type == "win32"
359+
return
376360
assert buffer.size >= 4096 # May be aligned up
377361
assert buffer.device_id == device.device_id
378362
assert buffer.memory_resource == vmm_mr
@@ -483,16 +467,15 @@ def test_vmm_allocator_grow_allocation(handle_type):
483467
pytest.skip("Virtual memory management is not supported on this device")
484468

485469
handle_type, security_attribute = handle_type # unpack
486-
win32_handle_metadata = ctypes.addressof(security_attribute) if security_attribute else 0
487-
options = VirtualMemoryResourceOptions(
488-
handle_type=handle_type,
489-
win32_handle_metadata=win32_handle_metadata,
490-
)
491-
470+
options = VirtualMemoryResourceOptions(handle_type=handle_type)
492471
vmm_mr = VirtualMemoryResource(device, config=options)
493472

494473
# Create initial allocation
495-
buffer = vmm_mr.allocate(2 * 1024 * 1024)
474+
try:
475+
buffer = vmm_mr.allocate(2 * 1024 * 1024)
476+
except NotImplementedError:
477+
assert handle_type == "win32"
478+
return
496479
original_size = buffer.size
497480

498481
# Grow the allocation

0 commit comments

Comments
 (0)