Repository navigation
[fix] VM resource options #3343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,6 @@ from typing import TYPE_CHECKING, Iterable | |
|
|
||
| from cuda.core._device import Device, _device_from_uuid | ||
| from cuda.core._utils.cuda_utils import driver | ||
| from cuda.core._utils.version import BUILD_CUDA_MAJOR | ||
| from cuda.core.typing import ( | ||
| DevicePointerType, | ||
| VirtualMemoryAccessType, | ||
|
|
@@ -97,18 +96,19 @@ class VirtualMemoryResourceOptions: | |
| Attributes | ||
| ---------- | ||
| allocation_type: :obj:`~_memory.VirtualMemoryAllocationType` | str | ||
| Controls the type of allocation. | ||
| Controls the type of allocation. Only ``"pinned"`` is supported; | ||
| use :class:`ManagedMemoryResource` for managed memory. | ||
| location_type: :obj:`~_memory.VirtualMemoryLocationType` | str | ||
| Controls the location of the allocation. ``"host_numa"`` requires | ||
| ``numa_id``. ``"host_numa_current"`` is rejected because the driver | ||
| does not accept it for physical allocations. | ||
| handle_type: :obj:`~_memory.VirtualMemoryHandleType` | str | ||
| handle_type: :obj:`~_memory.VirtualMemoryHandleType` | str | None | ||
| Export handle type for the physical allocation, and the switch for | ||
| sharing buffers with other processes (see | ||
| :attr:`VirtualMemoryResource.is_ipc_enabled`). Use ``"posix_fd"`` on | ||
| Linux if you plan to import/export the allocation. Use `None` if you | ||
| don't need an exportable handle. ``location_type="host"`` requires | ||
| `None`. | ||
| if you plan to import/export the allocation. Use `None` if you | ||
| don't need an exportable handle. The default on Windows is `None`, | ||
| "posix_fd" otherwise. ``location_type="host"`` requires `None`. | ||
| gpu_direct_rdma: bool | ||
| Hint that the allocation should be GDR-capable (if supported). | ||
| granularity: :obj:`~_memory.VirtualMemoryGranularityType` | str | ||
|
|
@@ -134,7 +134,9 @@ class VirtualMemoryResourceOptions: | |
|
|
||
| allocation_type: VirtualMemoryAllocationType = VirtualMemoryAllocationType.PINNED | ||
| location_type: VirtualMemoryLocationType = VirtualMemoryLocationType.DEVICE | ||
| handle_type: VirtualMemoryHandleType = VirtualMemoryHandleType.POSIX_FD | ||
| handle_type: VirtualMemoryHandleType | None = field( | ||
| default_factory=lambda: None if platform.system() == "Windows" else VirtualMemoryHandleType.POSIX_FD | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important: Update tests that rely on the old Windows default. On Windows, |
||
| ) | ||
| granularity: VirtualMemoryGranularityType = VirtualMemoryGranularityType.RECOMMENDED | ||
| gpu_direct_rdma: bool = False | ||
| addr_hint: int | None = 0 | ||
|
|
@@ -170,12 +172,11 @@ class VirtualMemoryResourceOptions: | |
| VirtualMemoryLocationType.HOST_NUMA_CURRENT: _l.CU_MEM_LOCATION_TYPE_HOST_NUMA_CURRENT, | ||
| } | ||
| _t = driver.CUmemAllocationType | ||
| # CUDA 13 added MANAGED to CUmemAllocationType. The CUDA 12 build has no such member. | ||
| # cuMemCreate only supports PINNED, even on CUDA 13 builds with a MANAGED enum member. | ||
| _allocation_type = {VirtualMemoryAllocationType.PINNED: _t.CU_MEM_ALLOCATION_TYPE_PINNED} # noqa: RUF012 | ||
| if BUILD_CUDA_MAJOR >= 13: | ||
| _allocation_type[VirtualMemoryAllocationType.MANAGED] = _t.CU_MEM_ALLOCATION_TYPE_MANAGED | ||
|
|
||
| def __post_init__(self) -> None: | ||
| self._allocation_type_to_driver(self.allocation_type) | ||
| # Allocation and pickling each read the peers, so a one-shot iterable | ||
| # such as a generator must not reach them. | ||
| self.peers = tuple(int(peer) for peer in self.peers) | ||
|
|
@@ -490,6 +491,7 @@ cdef class VirtualMemoryResource(MemoryResource): | |
| Shared by ``__init__`` and ``modify_allocation``, so a per-call | ||
| configuration is held to the same rules as the resource's own. | ||
| """ | ||
| VirtualMemoryResourceOptions._allocation_type_to_driver(cfg.allocation_type) | ||
| if cfg.location_type != self.config.location_type: | ||
| raise ValueError( | ||
| f"config.location_type {str(cfg.location_type)!r} does not match the resource's " | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
important: Include strings in the handle type annotation. The documented and tested value
"win32_kmt"is accepted at runtime, but the annotation and generated stub reject it in type-checked code. Addstrto the union and regenerate the stub.As per coding guidelines, “The argument and return types as defined in the docstrings should match the type annotations.”
Source: Coding guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to add
win32_kmtto theVirtualMemoryHandleTypeenum?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analysis chain
Script executed:
Length of output: 1840
@mdboomsuggestion:VirtualMemoryHandleTypealready definesWIN32_KMT = "win32_kmt"incuda_core/cuda/core/typing.py, Line 156. PassingVirtualMemoryHandleType.WIN32_KMTsatisfies the current annotation.My concern applies only to passing the raw string
"win32_kmt", which the API documents and accepts at runtime. Adding an enum member does not make that string assignable to the enum type. If raw strings remain supported,VirtualMemoryHandleType | str | Nonewould make the annotation match that contract.Learnings used
You are interacting with an AI system.