mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-11-17 17:38:18 +08:00
Sync v13.5-public from internal repo
This commit is contained in:
@@ -95,9 +95,9 @@ def check_ipc_support(device) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def child_worker(q_in, q_out, n_elements, parent_seed, child_seed):
|
||||
def child_worker(q_in, q_out, n_elements, parent_seed, child_seed, device_id):
|
||||
"""Runs in a separate process. Verifies and modifies the shared buffer."""
|
||||
device = Device(0)
|
||||
device = Device(device_id)
|
||||
device.set_current()
|
||||
pid = mp.current_process().pid
|
||||
|
||||
@@ -188,7 +188,7 @@ def main() -> int:
|
||||
q_from_child = mp.Queue()
|
||||
child = mp.Process(
|
||||
target=child_worker,
|
||||
args=(q_to_child, q_from_child, N, parent_seed, child_seed),
|
||||
args=(q_to_child, q_from_child, N, parent_seed, child_seed, args.device),
|
||||
)
|
||||
child.start()
|
||||
q_to_child.put(buffer)
|
||||
|
||||
@@ -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