Skip to main content

Generate Numba CUDA bindings from CUDA C++ declarations.

Project description

Numbast

Numbast generates Python bindings for CUDA C++ declarations so they can be used from Python in Numba CUDA kernels. It is intended for CUDA Python projects that need to expose existing C++ device APIs without hand-writing Numba typing, lowering, and shim code for every function or type.

Numbast works with ast_canopy, which parses CUDA C++ headers with Clang and serializes declaration metadata. The numbast package consumes those declarations and registers or emits Numba CUDA-compatible bindings.

What It Can Bind

Numbast supports a focused subset of CUDA C++ declarations:

  • Free functions, overload sets, and supported operator overloads.
  • Structs and classes, including constructors, public fields, methods, and conversion operators.
  • Enums exposed as Python IntEnum values with Numba-compatible typing.
  • Function templates and class templates where concrete specializations can be materialized for Numba CUDA.
  • External C++ type mappings when a signature mentions a type that should map to an already-known Numba type.

See the supported declarations page for the full support matrix and current limitations.

Binding Workflows

Numbast supports two complementary workflows.

Dynamic Binding Generation

Dynamic generation parses headers and registers bindings at runtime. Use it for experimentation, development, and environments where Numbast, ast_canopy, Clang tooling, and the CUDA headers are all available.

from ast_canopy import parse_declarations_from_source
from numba import cuda, types
from numba.core.datamodel.models import PrimitiveModel
from numbast import MemoryShimWriter, bind_cxx_function, bind_cxx_struct

decls = parse_declarations_from_source("demo.cuh", ["demo.cuh"], "sm_80")
shim_writer = MemoryShimWriter('#include "demo.cuh"')

MyType = bind_cxx_struct(shim_writer, decls.structs[0], types.Number, PrimitiveModel)
my_function = bind_cxx_function(shim_writer, decls.functions[0])


@cuda.jit(link=shim_writer.links())
def kernel(out):
    value = MyType(1.0)
    out[0] = my_function(value)

Static Binding Generation

Static generation writes a standalone Python module that can be packaged with a project. The generated module depends on Numba CUDA, but end users do not need Numbast or Clang tooling at runtime.

python -m numbast --cfg-path config.yml --output-dir ./generated

Installation

pip install numbast

Generating bindings requires a CUDA Toolkit and Clang tooling environment that can parse the target headers. Running generated bindings requires a compatible Numba CUDA runtime environment.

Documentation

Project Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numbast-0.9.0-py3-none-any.whl (148.4 kB view details)

Uploaded Python 3

File details

Details for the file numbast-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: numbast-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 148.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for numbast-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8768c5d5d1244cd3d3ba15db0cfc10ef18b11880fc9f1851c236bc147d48205
MD5 ebe8a789ed4cdde8dd00ba9f2c1317d1
BLAKE2b-256 f5943dcbbd42af3151cb6c52b05183046bdd161047d5ea9ab4cc221ed153854d

See more details on using hashes here.

Provenance

The following attestation bundles were made for numbast-0.9.0-py3-none-any.whl:

Publisher: publish.yaml on NVIDIA/numbast

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page