The `cuda-core` library provides low-level Pythonic bindings to the NVIDIA CUDA Driver API. It enables direct interaction with NVIDIA GPUs for tasks like device querying, memory management, context creation, and kernel launches. As part of the broader `cuda-python` project, it is currently at version 0.7.0 and often sees updates aligned with new CUDA Toolkit releases.
pip install cuda-coreVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes the CUDA driver, queries available devices, creates a CUDA context, allocates memory on the GPU, copies data from host to device, and then cleans up resources. It also includes basic error handling for common CUDA issues.
Before installing `cuda-core`, ensure you have a compatible NVIDIA GPU and have installed the appropriate NVIDIA GPU drivers and CUDA Toolkit from NVIDIA's developer website. The `cuda-python` project's documentation often provides compatibility matrices.
Always pair `drv.cuMemAlloc` (or `cuMemAllocManaged`) with a corresponding `drv.cuMemFree`. Utilize `try...finally` blocks for robust resource cleanup, especially when handling contexts and memory pointers.
Understand the distinction between the Driver API (`cuda.core`) and the Runtime API (`cuda.cudart`). For higher-level abstractions, consider using `cuda.cudart` or other libraries built on CUDA, such as CuPy, PyTorch, or TensorFlow, which handle much of the low-level complexity for you.
Consult the `cuda-python` project documentation and NVIDIA's compatibility tables to ensure all components (GPU driver, CUDA Toolkit, and `cuda-core` package) are compatible with each other and your hardware. Often, updating drivers or using a specific CUDA Toolkit version can resolve these issues.