Skip to content

Commit 984c6c4

Browse files
benhgleofang
andauthored
Fix VirtualMemoryResourceOptions docs (#1150)
* update docstring in virtualresourceoptions * fix unaligned dic * match other classes better * flip self and peer * update docs to use automatic generation * Update cuda_core/cuda/core/experimental/_memory.pyx Co-authored-by: Leo Fang <leo80042@gmail.com> * Update cuda_core/cuda/core/experimental/_memory.pyx Co-authored-by: Leo Fang <leo80042@gmail.com> * Update cuda_core/cuda/core/experimental/_memory.pyx Co-authored-by: Leo Fang <leo80042@gmail.com> * Update cuda_core/cuda/core/experimental/_memory.pyx Co-authored-by: Leo Fang <leo80042@gmail.com> * Update cuda_core/cuda/core/experimental/_memory.pyx Co-authored-by: Leo Fang <leo80042@gmail.com> * Reply to Leo's comments * Add _memory. qualifier to make docs resolver happy, and remove extra indent * Apply suggestions from code review --------- Co-authored-by: Leo Fang <leo80042@gmail.com> Co-authored-by: Leo Fang <leof@nvidia.com>
1 parent bcd40ff commit 984c6c4

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

cuda_core/cuda/core/experimental/_memory.pyx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,10 @@ class _SynchronousMemoryResource(MemoryResource):
10891089
return self._dev_id
10901090

10911091

1092-
VirtualMemoryHandleTypeT = Literal["posix_fd", "generic", "none", "win32", "win32_kmt", "fabric"]
1092+
VirtualMemoryHandleTypeT = Union[Literal["posix_fd", "generic", "win32", "win32_kmt", "fabric"], None]
10931093
VirtualMemoryLocationTypeT = Literal["device", "host", "host_numa", "host_numa_current"]
10941094
VirtualMemoryGranularityT = Literal["minimum", "recommended"]
1095-
VirtualMemoryAccessTypeT = Literal["rw", "r", "none"]
1095+
VirtualMemoryAccessTypeT = Union[Literal["rw", "r"], None]
10961096
VirtualMemoryAllocationTypeT = Literal["pinned", "managed"]
10971097

10981098

@@ -1101,18 +1101,31 @@ class VirtualMemoryResourceOptions:
11011101
"""A configuration object for the VirtualMemoryResource
11021102
Stores configuration information which tells the resource how to use the CUDA VMM APIs
11031103

1104-
Args:
1105-
handle_type: Export handle type for the physical allocation. Use
1106-
CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR on Linux if you plan to
1107-
import/export the allocation (required for cuMemRetainAllocationHandle).
1108-
Use CU_MEM_HANDLE_TYPE_NONE if you don't need an exportable handle.
1109-
gpu_direct_rdma: Hint that the allocation should be GDR-capable (if supported).
1110-
granularity: 'recommended' or 'minimum'. Controls granularity query and size rounding.
1111-
addr_hint: A (optional) virtual address hint to try to reserve at. 0 -> let CUDA choose.
1112-
addr_align: Alignment for the VA reservation. If None, use the queried granularity.
1113-
peers: Extra device IDs that should be granted access in addition to `device`.
1114-
self_access: Access flags for the owning device ('rw', 'r', or 'none').
1115-
peer_access: Access flags for peers ('rw' or 'r').
1104+
Attributes
1105+
----------
1106+
allocation_type: :obj:`~_memory.VirtualMemoryAllocationTypeT`
1107+
Controls the type of allocation.
1108+
location_type: :obj:`~_memory.VirtualMemoryLocationTypeT`
1109+
Controls the location of the allocation.
1110+
handle_type: :obj:`~_memory.VirtualMemoryHandleTypeT`
1111+
Export handle type for the physical allocation. Use
1112+
``"posix_fd"`` on Linux if you plan to
1113+
import/export the allocation (required for cuMemRetainAllocationHandle).
1114+
Use `None` if you don't need an exportable handle.
1115+
gpu_direct_rdma: bool
1116+
Hint that the allocation should be GDR-capable (if supported).
1117+
granularity: :obj:`~_memory.VirtualMemoryGranularityT`
1118+
Controls granularity query and size rounding.
1119+
addr_hint: int
1120+
A (optional) virtual address hint to try to reserve at. Setting it to 0 lets the CUDA driver decide.
1121+
addr_align: int
1122+
Alignment for the VA reservation. If `None`, use the queried granularity.
1123+
peers: Iterable[int]
1124+
Extra device IDs that should be granted access in addition to ``device``.
1125+
self_access: :obj:`~_memory.VirtualMemoryAccessTypeT`
1126+
Access flags for the owning device.
1127+
peer_access: :obj:`~_memory.VirtualMemoryAccessTypeT`
1128+
Access flags for peers.
11161129
"""
11171130
# Human-friendly strings; normalized in __post_init__
11181131
allocation_type: VirtualMemoryAllocationTypeT = "pinned"
@@ -1127,9 +1140,9 @@ class VirtualMemoryResourceOptions:
11271140
peer_access: VirtualMemoryAccessTypeT = "rw"
11281141

11291142
_a = driver.CUmemAccess_flags
1130-
_access_flags = {"rw": _a.CU_MEM_ACCESS_FLAGS_PROT_READWRITE, "r": _a.CU_MEM_ACCESS_FLAGS_PROT_READ, "none": 0}
1143+
_access_flags = {"rw": _a.CU_MEM_ACCESS_FLAGS_PROT_READWRITE, "r": _a.CU_MEM_ACCESS_FLAGS_PROT_READ, None: 0}
11311144
_h = driver.CUmemAllocationHandleType
1132-
_handle_types = {"none": _h.CU_MEM_HANDLE_TYPE_NONE, "posix_fd": _h.CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR, "win32": _h.CU_MEM_HANDLE_TYPE_WIN32, "win32_kmt": _h.CU_MEM_HANDLE_TYPE_WIN32_KMT, "fabric": _h.CU_MEM_HANDLE_TYPE_FABRIC}
1145+
_handle_types = {None: _h.CU_MEM_HANDLE_TYPE_NONE, "posix_fd": _h.CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR, "win32": _h.CU_MEM_HANDLE_TYPE_WIN32, "win32_kmt": _h.CU_MEM_HANDLE_TYPE_WIN32_KMT, "fabric": _h.CU_MEM_HANDLE_TYPE_FABRIC}
11331146
_g = driver.CUmemAllocationGranularity_flags
11341147
_granularity = {"recommended": _g.CU_MEM_ALLOC_GRANULARITY_RECOMMENDED, "minimum": _g.CU_MEM_ALLOC_GRANULARITY_MINIMUM}
11351148
_l = driver.CUmemLocationType

cuda_core/docs/source/api_private.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ CUDA runtime
1818

1919
_memory.PyCapsule
2020
_memory.DevicePointerT
21+
_memory.VirtualMemoryAllocationTypeT
22+
_memory.VirtualMemoryLocationTypeT
23+
_memory.VirtualMemoryGranularityT
24+
_memory.VirtualMemoryAccessTypeT
25+
_memory.VirtualMemoryHandleTypeT
2126
_device.DeviceProperties
2227
_memory.IPCAllocationHandle
2328
_memory.IPCBufferDescriptor

0 commit comments

Comments
 (0)