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.
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.
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.")