mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-11-17 17:38:18 +08:00
Post v13.5 (#470)
This commit is contained in:
@@ -6,7 +6,7 @@ This sample demonstrates peer-to-peer (P2P) memory access between multiple GPUs
|
||||
|
||||
## What you will learn
|
||||
|
||||
- How to detect multiple CUDA-capable GPUs using `system.get_num_devices()` and `Device(id)`
|
||||
- How to detect multiple CUDA-capable GPUs using `Device.get_all_devices()`
|
||||
- How to check P2P capability between GPU pairs using `device.can_access_peer()`
|
||||
- How to enable and disable peer access using `DeviceMemoryResource.peer_accessible_by`
|
||||
- How to allocate device memory on specific GPUs using `DeviceMemoryResource`
|
||||
@@ -26,9 +26,7 @@ This sample demonstrates peer-to-peer (P2P) memory access between multiple GPUs
|
||||
## Key APIs
|
||||
|
||||
**From cuda.core:**
|
||||
- `system` – Pre-instantiated singleton for system-level CUDA information
|
||||
- `system.get_num_devices()` – Get number of CUDA-capable devices
|
||||
- `Device(id)` – Get specific CUDA device handle
|
||||
- `Device.get_all_devices()` – Get handles for all CUDA-visible devices
|
||||
- `device.can_access_peer(peer)` – Check if this device can access peer device memory
|
||||
- `device.set_current()` – Set active device for subsequent operations
|
||||
- `device.create_stream()` – Create CUDA stream for kernel execution
|
||||
@@ -94,7 +92,7 @@ pip install -r requirements.txt
|
||||
|
||||
Or manually:
|
||||
```bash
|
||||
pip install numpy>=2.3.2 cuda-core>=1.0.0 cuda-python>=13.0.0
|
||||
pip install numpy>=2.3.2 cuda-core>=1.2.0 cuda-python>=13.0.0
|
||||
```
|
||||
|
||||
## How to run
|
||||
|
||||
@@ -39,7 +39,6 @@ try:
|
||||
Program,
|
||||
ProgramOptions,
|
||||
launch,
|
||||
system,
|
||||
)
|
||||
except ImportError as e:
|
||||
print(f"Error: Required package not found: {e}")
|
||||
@@ -91,7 +90,8 @@ def run(num_elements=1024 * 1024 * 16):
|
||||
|
||||
# Check for multiple GPUs
|
||||
print("\nChecking for multiple GPUs...")
|
||||
num_devices = system.get_num_devices()
|
||||
devices = Device.get_all_devices()
|
||||
num_devices = len(devices)
|
||||
print(f"CUDA-capable device count: {num_devices}")
|
||||
|
||||
if num_devices < 2:
|
||||
@@ -101,9 +101,6 @@ def run(num_elements=1024 * 1024 * 16):
|
||||
)
|
||||
return 2
|
||||
|
||||
# Get device properties
|
||||
devices = [Device(i) for i in range(num_devices)]
|
||||
|
||||
# Check for P2P capability
|
||||
print("\nChecking GPU(s) for support of peer to peer memory access...")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user