CUDA Pathfinder

1.5.0 · active · verified Sun Mar 29

cuda-pathfinder is a Python library from NVIDIA that provides utilities for locating CUDA components, such as dynamic libraries (.so, .dll) and CUDA Toolkit (CTK) header directories. It aims to be a one-stop solution for discovering CUDA artifacts within a Python environment. It is currently at version 1.5.0 and is part of the broader NVIDIA CUDA Python ecosystem, undergoing active development with regular releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `cuda-pathfinder` to locate and load an NVIDIA dynamic library, such as the CUDA Runtime library (`cudart`). It highlights the primary use case of finding system-level CUDA components within a Python environment. The example includes error handling for when the library is not found.

from cuda.pathfinder import load_nvidia_dynamic_lib, DynamicLibNotFoundError
import os

try:
    # Locate and load the CUDA Runtime dynamic library (e.g., cudart.so, cudart.dll)
    cudart_lib = load_nvidia_dynamic_lib('cudart')
    print(f"Successfully loaded CUDA Runtime library: {cudart_lib.path}")

    # Example: Accessing its handle (but don't close it!)
    # The handle is a low-level OS object, specific usage depends on further operations
    # For instance, if you were to interact with a CFFI interface.
    print(f"Library handle (platform specific): {cudart_lib.handle_uint}")

    # You can also find other components like header directories
    # For this example, we're not using os.environ.get as it's not directly for auth.
    # No direct quickstart for header directory loading that requires external auth.
    # This part is illustrative of another feature.
    # try:
    #     cuda_headers = find_nvidia_header_directory()
    #     print(f"CUDA header directory found at: {cuda_headers.path}")
    # except Exception as e:
    #     print(f"Could not find CUDA header directory: {e}")

except DynamicLibNotFoundError:
    print("CUDA Runtime library 'cudart' not found. Ensure CUDA Toolkit is installed and accessible.")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →