NVIDIA CUDA NVRTC for CUDA 12.x
NVRTC (NVIDIA Runtime Compiler) is a library designed for runtime compilation of CUDA C++ source code into PTX (Parallel Thread Execution) assembly. This Python package, `nvidia-cuda-nvrtc-cu12`, provides the native runtime libraries (DLLs/SOs) for CUDA 12.x, enabling dynamic code generation and execution on NVIDIA GPUs. It's a fundamental component of the CUDA Toolkit, actively maintained by NVIDIA, and crucial for other Python libraries that leverage JIT CUDA compilation.
Warnings
- breaking CUDA Python wheels, including `nvidia-cuda-nvrtc-cu12`, require a compatible NVIDIA GPU driver installed on the system. Mismatched driver versions (e.g., an older driver with a newer CUDA toolkit version or vice-versa) can lead to runtime errors or GPU features being unavailable.
- gotcha This package is intended for 'runtime use' and provides native shared libraries (like `.dll` or `.so` files). It *does not* include developer tools, headers, or the `nvcc` compiler itself. For full CUDA development workflows, the complete NVIDIA CUDA Toolkit must be installed separately.
- gotcha The `nvidia-cuda-nvrtc-cu12` package does not expose a direct Python API or symbols for import by end-user Python code. Its primary role is to provide the native NVRTC libraries that other Python packages (e.g., PyTorch, CuPy, JAX) link against and use internally for Just-In-Time (JIT) compilation of CUDA C++ kernels.
- gotcha Security analyses of `nvidia-cuda-nvrtc-cu12` have occasionally flagged 'reduced effectiveness mitigations' for vulnerabilities when statically linked libraries from different toolchain versions are combined. This can impact the integrity of control flow protection mechanisms.
Install
-
pip install nvidia-cuda-nvrtc-cu12
Quickstart
import os
# This package primarily provides native runtime libraries (DLLs/SOs)
# for CUDA's NVRTC component, which are consumed by other higher-level
# CUDA-enabled Python libraries (e.g., PyTorch, CuPy) for JIT compilation.
# There is no direct Python API exposed by this specific package for end-user import.
# The following code demonstrates verifying CUDA's availability, which implicitly
# relies on the correctly installed underlying CUDA runtime components like NVRTC.
try:
import torch
print(f"PyTorch CUDA available: {torch.cuda.is_available()}")
if torch.cuda.is_available():
print(f"PyTorch CUDA version: {torch.version.cuda}")
print(f"Current CUDA device: {torch.cuda.get_device_name(0)}")
except ImportError:
print("PyTorch not installed. Cannot verify CUDA availability via PyTorch.")
try:
import cupy
print(f"CuPy CUDA available: {cupy.cuda.is_available()}")
if cupy.cuda.is_available():
print(f"CuPy CUDA version: {cupy.cuda.runtime.get_version()}")
print(f"Current CUDA device: {cupy.cuda.Device(0).name}")
except ImportError:
print("CuPy not installed. Cannot verify CUDA availability via CuPy.")
# A successful installation of nvidia-cuda-nvrtc-cu12 means these libraries
# are available for use by such frameworks.