cuda

package module
v0.0.0-...-d56335e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Optional Go/CUDA KZG opening computer

This independent Go module implements Core's kzg.OpeningComputer. Go calls CUDA Driver and NVRTC through purego, on Linux/amd64 and Windows/amd64. NVRTC compiles CUDA C++ kernels at initialization. No Python, CuPy, CGO, NVCC build or host C++ compiler is required. Default Core, CPU verification and browser/WASM builds do not import this module.

It accelerates the quotient and G1 MSM for the exact KZG4096 profile. Core still hashes cells, constructs commitments, serializes proofs, and verifies full Prove results against the caller-selected commitment. Prepared Open consumers must verify each result before using or caching it, as with CPU.

The scheduling kernels use field/point arithmetic from ICICLE v2.8.0 (MIT), not ICICLE's MSM API. The external checkout is pinned to aacec3f72f14f53dd96d835698d2c87cde3a68b8; every compiled header has a checked SHA-256 in worker/headers.json. Headers must retain LF line endings. This is an optional implementation pending hardware correctness/performance qualification; historical evaluator GPU results do not validate this backend.

Windows 11 / Git Bash

Install Go using this module's go.mod version. An NVIDIA driver and the CUDA Toolkit's NVRTC library are required. If CUDA Toolkit 13.x is already installed with NVRTC, it need not be reinstalled. Check CUDA_PATH points to the Toolkit; its bin directory must also contain the matching NVRTC builtins DLL. A driver version reported by nvidia-smi alone does not establish that NVRTC is installed.

Run from this directory, not the workspace root:

bash scripts/prepare-icicle.sh
bash scripts/cuda-smoke.sh

If automatic NVRTC discovery fails, pass its full path, for example:

bash scripts/cuda-smoke.sh --nvrtc 'C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.3/bin/nvrtc64_130_0.dll'

Smoke compares device proofs byte-for-byte with CPU and checks CPU verification, different witnesses, indices 0/1/127/4095, all-zero/infinity behavior and wrong root rejection. A smoke pass establishes correctness for those cases, not an end-to-end latency SLO. Linux uses the same scripts; NVRTC discovery tries libnvrtc.so, .so.13, .so.12, or the explicit --nvrtc path.

Embedding

computer, err := cuda.New(cuda.Config{ICICLEInclude: include, Batch: 8, Streams: 4})
if err != nil { return err }
defer computer.Close()
scheme, err := kzg.NewSchemeWithOpeningComputer(computer)
// Inject scheme as the exact KZG4096 commitment backend in the composing host.

One computer can serve concurrent schemes and scopes. It owns one private CUDA context, resident fixed SRS table, multiple streams and reusable bounded buffers. BatchWait is optional (zero by default); MaxPending bounds its local pending buffer, in addition to its active batch. Service queue, deadlines, tenant quotas, CPU/GPU routing and retries belong to the host. Device failure rejects work; it never silently retries on CPU. Close releases pending callers and waits for active device operations before freeing buffers. CUDA calls cannot be safely interrupted by a Go context deadline.

The module requires an exact pushed Core API revision in go.mod. It does not depend on Gateway or the evaluator. The composing executable owns CUDA lifetime: stop requests, close the Gateway/runtime, then close the computer. CPU/GPU mixing must be an explicit host policy and must preserve the same Core profile.

Validation without a GPU

GOWORK=off go test ./...
GOWORK=off go vet ./...
CGO_ENABLED=0 GOWORK=off go build ./...

These run simulated-device scheduling/lifecycle tests and CPU encoding checks. Set MALT_CUDA_ICICLE_INCLUDE to additionally check the pinned source assembly. They do not execute a CUDA kernel; use the smoke command on an NVIDIA machine. With both that variable and MALT_CUDA_NVRTC_LIBRARY pointing at an NVRTC DLL/SO, go test -run TestNVRTCCompilation additionally compiles the real kernel for compute_86 through the Go FFI without requiring a GPU/driver.

Documentation

Overview

Package cuda implements an optional Go-controlled CUDA opening computer. CUDA Driver and NVRTC libraries are loaded by New; Python and CGO are not used.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("CUDA opening computer pending limit exceeded")
View Source
var ErrClosed = errors.New("CUDA opening computer is closed")

Functions

This section is empty.

Types

type Computer

type Computer struct {
	// contains filtered or unexported fields
}

Computer submits batches on one locked OS thread, retaining a device context, fixed SRS table and bounded workspace. Its owner must call Close.

func New

func New(cfg Config) (*Computer, error)

New compiles the pinned kernel with NVRTC and initializes the device. No installation or download occurs. Initialization can take several seconds.

func (*Computer) Close

func (c *Computer) Close() error

Close rejects new work, releases pending callers, and waits for in-flight CUDA work before freeing its context. Driver calls cannot be safely aborted by a Go deadline. Deadline and queue policy belong in the host executor.

func (*Computer) Open

func (c *Computer) Open(evaluations [][32]byte, index uint64) ([48]byte, error)

Open waits for device completion. A full pending buffer returns ErrBusy. Device errors fail closed; there is no implicit CPU retry.

type Config

type Config struct {
	ICICLEInclude string // Pinned ICICLE v2.8.0 icicle/include directory.
	NVRTCLibrary  string // Optional absolute NVRTC DLL/SO path.
	Device        int
	Batch         int           // Default 8; maximum 64.
	Streams       int           // Default min(4, Batch).
	MaxPending    int           // Default 64, in addition to the active device batch.
	BatchWait     time.Duration // Optional microbatch collection window; default 0.
}

Config controls device computation. Service admission belongs to the host.

Directories

Path Synopsis
cmd
cuda-smoke command
cuda-smoke checks actual device proofs against the independent CPU backend.
cuda-smoke checks actual device proofs against the independent CPU backend.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL