Skip to content

Cubin producer API

tensoracle.producer wraps the C++ producer in tensoracle/cubin.h and tensoracle/cubin.hpp. It compiles caller-owned CUDA C++ source into sm86, sm89, and sm120 cubins, bundle.json, and bundle.cpp. Install tensoracle[producer] for NVRTC and the PyPI CUDA tools; neither a GPU nor an OS-installed CUDA Toolkit is required. Triton kernels are not accepted.

The extra declares nvidia-cuda-nvrtc, nvidia-cuda-nvcc, nvidia-cuda-cuobjdump, nvidia-cuda-crt, and nvidia-nvvm in the 13.2 series. Within the Python environment's nvidia/cu13 directory, compile_bundle uses these platform-specific paths:

Tool Linux x86_64 Windows x86_64
NVRTC lib/libnvrtc.so.13 bin/x86_64/nvrtc64_130_0.dll
ptxas bin/ptxas bin/ptxas.exe
cuobjdump bin/cuobjdump bin/cuobjdump.exe

cuda_root selects another CUDA package root; nvrtc, ptxas, and cuobjdump independently override individual paths. The producer does not use CUDA_HOME. Missing tools report the package and searched path. ptxas outside >=13.2,<14 is rejected before output files are written.

Describe a CUDA C++ kernel

Each KernelSpec supplies CUDA C++ source, an extern "C" entry symbol, ordered public argument names and types, and integer compile constants. The source uses those constants as compile-time definitions. The following kernel and argument layout follow the producer test fixture in python/tests/test_producer.py:

from pathlib import Path
from tensoracle.producer import KernelSpec, compile_bundle

source = '''extern "C" __global__ void copy_kernel(const float* x, float* y, int n) {
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    if (i < n) y[i] = x[i] * FACTOR;
}'''
spec = KernelSpec(
    name="copy",
    source=source,
    signature=(("x", "*fp32"), ("y", "*fp32"), ("n", "i32")),
    constexprs={"FACTOR": 2},
    entry_symbol="copy_kernel",
)
manifest = compile_bundle((spec,), Path("bundle"))

divisible_by adds argument specialization constraints when needed, and dynamic_shared_memory_bytes declares dynamic shared memory. The producer verifies the compiled entry's public parameter count, order, and types. CUDA C++ kernels have no hidden trailing parameters or Triton scratch arguments. The manifest uses schema version 2 and records NVRTC and ptxas versions, source digests, architecture, resource use, and parameter ABI.

Use bundle inspection before distributing a plugin, and the CMake helper to build it from the generated bundle. Generation alone does not establish a kernel's numerical correctness, supported shapes, or runtime performance.

KernelSpec dataclass

CUDA C++ source, an extern C entry, ordered arguments, and compile constants.

name instance-attribute

source instance-attribute

signature instance-attribute

constexprs instance-attribute

entry_symbol instance-attribute

divisible_by = field(default_factory=dict) class-attribute instance-attribute

dynamic_shared_memory_bytes = 0 class-attribute instance-attribute

__init__(name, source, signature, constexprs, entry_symbol, divisible_by=dict(), dynamic_shared_memory_bytes=0)

compile_bundle(specs, output, *, ptxas=None, cuobjdump=None, nvrtc=None, cuda_root=None)

Build sm86, sm89, and sm120 cubins without a GPU or OS CUDA Toolkit.

The C++ implementation validates ptxas >=13.2,<14 before writing output. Omitted tools come from the nvidia/cu13 directory in the Python environment.