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:
@@ -23,7 +23,7 @@ Query and display detailed properties of all CUDA-capable devices in your system
|
||||
|
||||
- `Device.get_all_devices()` - Get tuple of all available Device instances
|
||||
- `Device(device_id)` - Get Device object for specific device ID
|
||||
- `system.get_driver_version()` - Query CUDA driver version
|
||||
- `system.get_user_mode_driver_version()` - Query CUDA driver version
|
||||
- `Device.set_current()` - Set the current device for API calls
|
||||
- `Device.properties` - Access comprehensive device properties
|
||||
- `Device.name` - Get device name string
|
||||
@@ -90,7 +90,7 @@ Query and display detailed properties of all CUDA-capable devices in your system
|
||||
- CUDA Toolkit 13.0 or newer (recommended; matches `cuda-python` 13.x)
|
||||
- Python 3.10 or newer
|
||||
- `cuda-python` package (>=13.0.0)
|
||||
- `cuda-core` package (>=1.0.0)
|
||||
- `cuda-core` package (>=1.2.0)
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -103,7 +103,7 @@ pip install -r requirements.txt
|
||||
|
||||
The requirements.txt installs:
|
||||
- `cuda-python` (>=13.0.0)
|
||||
- `cuda-core` (>=1.0.0)
|
||||
- `cuda-core` (>=1.2.0)
|
||||
|
||||
## How to Run
|
||||
|
||||
|
||||
@@ -87,7 +87,12 @@ def print_driver_info() -> None:
|
||||
"NVML bindings are not compatible with this driver; "
|
||||
"device info will be limited."
|
||||
)
|
||||
print(f"Current process: {system.get_process_name(os.getpid())}")
|
||||
try:
|
||||
# On WSL, NVML can only name a PID that already holds a CUDA
|
||||
# context, which this process doesn't have yet.
|
||||
print(f"Current process: {system.get_process_name(os.getpid())}")
|
||||
except system.NotFoundError as e:
|
||||
print(f"Current process: unavailable ({e})")
|
||||
|
||||
|
||||
def print_device_info(device: "system.Device") -> None:
|
||||
|
||||
@@ -147,14 +147,27 @@ def run_lifecycle(proc: checkpoint.Process, lock_timeout_ms: int) -> List[StepTi
|
||||
raise CheckpointUnsupportedError from exc
|
||||
timings.append(StepTiming("lock", ms, proc.state))
|
||||
|
||||
ms = _time_call(proc.checkpoint)
|
||||
timings.append(StepTiming("checkpoint", ms, proc.state))
|
||||
# Always unlock, even on failure, or the process stays permanently
|
||||
# "locked" and later cleanup calls deadlock against it. Keep the
|
||||
# original error primary if unlock() also fails.
|
||||
op_error: BaseException | None = None
|
||||
try:
|
||||
ms = _time_call(proc.checkpoint)
|
||||
timings.append(StepTiming("checkpoint", ms, proc.state))
|
||||
|
||||
ms = _time_call(proc.restore)
|
||||
timings.append(StepTiming("restore", ms, proc.state))
|
||||
ms = _time_call(proc.restore)
|
||||
timings.append(StepTiming("restore", ms, proc.state))
|
||||
except BaseException as exc:
|
||||
op_error = exc
|
||||
|
||||
ms = _time_call(proc.unlock)
|
||||
timings.append(StepTiming("unlock", ms, proc.state))
|
||||
try:
|
||||
ms = _time_call(proc.unlock)
|
||||
timings.append(StepTiming("unlock", ms, proc.state))
|
||||
except Exception:
|
||||
if op_error is None:
|
||||
raise
|
||||
if op_error is not None:
|
||||
raise op_error
|
||||
|
||||
return timings
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ This sample demonstrates how to add a custom GPU operation to PyTorch using the
|
||||
- cuda-python >= 13.0.0
|
||||
- cuda-core >=1.0.0
|
||||
|
||||
**PyTorch GPU compatibility:** Install a CUDA-enabled PyTorch build that supports your target GPU. GPU architecture support varies by platform and CUDA build. Check the [PyTorch CUDA Support Matrix](https://github.com/pytorch/pytorch/blob/main/RELEASE.md#pytorch-cuda-support-matrix) before installing PyTorch.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
|
||||
@@ -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