NVIDIA cuBLAS Runtime Library (CUDA 12.x)
nvidia-cublas-cu12 provides the native runtime libraries for NVIDIA's CUBLAS (CUDA Basic Linear Algebra Subprograms) on CUDA 12.x enabled systems. It's a GPU-accelerated library designed for high-performance linear algebra operations crucial for AI, machine learning, and high-performance computing (HPC) applications. This Python package acts as a runtime dependency for other Python libraries that leverage cuBLAS functionalities, rather than exposing a direct Python API itself. The current version is 12.9.2.10, and it is actively maintained with frequent updates.
Common errors
-
cannot open shared object file: libcublas.so.12: No such file or directory
cause The system cannot find the 'libcublas.so.12' shared library, typically due to an incorrect 'LD_LIBRARY_PATH' environment variable, an incomplete CUDA Toolkit installation, or a version mismatch between the CUDA Toolkit and the consuming application.fixEnsure the NVIDIA CUDA Toolkit is correctly installed and its 'lib64' directory (e.g., '/usr/local/cuda-12.x/lib64') is included in the 'LD_LIBRARY_PATH' environment variable. For example: 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH'. -
RuntimeError: cuda error: cublas_status_not_initialized
cause The cuBLAS library failed to initialize, often due to incompatible CUDA driver/toolkit versions, insufficient GPU memory, or an unstable GPU environment.fixVerify that your CUDA driver and toolkit versions are compatible with your deep learning framework (e.g., PyTorch, TensorFlow). Update GPU drivers to the latest stable version, ensure sufficient GPU memory is available for the operation, and consider restarting your kernel or system. -
Distribution 'nvidia-cublas-cu12==X.Y.Z' can't be installed because it doesn't have a source distribution or wheel for the current platform
cause This error from pip or uv indicates an incompatibility between the requested 'nvidia-cublas-cu12' version (often a dependency of a deep learning framework like PyTorch) and the system's platform (OS, architecture, Python version) for which no pre-built wheel is available.fixEnsure your Python environment (OS, architecture, Python version) matches the available pre-built wheels for 'nvidia-cublas-cu12'. If installing PyTorch, use the specific installation command from the PyTorch website that matches your CUDA version and platform. For Docker environments, avoid Alpine-based images if PyTorch only provides 'glibc' wheels. -
Target "CUDA::cublas" links to target "CUDA::cublas" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
cause When building C/C++ projects with CMake that depend on cuBLAS, this error occurs because CMake cannot locate the 'CUDA::cublas' target. This typically happens if 'find_package(CUDAToolkit)' was not called, failed, or the CUDA Toolkit installation is incomplete or not properly configured for CMake discovery.fixIn your 'CMakeLists.txt', ensure you explicitly call 'find_package(CUDAToolkit REQUIRED)' (for CMake 3.17+). Verify that the CUDA Toolkit is correctly installed and discoverable; you might need to set environment variables like 'CUDA_PATH' or 'CUDAToolkit_ROOT' to help CMake find it. Also, ensure cuBLAS workspace is correctly configured to avoid allocation issues within graphs.
Warnings
- breaking Major version numbers (e.g., `cu12` vs. `cu11`) indicate compatibility with specific CUDA Toolkit versions. Mixing `nvidia-cublas-cu12` with libraries compiled for older CUDA versions (e.g., `cu11`) or an incompatible system CUDA toolkit can lead to runtime errors like 'undefined symbols' or 'failed to load shared library'.
- gotcha The `pip` wheels for `nvidia-cublas-cu12` are intended for runtime use and do not include developer tools (like `nvcc`) or header files necessary for compiling applications against cuBLAS. For development purposes (e.g., building custom CUDA extensions), a full NVIDIA CUDA Toolkit installation is typically required.
- gotcha When using cuBLAS functions within CUDA graphs in cuBLAS 12.x, not explicitly providing a workspace can lead to `cudaErrorNotSupported (801)` due to stream-ordered memory allocations. This is a change from older cuBLAS versions.
- gotcha Incorrect `LD_LIBRARY_PATH` or `CUDA_HOME` environment variables can prevent Python applications from finding the installed native cuBLAS shared libraries, resulting in 'cannot open shared object file' errors.
- gotcha Testing of CUDA-dependent functionality for `nvidia-cublas-cuXX` may be skipped or incomplete if required libraries like CuPy (e.g., `cupy-cuda12x`) are not installed.
- breaking The package `nvidia-cublas-cu12` (and similar `nvidia-*cuXX` packages) available on PyPI.org are often placeholder projects. These packages are primarily hosted on the NVIDIA Python Package Index.
Install
-
pip install nvidia-cublas-cu12
Imports
- libcublas
This package does not expose direct Python imports. It provides native shared libraries (e.g., libcublas.so, cublas.dll) that other Python libraries link against.
Quickstart
import os
# nvidia-cublas-cu12 itself does not have direct Python imports or a quickstart.
# Its purpose is to provide the underlying shared libraries for other Python packages.
# For example, nvmath-python can leverage it.
# To use a library that depends on nvidia-cublas-cu12, you'd typically install it like:
# pip install nvmath-python[cu12] cupy-cuda12x
# Example of how a dependent library (like nvmath-python or CuPy) *might*
# indicate the presence of cuBLAS. This code is conceptual, not direct use of this package.
# Replace with actual usage from a wrapper library if available and runnable.
try:
# Attempt to import a library that *uses* cuBLAS if installed
import cupy as cp
print(f"CuPy version: {cp.__version__}")
print(f"CuPy CUDA enabled: {cp.cuda.is_available()}")
if cp.cuda.is_available():
a = cp.random.rand(5, 5)
b = cp.random.rand(5, 5)
c = a @ b # This operation would internally use cuBLAS
print(f"CuPy matrix multiplication (via cuBLAS if linked) successful.\nResult shape: {c.shape}")
else:
print("CuPy is installed but CUDA is not available. Ensure drivers and CUDA runtime are correctly set up.")
except ImportError:
print("CuPy not installed. Install with `pip install cupy-cuda12x` to test CUDA functionality.")
except Exception as e:
print(f"An error occurred during CuPy test: {e}")
# The presence of `nvidia-cublas-cu12` itself can be verified at the system level.
# For direct validation of the package installation:
import pkg_resources
try:
distribution = pkg_resources.get_distribution('nvidia-cublas-cu12')
print(f"\nPackage 'nvidia-cublas-cu12' is installed. Version: {distribution.version}")
except pkg_resources.DistributionNotFound:
print("Package 'nvidia-cublas-cu12' not found. Please install it.")