{"id":1592,"library":"nvidia-curand","title":"NVIDIA cuRAND","description":"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.","status":"active","version":"10.4.2.51","language":"en","source_language":"en","source_url":"https://github.com/NVIDIA/cuda-python","tags":["NVIDIA","CUDA","GPU","random numbers","native library","cuRAND"],"install":[{"cmd":"pip install nvidia-curand","lang":"bash","label":"Install `nvidia-curand`"}],"dependencies":[{"reason":"Provides core CUDA runtime libraries, which `nvidia-curand` depends on.","package":"nvidia-cuda-runtime","optional":false}],"imports":[{"note":"It provides underlying native cuRAND libraries that other Python libraries (e.g., CuPy, Numba) link against to enable GPU-accelerated random number generation. You interact with cuRAND indirectly through these higher-level wrappers.","symbol":"None (native library)","correct":"This package is not typically imported directly for Python symbols."}],"quickstart":{"code":"import cupy as cp\nimport os\n\n# This quickstart demonstrates how CuPy, which uses cuRAND (provided by nvidia-curand),\n# generates random numbers on the GPU. Ensure an NVIDIA GPU and drivers are installed.\n\n# Optional: Set CUDA_VISIBLE_DEVICES if you have multiple GPUs and want to specify one\n# os.environ['CUDA_VISIBLE_DEVICES'] = '0'\n\ntry:\n    # Generate 5 random floats on the GPU using CuPy\n    gpu_random_numbers = cp.random.rand(5)\n    print(\"GPU Random Numbers (CuPy using cuRAND):\", gpu_random_numbers)\n\n    # Verify the device\n    print(f\"Generated on device: {gpu_random_numbers.device}\")\n\n    # Perform a basic GPU calculation with another random array\n    gpu_array_a = cp.array([10.0, 20.0, 30.0], dtype=cp.float32)\n    gpu_array_b = cp.random.rand(3, dtype=cp.float32) # Uses cuRAND\n    gpu_result = gpu_array_a * gpu_array_b\n\n    print(\"GPU Array A:\", gpu_array_a)\n    print(\"GPU Array B (random):\", gpu_array_b)\n    print(\"GPU Result (A * B):\", gpu_result)\n\nexcept cp.cuda.runtime.CUDARuntimeError as e:\n    print(f\"CUDA Error encountered: {e}\")\n    print(\"Please ensure you have an NVIDIA GPU, compatible drivers, and CUDA toolkit installed.\")\n    print(\"Also, verify that CuPy is installed and configured correctly.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Use a Python wrapper library like CuPy (`import cupy as cp`) or Numba for GPU-accelerated random number generation. Ensure these wrappers are compatible with the `nvidia-curand` version you have installed.","message":"The `nvidia-curand` package primarily provides native shared libraries and is not designed for direct Python API calls or symbol imports. Python users typically interact with cuRAND through higher-level libraries like CuPy or Numba.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the appropriate NVIDIA GPU drivers for your hardware. Ensure your system meets the minimum requirements for the CUDA Toolkit version associated with `nvidia-curand`.","message":"`nvidia-curand` requires an NVIDIA GPU and compatible NVIDIA drivers to be installed on your system. Without these, the native libraries cannot be utilized, leading to runtime errors in dependent packages.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always ensure that the `nvidia-curand` package, your system's CUDA Toolkit, GPU drivers, and any dependent Python libraries (like CuPy) are compatible. Refer to NVIDIA's documentation for specific version compatibility matrices.","message":"Incompatibility between the installed `nvidia-curand` version, your system's CUDA Toolkit, and your GPU drivers can lead to runtime failures (`CUDARuntimeError`). Versioning is critical for NVIDIA's CUDA ecosystem.","severity":"breaking","affected_versions":"All versions"},{"fix":"For most standard installations, `pip` manages paths automatically. If you encounter library not found errors, check your `LD_LIBRARY_PATH` (Linux) or `PATH` (Windows) and ensure it includes the directory where the `nvidia-curand` shared libraries are installed (usually within your Python environment's `site-packages/nvidia/curand/lib`).","message":"While `pip install nvidia-curand` makes the native libraries available, you might still need to configure environment variables (e.g., `LD_LIBRARY_PATH` on Linux) in certain complex setups or if other CUDA installations interfere, to ensure dependent libraries find the correct `cuRAND` shared objects.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}