Add optional CUDA-accelerated PLONK prover for BLS12-381 - #1792
Open
seunlanlege wants to merge 23 commits into
Open
Add optional CUDA-accelerated PLONK prover for BLS12-381#1792seunlanlege wants to merge 23 commits into
seunlanlege wants to merge 23 commits into
Conversation
…t numerator (icicle/CUDA)
…, test-only p2 toolkit
…ld, no hFolded upload)
…/commit on device handles)
…nt batchOpening, skip the wire download
…esident (skip their download)
… selector downloads
…/linearized poly evals
…checks, dev toggles)
…ly); lazy-init via SetDevice
…nings structural miss
GPU PLONK prover: device-resident rho-loop (icicle/CUDA)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds an optional, GPU-accelerated PLONK prover for the BLS12-381 backend, gated entirely behind a
cudabuild tag. When gnark is built normally (without-tags cuda), behavior is unchanged: the CPU prover is the only code path compiled in, and there is no new runtime dependency. When built with-tags cuda, the PLONK prover for BLS12-381 runs a device-resident proving pipeline on an NVIDIA GPU via cgo, backed by open-icicle.The design goal is a fully device-resident prover: the witness, wires, canonical trace, and opening polynomials stay on the GPU across the entire proof, so host↔device transfers are minimized rather than round-tripping per NTT/MSM.
Build model & CPU-path safety
prove_gpu.go(//go:build cuda) carries the real device-resident prover;prove_nogpu.go(//go:build !cuda) provides no-op placeholders so the package builds identically without the tag.cudabuild is strict GPU-or-die: device errorspanicrather than silently falling back to CPU, so a misconfigured GPU can never produce a proof via an unintended path.What runs on-device (cuda build)
Supporting optimizations: the circuit-fixed trace and canonical
Qkare cached on the proving key and cloned per-proof (pooled/recycled); SRS point-conversion and NTT warmup are overlapped with the CPU witness solve.New code layout
backend/plonk/bls12-381/prove_gpu.go//go:build cuda)backend/plonk/bls12-381/prove_nogpu.go//go:build !cuda)backend/plonk/bls12-381/prove_resident_openings.gobackend/plonk/bls12-381/prove_resident_wire.gobackend/plonk/bls12-381/prove.go,setup.gointernal/gpu/bls12381/gpu.golibgnark_cuda+ icicleinternal/gpu/bls12381/{resident,plonk}.gointernal/gpu/bls12381/p2/Dependencies (for maintainer discussion)
The
cudabuild links againstlibgnark_cuda,icicle_field_bls12_381,icicle_curve_bls12_381,icicle_device, andcudart; paths are supplied viaCGO_CFLAGS/CGO_LDFLAGSat build time (documented ingpu.go). These are only required when building with the tag.go.sumcurrently references apolytope-labs/gnark-cryptofork (v0.19.3-0.20260627...). This is the main item to resolve before merge — we'd like to land the requiredgnark-cryptochanges upstream first so this PR can build against stockgnark-cryptowith no fork/replace. Happy to open that companion PR; guidance on how you'd prefer to structure it is welcome.Scope & limitations
prove_reuse_test.goandinternal/gpu/bls12381/p2/grandproduct_test.go; CI without a CUDA device continues to build and test the CPU path only.Note
High Risk
Large new proving surface on the critical proof-generation path; CUDA builds panic on GPU failure and omit full GPU support for statistical ZK, so correctness and ops risk are high despite CPU-only builds being isolated by build tags.
Overview
Adds an optional PLONK prover for BLS12-381 behind the
cudabuild tag: a device-resident pipeline (prove_gpu.go,internal/gpu/bls12381,p2/) that keeps wires, quotient work, and much of KZG on-GPU, withprove_nogpu.gostubs so default builds stay pure-Go and unchanged.Shared prover changes (
prove.go,setup.go): hooks try GPU helpers first where compiled; Setup caches circuit-fixedtrace, canonicalQk, and async.Poolof trace clones (clone/cloneInto);prewarmGPUoverlaps SRS/NTT prep with witness solve;defer freeGPUContextand pool return after prove; parallelbatchInvertfor large domains;TestProvingKeyTraceReuseguards trace aliasing across repeated proves.CUDA-only behavior: strict GPU-or-die (
gpuFatalpanics, no silent CPU fallback); resident quotient rho-loop, on-device divide/commit for H, grand-product Z, async LRO MSMs, and resident batch openings; statistical ZK disables the full resident GPU quotient/openings path.Reviewed by Cursor Bugbot for commit 5be470e. Bugbot is set up for automated code reviews on this repo. Configure here.