NVIDIA CUBLAS Runtime Libraries
The `nvidia-cublas` package provides the native runtime libraries for NVIDIA's CUBLAS (CUDA Basic Linear Algebra Subroutines). It acts as a foundational dependency, allowing other Python deep learning and scientific computing frameworks (like PyTorch, TensorFlow, and CuPy) to leverage GPU-accelerated linear algebra operations efficiently. It is currently at version 13.3.0.5 and typically receives updates aligned with new NVIDIA CUDA Toolkit releases.
Warnings
- gotcha The `nvidia-cublas` package does not expose a direct Python API. Its primary function is to provide the underlying native CUBLAS shared libraries that other Python libraries (e.g., PyTorch, TensorFlow, CuPy) link against to perform GPU-accelerated linear algebra operations.
- gotcha CUBLAS versions must be compatible with your installed NVIDIA GPU drivers and the CUDA Toolkit version used by your deep learning framework. Mismatches can lead to runtime errors or performance issues.
- gotcha Installing `nvidia-cublas` via pip can conflict with existing system-wide or Conda-managed CUDA installations if `LD_LIBRARY_PATH` or other environment variables are not correctly managed, potentially leading to 'DLL not found' or 'CUDA driver' errors.
Install
-
pip install nvidia-cublas
Quickstart
import torch
def check_cublas_availability():
# Ensure PyTorch is installed and CUDA is available for CUBLAS to be used
try:
if not torch.cuda.is_available():
print("CUDA is not available. CUBLAS operations will run on CPU or not at all.")
return
print(f"CUDA is available. Device name: {torch.cuda.get_device_name(0)}")
print(f"Number of CUDA devices: {torch.cuda.device_count()}")
# Perform a simple matrix multiplication that typically uses CUBLAS
a = torch.randn(1000, 1000, device='cuda')
b = torch.randn(1000, 1000, device='cuda')
c = torch.matmul(a, b)
print("Successfully performed a GPU matrix multiplication (likely using CUBLAS).")
print(f"Result shape: {c.shape}")
except Exception as e:
print(f"An error occurred during CUDA operation: {e}")
print("This might indicate an issue with CUBLAS, CUDA installation, or drivers.")
if __name__ == "__main__":
check_cublas_availability()