diff --git a/samples/cuda_core/multiGPUGradientAverage/multiGPUGradientAverage.py b/samples/cuda_core/multiGPUGradientAverage/multiGPUGradientAverage.py index 612ca80a2bf..2daba66bbae 100644 --- a/samples/cuda_core/multiGPUGradientAverage/multiGPUGradientAverage.py +++ b/samples/cuda_core/multiGPUGradientAverage/multiGPUGradientAverage.py @@ -77,7 +77,6 @@ Program, ProgramOptions, launch, - system, ) except ImportError as e: print(f"Error: Required package not found: {e}") @@ -103,7 +102,8 @@ def init_device(rank: int): tuple[Device, Stream] CUDA device object and stream object. """ - num_gpus = system.get_num_devices() + # CUDA's device count honors CUDA_VISIBLE_DEVICES; system.get_num_devices() counts every GPU NVML sees. + num_gpus = len(Device.get_all_devices()) if num_gpus == 0: raise RuntimeError("No CUDA devices available") diff --git a/samples/cuda_core/simpleMultiGpu/README.md b/samples/cuda_core/simpleMultiGpu/README.md index 2250d9e575d..b32d8fcc35d 100644 --- a/samples/cuda_core/simpleMultiGpu/README.md +++ b/samples/cuda_core/simpleMultiGpu/README.md @@ -33,7 +33,7 @@ input buffers, so the kernels see fully-materialized data. ### From `cuda.core` -- `system.get_num_devices()` - count of visible CUDA devices +- `Device.get_all_devices()` - the CUDA devices visible to this process - `Device(device_id)` / `Device.set_current()` - select and activate a device - `Device.create_stream()` - create a `cuda.core` stream on the current device - `Device.create_stream(adaptor)` - wrap a foreign stream via the `__cuda_stream__` protocol diff --git a/samples/cuda_core/simpleMultiGpu/simpleMultiGpu.py b/samples/cuda_core/simpleMultiGpu/simpleMultiGpu.py index 490e8b76633..85e1859e296 100644 --- a/samples/cuda_core/simpleMultiGpu/simpleMultiGpu.py +++ b/samples/cuda_core/simpleMultiGpu/simpleMultiGpu.py @@ -55,7 +55,7 @@ try: import cupy as cp - from cuda.core import Device, LaunchConfig, Program, ProgramOptions, launch, system + from cuda.core import Device, LaunchConfig, Program, ProgramOptions, launch except ImportError as e: print(f"Error: Required package not found: {e}") print("Please install from requirements.txt:") @@ -117,7 +117,8 @@ def _compile(device, source): def main(): - num_devices = system.get_num_devices() + # CUDA's device count honors CUDA_VISIBLE_DEVICES; system.get_num_devices() counts every GPU NVML sees. + num_devices = len(Device.get_all_devices()) if num_devices < 2: print( f"This sample requires at least 2 CUDA-capable devices (found {num_devices}). Waiving.", diff --git a/samples/cuda_core/simpleP2P/README.md b/samples/cuda_core/simpleP2P/README.md index b12ddfc4dc5..3541df9dbb6 100644 --- a/samples/cuda_core/simpleP2P/README.md +++ b/samples/cuda_core/simpleP2P/README.md @@ -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()` and `Device(id)` - 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` @@ -27,7 +27,7 @@ This sample demonstrates peer-to-peer (P2P) memory access between multiple GPUs **From cuda.core:** - `system` – Pre-instantiated singleton for system-level CUDA information -- `system.get_num_devices()` – Get number of CUDA-capable devices +- `Device.get_all_devices()` – Get the CUDA devices visible to this process - `Device(id)` – Get specific CUDA device handle - `device.can_access_peer(peer)` – Check if this device can access peer device memory - `device.set_current()` – Set active device for subsequent operations diff --git a/samples/cuda_core/simpleP2P/simpleP2P.py b/samples/cuda_core/simpleP2P/simpleP2P.py index d2406487fa5..c0f5678d856 100644 --- a/samples/cuda_core/simpleP2P/simpleP2P.py +++ b/samples/cuda_core/simpleP2P/simpleP2P.py @@ -45,7 +45,6 @@ Program, ProgramOptions, launch, - system, ) except ImportError as e: print(f"Error: Required package not found: {e}") @@ -99,7 +98,8 @@ def run(num_elements=1024 * 1024 * 16): # Check for multiple GPUs print("\nChecking for multiple GPUs...") - num_devices = system.get_num_devices() + # CUDA's device count honors CUDA_VISIBLE_DEVICES; system.get_num_devices() counts every GPU NVML sees. + num_devices = len(Device.get_all_devices()) print(f"CUDA-capable device count: {num_devices}") if num_devices < 2: