mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-13 00:08:26 +08:00
CUDA 13.4 samples update - v13.4-public
Release 13.4 of the CUDA Samples supported by CUDA Toolkit 13.4. See Changelog for more information.
This commit is contained in:
@@ -30,8 +30,8 @@ round-trip test:
|
||||
- How cuda.core's pickle reducers rebuild the MR and map the buffer
|
||||
in the receiving process
|
||||
- Why `multiprocessing` must use the `"spawn"` start method with CUDA
|
||||
- Detecting IPC support at runtime (POSIX file-descriptor handle
|
||||
type, memory-pool support, Linux-only)
|
||||
- Detecting IPC support at runtime (memory-pool support and the
|
||||
POSIX file-descriptor handle type in the pool's handle mask)
|
||||
|
||||
## Key Libraries
|
||||
|
||||
@@ -48,7 +48,7 @@ round-trip test:
|
||||
- `mr.allocate(nbytes)` - allocate a `Buffer` from the IPC pool
|
||||
- `Buffer.is_mapped` - True when the buffer is usable in the current process
|
||||
- `Device.properties.memory_pools_supported` - runtime feature check
|
||||
- `Device.properties.handle_type_posix_file_descriptor_supported` - runtime feature check
|
||||
- `Device.properties.mempool_supported_handle_types` - runtime feature check
|
||||
|
||||
### From `cuda_samples_utils`
|
||||
|
||||
@@ -105,8 +105,8 @@ python ipcMemoryPool.py --elements 65536
|
||||
python ipcMemoryPool.py --device 1
|
||||
```
|
||||
|
||||
On platforms or devices that do not support CUDA IPC, the sample
|
||||
prints a diagnostic and exits cleanly with status 0.
|
||||
On platforms or devices that do not support CUDA IPC memory pools, the
|
||||
sample prints a diagnostic and exits with status 2.
|
||||
|
||||
## Expected Output
|
||||
|
||||
@@ -137,4 +137,4 @@ based on your system.
|
||||
- [CUDA Python Documentation](https://nvidia.github.io/cuda-python/)
|
||||
- [`cuda.core` memory API](https://nvidia.github.io/cuda-python/cuda-core/latest/api.html#memory)
|
||||
- Upstream `cuda.core` IPC tests: [`test_memory_ipc.py`](https://github.com/NVIDIA/cuda-python/blob/main/cuda_core/tests/memory_ipc/test_memory_ipc.py)
|
||||
- [CUDA IPC programming guide](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#interprocess-communication)
|
||||
- [CUDA IPC programming guide](https://docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/inter-process-communication.html#interprocess-communication)
|
||||
|
||||
@@ -47,13 +47,12 @@ The sample does a round-trip test:
|
||||
signals completion.
|
||||
5. Parent verifies the child's writes.
|
||||
|
||||
IPC requires Linux (POSIX file-descriptor handles) and device support for
|
||||
memory pools. On unsupported platforms the sample prints a diagnostic and
|
||||
exits cleanly.
|
||||
IPC here requires a device whose memory pools can be exported as POSIX
|
||||
file-descriptor handles, which in practice means Linux. Where that is
|
||||
unavailable the sample prints a diagnostic and exits with code 2.
|
||||
"""
|
||||
|
||||
import multiprocessing as mp
|
||||
import platform
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -62,6 +61,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent.parent / "Utilities"))
|
||||
try:
|
||||
import cupy as cp
|
||||
import numpy as np
|
||||
from cuda.bindings.driver import CUmemAllocationHandleType
|
||||
from cuda.core import (
|
||||
Device,
|
||||
DeviceMemoryResource,
|
||||
@@ -80,17 +80,17 @@ CHILD_TIMEOUT_SEC = 30
|
||||
|
||||
def check_ipc_support(device) -> bool:
|
||||
"""Return True if this device/platform supports CUDA IPC memory pools."""
|
||||
if platform.system() != "Linux":
|
||||
print(
|
||||
f"IPC via POSIX file descriptors is only supported on Linux "
|
||||
f"(detected {platform.system()})."
|
||||
)
|
||||
return False
|
||||
if not device.properties.memory_pools_supported:
|
||||
print("Device does not support CUDA memory pools.")
|
||||
return False
|
||||
if not device.properties.handle_type_posix_file_descriptor_supported:
|
||||
print("Device/platform does not support POSIX-fd IPC handles.")
|
||||
# handle_type_posix_file_descriptor_supported describes the virtual memory
|
||||
# management APIs, not memory pools. A device can report it while still
|
||||
# exporting no pool handle type at all, so query the pool-specific mask.
|
||||
if not (
|
||||
device.properties.mempool_supported_handle_types
|
||||
& int(CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR)
|
||||
):
|
||||
print("Device does not support POSIX-fd IPC handles for memory pools.")
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -153,8 +153,8 @@ def main() -> int:
|
||||
print_gpu_info(device)
|
||||
|
||||
if not check_ipc_support(device):
|
||||
print("\nCUDA IPC is not available on this system; exiting cleanly.")
|
||||
return 0
|
||||
print("\nCUDA IPC memory pools are not supported on this platform.")
|
||||
return 2
|
||||
|
||||
N = args.elements
|
||||
nbytes = N * np.dtype(np.float32).itemsize
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
numpy>=2.3.2
|
||||
cuda-python>=13.0.0
|
||||
cuda-core>=1.0.0
|
||||
cuda-core>=1.2.0
|
||||
|
||||
@@ -157,6 +157,15 @@ def run(num_elements=1024 * 1024 * 16):
|
||||
f"GPU{gpuid[0]}, GPU{gpuid[1]} and CPU Host)..."
|
||||
)
|
||||
|
||||
# DeviceMemoryResource is backed by a device memory pool, which is not
|
||||
# available on every device.
|
||||
if not (
|
||||
dev0.properties.memory_pools_supported
|
||||
and dev1.properties.memory_pools_supported
|
||||
):
|
||||
print("\nDevice memory pools are not supported on this platform.")
|
||||
return 2
|
||||
|
||||
# Allocate on GPU 0 and grant access to GPU 1
|
||||
dev0.set_current()
|
||||
mr0 = DeviceMemoryResource(dev0)
|
||||
@@ -176,6 +185,14 @@ def run(num_elements=1024 * 1024 * 16):
|
||||
)
|
||||
|
||||
# Allocate pinned host memory
|
||||
# PinnedMemoryResource is backed by a host memory pool, which is not
|
||||
# available on every device.
|
||||
if not (
|
||||
dev0.properties.host_memory_pools_supported
|
||||
and dev1.properties.host_memory_pools_supported
|
||||
):
|
||||
print("\nHost pinned memory pools are not supported on this platform.")
|
||||
return 2
|
||||
pinned_mr = PinnedMemoryResource()
|
||||
h0 = pinned_mr.allocate(buf_size, stream=dev0.default_stream)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user