Registry / ai-ml / cuda-core

cuda-core

JSON →
library1.1.1pypypi✓ verified 28d ago

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-core
INSTALL
IMPORT
SIG · CUDA-CORE
C
cuda-core
ai-mlpythonv1.1.1
Install
4.4s avg
Import
—
Disk
111MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
build_error
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 4.4s · import 0.000s · 102MB
111MB installed
● package 111MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cuda
✓ import cuda
✗ import cuda.core as drv

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.

import cuda.core as drv import numpy as np try: # Initialize the CUDA driver API drv.init() # Get device count device_count = drv.cuDeviceGetCount() if device_count == 0: print("No CUDA devices found. Ensure GPU drivers and CUDA Toolkit are installed.") else: print(f"Found {device_count} CUDA device(s).") # Get the first device and create a context device = drv.cuDeviceGet(0) # Flags: 0 for default context creation context = drv.cuCtxCreate(0, device) print(f"Created CUDA context on device 0: {device}") # Prepare host data host_data = np.arange(10, dtype=np.int32) print(f"Host data: {host_data}") # Allocate memory on the device device_ptr = drv.cuMemAlloc(host_data.nbytes) print(f"Allocated {host_data.nbytes} bytes on device at address: {device_ptr}") # Copy host data to device drv.cuMemcpyHtoD(device_ptr, host_data.ctypes.data, host_data.nbytes) print("Copied host data to device.") # Example: Copy device data back to host (optional, for verification) retrieved_data = np.empty_like(host_data) drv.cuMemcpyDtoH(retrieved_data.ctypes.data, device_ptr, retrieved_data.nbytes) print(f"Retrieved data from device: {retrieved_data}") # Clean up: Free device memory and destroy context drv.cuMemFree(device_ptr) drv.cuCtxDestroy(context) print("Successfully freed device memory and destroyed context.") except drv.CUException as e: print(f"CUDA Error: {e}. This often indicates issues with CUDA Toolkit installation, drivers, or device availability.") print("Please ensure you have a compatible NVIDIA GPU, up-to-date drivers, and a correctly installed CUDA Toolkit.") except Exception as e: print(f"An unexpected Python error occurred: {e}")
Debug
Known issues
breakingThe `cuda-core` library provides bindings to the CUDA Driver API and *requires a compatible NVIDIA CUDA Toolkit to be installed on the system* (including drivers, runtime, and developer headers). It is not a standalone Python package that ships with CUDA itself.
fix
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.
affects: All
gotchaAs a low-level Driver API, `cuda-core` necessitates explicit memory management. Users must manually allocate and deallocate GPU memory using functions like `drv.cuMemAlloc` and `drv.cuMemFree`. Failing to free allocated memory can lead to GPU memory leaks and resource exhaustion.
fix
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.
affects: All
gotcha`cuda.core` binds directly to the CUDA Driver API, which is lower-level than the CUDA Runtime API (often used implicitly by `nvcc` and libraries like `cuda.cudart`). It doesn't provide high-level abstractions like automatic memory management, unified memory, or stream synchronization helpers out-of-the-box.
fix
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.
affects: All
gotchaMismatches between the `cuda-core` Python package version, the system's installed CUDA Toolkit version, and the NVIDIA GPU driver version can lead to `drv.CUException` errors (e.g., `CUDA_ERROR_NOT_INITIALIZED`, `CUDA_ERROR_NO_DEVICE`, `CUDA_ERROR_INVALID_DEVICE`).
fix
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.
affects: All
Upgrade
Version history
1.1.1latest on PyPI · released Jul 29, 2026
Audit
Dependencies
numpyoptionalRequired for the quickstart code example (data generation for device memory transfer).
Agent activity
31 hits · last 30 days
node
26
Amazon
1
OpenAI (training)
1
Resources
cuda-core — pip install cuda-core · libregistry