NVIDIA cuRAND

10.4.2.51 · active · verified Thu Apr 09

The `nvidia-curand` library provides the native CURAND shared libraries, making them discoverable via `pip` for Python packages that utilize GPU-accelerated random number generation. It is not intended for direct Python API calls but serves as a crucial dependency for libraries like CuPy and Numba. The current version is 10.4.2.51, and its releases are typically tied to updates of the NVIDIA CUDA Toolkit.

Warnings

Install

Imports

Quickstart

Demonstrates how CuPy, which relies on native libraries like those provided by `nvidia-curand`, can generate GPU-accelerated random numbers. This package ensures the underlying cuRAND shared objects are available for CuPy and similar libraries. A functional NVIDIA GPU and compatible drivers are required for this code to run successfully.

import cupy as cp
import os

# This quickstart demonstrates how CuPy, which uses cuRAND (provided by nvidia-curand),
# generates random numbers on the GPU. Ensure an NVIDIA GPU and drivers are installed.

# Optional: Set CUDA_VISIBLE_DEVICES if you have multiple GPUs and want to specify one
# os.environ['CUDA_VISIBLE_DEVICES'] = '0'

try:
    # Generate 5 random floats on the GPU using CuPy
    gpu_random_numbers = cp.random.rand(5)
    print("GPU Random Numbers (CuPy using cuRAND):", gpu_random_numbers)

    # Verify the device
    print(f"Generated on device: {gpu_random_numbers.device}")

    # Perform a basic GPU calculation with another random array
    gpu_array_a = cp.array([10.0, 20.0, 30.0], dtype=cp.float32)
    gpu_array_b = cp.random.rand(3, dtype=cp.float32) # Uses cuRAND
    gpu_result = gpu_array_a * gpu_array_b

    print("GPU Array A:", gpu_array_a)
    print("GPU Array B (random):", gpu_array_b)
    print("GPU Result (A * B):", gpu_result)

except cp.cuda.runtime.CUDARuntimeError as e:
    print(f"CUDA Error encountered: {e}")
    print("Please ensure you have an NVIDIA GPU, compatible drivers, and CUDA toolkit installed.")
    print("Also, verify that CuPy is installed and configured correctly.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →