Rust Fil proofs SUPRASEAL_C2 optimization
This sub-session achieved a comprehensive understanding and documentation of the SUPRASEAL_C2 Groth16 proof generation pipeline for Filecoin PoRep, identifying its ~200 GiB peak memory footprint and its root causes. The work produced a detailed background reference document mapping the entire call chain from Curio's Go task layer through Rust FFI into C++/CUDA kernels, with memory accounting and nine structural bottlenecks. Additionally, three composable optimization proposals were developed: Sequential Partition Synthesis to reduce peak memory by streaming partitions sequentially, Persistent Prover Daemon to eliminate SRS loading overhead, and Cross-Sector Batching to improve throughput by batching multiple sectors' circuits. A final round of micro-optimization analysis examined CPU synthesis hotpaths, GPU NTT/MSM characteristics, H-to-D transfer patterns, and the feasibility of recomputing a/b/c vectors on-the-fly. The overarching achievement is a shift from optimizing individual proof generation toward architecting a continuous, memory-efficient proving pipeline optimized for heterogeneous cloud rental markets.
The cuzk Proving Engine: A 37-Segment Journey Through the Architecture of SNARK Optimization
Segments
- Deep-dive investigation into SUPRASEAL_C2 Groth16 proof generation pipeline for Filecoin PoRep, mapping the full call chain from Curio to CUDA kernels, accounting for ~200 GiB peak memory, and producing four documents including a background reference with nine bottlenecks and three optimization proposals to reduce memory, eliminate SRS loading overhead, and improve throughput, along with micro-optimization analysis of CPU and GPU hotpaths.Map call chain from Curio to supraseal-c2 with memory accounting, Analyze Curio orchestration and circuit value distribution, Characterize computational hotpaths at instruction level, Document pipeline architecture with nine bottlenecks, Propose Sequential Partition Synthesis for memory reduction, Propose Persistent Prover Daemon to eliminate SRS loading overhead, Propose Cross-Sector Batching for throughput improvement, Conduct micro-optimization analysis of CPU and GPU compute patterns, Evaluate recomputing a/b/c vectors on-the-fly
- This sub-session achieved a deep, compute-level investigation of the entire C2 proof generation pipeline, identifying 18 specific micro-optimizations across GPU kernels, CPU synthesis, and memory transfers, documented in c2-optimization-proposal-4.md, and initiated exploration of exploiting constraint structure for precomputation.Deep analysis of GPU kernel internals (NTT, MSM, batch addition), Analysis of CPU synthesis hotpath in bellperson, Analysis of host-to-device transfer patterns, Identification and documentation of 18 compute optimization opportunities, Writing c2-optimization-proposal-4.md with implementation roadmap, Investigation of constraint structure exploitation for precomputation
- Investigated exploitation of known constraint shapes (SHA-256 dominance, boolean witnesses) for C2 proof generation, designing Proposal 5 with Pre-Compiled Constraint Evaluator, specialized MatVec, and pre-computed split MSM topology, and synthesized a total impact assessment across all five proposals with implementation roadmap.Investigate constraint-shape-aware optimizations for Groth16, Design Pre-Compiled Constraint Evaluator (PCE), Develop specialized MatVec for boolean witness exploitation, Create pre-computed split MSM topology, Synthesize total impact assessment across proposals 1-5
- Designed a pipelined SNARK proving daemon (cuzk) architecture through exhaustive investigation of the existing proof system, GPU inference engine patterns, and test data, resulting in a comprehensive cuzk-project.md document with phased implementation plan.Read and analyze all seven prior optimization proposals and background documents, Explore existing system layers: ffiselect, SRS loading, proof types, supraseal API, bellperson internals, Study GPU inference engine architectures (vLLM, Triton, TensorRT-LLM), Verify golden test data and explore lotus-bench commands, Design cuzk architecture and write cuzk-project.md document, Plan phased implementation roadmap with 18-week schedule
- Implemented Phase 0 of the cuzk proving engine by creating the Rust workspace, defining the gRPC API, implementing the core engine with priority scheduler, fixing build issues, validating the end-to-end pipeline, and resolving parameter dependencies.Create extern/cuzk/ Rust workspace with six crates, Define gRPC protobuf API for proof submission and daemon management, Implement core engine architecture with priority scheduler, Wire prover module to filecoin-proofs-api calls, Fix build system incompatibilities (Rust edition, dependencies, message size), Validate end-to-end gRPC pipeline (daemon, client, proof submission), Resolve parameter dependency by fetching and copying 32 GiB params
- Validated end-to-end PoRep proving pipeline with real GPU proofs, achieving 20.5% speedup from SRS residency, and hardened Phase 0 with observability and debugging improvements.Validate end-to-end PoRep proving pipeline with real GPU proof, Measure SRS residency benefit (20.5% speedup), Add tracing spans with job_id correlation for upstream logs, Add timing breakdown separating deserialization from proving time, Add per proof-kind Prometheus counters and duration summaries, Add GPU detection via nvidia-smi to status response, Fix AwaitProof RPC to support late listeners, Implement graceful shutdown via watch channel, Add cuzk-bench batch command for throughput measurement, Add sample config file cuzk.example.toml, Commit scaffold and hardening phases to feat/cuzk branch
- Completed Phase 1 of the cuzk proving engine by implementing all four Filecoin proof types (WinningPoSt, WindowPoSt, SnapDeals), adding multi-GPU worker pool with priority scheduling, then reviewing remaining deliverables and researching vanilla proof generation for next steps.Implement WinningPoSt, WindowPoSt, SnapDeals proving functions, Extend protobuf with repeated vanilla_proofs and commitment fields, Refactor engine for multi-GPU worker pool with CUDA_VISIBLE_DEVICES isolation, Update bench tool with flags for all proof types, Review project plan and assess Phase 1 deliverables, Research vanilla proof generation function signatures
- Completed Phase 1 by implementing the gen-vanilla command for generating vanilla proof test data, then analyzed bellperson internals and created a minimal fork to expose synthesis/GPU split APIs, designing the Phase 2 pipeline architecture.Implement gen-vanilla command for PoSt and SnapDeals test data generation, Analyze bellperson internals and design Phase 2 pipeline architecture, Create minimal bellperson fork exposing synthesis/GPU split APIs, Patch workspace to use bellperson fork and validate compilation
- Implemented the core Phase 2 pipelined proving engine for cuzk, replacing the monolithic PoRep C2 prover with a per-partition synthesis/GPU architecture via new SRS manager and pipeline modules.Create SRS manager module, Implement per-partition pipelining, Refactor engine for pipeline mode, Implement split synthesis/GPU prover functions, Add pipeline configuration support, Commit Phase 2 core implementation
- Completed Phase 2 pipeline implementation with batch-mode PoRep C2 synthesis, expanded pipeline to all proof types, validated GPU performance matching monolithic baseline, and planned async overlap architecture.E2E GPU test pipelined PoRep C2, Implement batch-all-partitions synthesis, Add PoSt/SnapDeals synthesis pipeline, GPU test batch-mode PoRep C2, Plan async overlap architecture
- Completed Phase 2 pipeline by committing batch-mode rewrite and implementing true async overlap between synthesis and GPU proving, validated with 3 consecutive PoRep C2 proofs achieving 1.27x throughput improvement.Commit batch-mode pipeline rewrite for all proof types, Implement async overlap synthesis-GPU pipeline with bounded channel, Validate E2E GPU performance with 3 consecutive PoRep proofs, Clean git state and ensure all tests pass
- Implemented and GPU-validated Phase 3 cross-sector batching for the cuzk pipelined SNARK proving engine, achieving 1.46x throughput improvement with minimal memory overhead.Implement cross-sector batching with BatchCollector, GPU E2E validate Phase 3 batching, Implement multi-sector PoRep synthesis, Implement split_batched_proofs for proof separation, Benchmark throughput and memory for batch_size=2, Commit Phase 3 implementation to feat/cuzk
- Completed Phase 3 E2E GPU validation of cross-sector batching and began Phase 4 compute-level optimizations, implementing four optimizations from c2-optimization-proposal-4.md, then reverting one due to regression and adding detailed CUDA timing instrumentation.Complete Phase 3 E2E GPU testing and documentation, Create local forks of bellpepper-core and supraseal-c2, Implement SmallVec optimization for LC Indexer (A1), Implement pre-sizing for ProvingAssignment (A2), Implement parallelize B_G2 CPU MSMs (A4), Implement pin a,b,c vectors with cudaHostRegister (B1), Implement per-MSM window tuning (D4), Benchmark Phase 4 changes, revert A2 usage, add CUDA timing instrumentation
- Diagnosed Phase 4 regression by reverting A2 and B1, then using a synth-only microbenchmark to identify SmallVec (A1) as the cause of a 5–6s synthesis slowdown.revert A2 pre-sizing from pipeline.rs, fix CUDA printf buffering for timing output, collect first CUZK_TIMING breakdown, revert B1 cudaHostRegister optimization, build synth-only microbenchmark subcommand, benchmark A1 SmallVec variants (Vec, cap=1/2/4), prepare perf stat analysis for SmallVec regression
- Implemented and profiled synthesis optimizations for the cuzk proving engine, including a Vec recycling pool and software prefetch, then identified and addressed the true bottleneck of temporary LinearCombination allocations inside closures by adding in-place methods to Boolean and Num.Implement Vec recycling pool for LinearCombination, Add software prefetch intrinsics to eval loops, Profile synthesis with perf to identify allocation bottleneck, Implement add_to_lc/sub_from_lc methods on Boolean, Patch hot call sites to eliminate temporary LC allocations
- Completed Phase 4 synthesis optimizations (Boolean::add_to_lc, async deallocation) achieving 13.2% total E2E improvement, then investigated and ruled out allocation overhead as a bottleneck by wiring up SynthesisCapacityHint with zero impact.Benchmark Boolean::add_to_lc synthesis optimization, Diagnose GPU wrapper regression (destructor overhead), Implement async deallocation for large vectors, Investigate allocation overhead hypothesis, Wire up SynthesisCapacityHint in pipeline, Benchmark allocation hint impact
- Designed and implemented the Pre-Compiled Constraint Evaluator (PCE) for Phase 5 of the cuzk proving engine, including core CSR infrastructure, multi-threaded evaluation, and full integration into the proof pipeline.Phase 4 post-mortem and transition to Phase 5, Design and implement cuzk-pce crate with CSR types, Implement multi-threaded CSR evaluation, Integrate PCE into cuzk pipeline with synthesize_auto, Add PceExtract benchmark command, Update all synthesis call sites to use PCE
- Debugged and fixed a correctness bug in the PCE's RecordingCS column indexing, optimized MatVec with parallel execution achieving 1.42× speedup, then designed and ran memory benchmarks to validate that PCE's 25.7 GiB static overhead scales gracefully across multiple concurrent pipelines, addressing multi-GPU deployment concerns.Debug and fix RecordingCS column index offset bug with tagged encoding, Optimize PCE MatVec with parallel execution for 8.8s evaluation, Design and implement pce-pipeline benchmark subcommand with RSS tracking, Validate memory model for multi-GPU scaling with sequential and parallel benchmarks, Update cuzk-project.md documentation with Phase 5 memory analysis and roadmap
- Implemented PCE disk persistence with raw binary format achieving 5.4x load speedup, designed Phase 6 slotted pipeline for finer-grained synthesis/GPU overlap, and integrated PCE preloading into the daemon to eliminate first-proof penalty.Implement PCE disk persistence with raw binary format, Integrate PCE preloading into daemon startup, Design Phase 6 slotted pipeline (c2-optimization-proposal-6.md), Implement slotted partition proving (prove_porep_c2_slotted), Update project documentation with parallel benchmarks, Commit changes to git
- Implemented and validated the Phase 6 slotted partition pipeline for the cuzk SNARK proving engine, achieving significant speedup and memory reduction.Refactor C1 deserialization into shared ParsedC1Output struct, Implement ProofAssembler struct for per-slot proof collection, Implement prove_porep_c2_slotted with thread scope and sync_channel, Add slot_size configuration to PipelineConfig, Wire slotted pipeline into engine process_batch, Add SlottedBench subcommand with GPU utilization tracking, Benchmark and validate slotted pipeline performance, Identify overlap calculation bug and rayon parallelism limits
- End-to-end testing of the cuzk proving daemon revealed that the standard pipeline path significantly outperforms the partitioned path in throughput (47.7s vs 72s per proof) due to inter-proof overlap, while the partitioned path remains valuable for memory reduction (71 GiB vs 228 GiB peak).End-to-end benchmark cuzk daemon pipeline performance, Compare standard vs partitioned proof paths, Analyze GPU utilization and throughput bottlenecks, Test concurrency levels and synthesis_lookahead, Evaluate memory reduction trade-offs
- Diagnosed a structural GPU idle gap in the cuzk proving engine and implemented parallel synthesis via tokio::sync::Semaphore, which saturated GPU utilization but revealed CPU contention as the new bottleneck, yielding only modest throughput improvement.Implement waterfall timeline instrumentation, Implement parallel synthesis with Semaphore, Benchmark parallel synthesis pipeline, Analyze CPU resource contention bottleneck, Identify need for Phase 5 Wave 2/3 optimizations
- Designed Phase 7 per-partition dispatch architecture for PoRep C2 proving, validated cross-sector pipelining via simulation, and committed the design document.correct partition synthesis time understanding, simulate per-partition dispatch model, design Phase 7 architecture with cross-sector pipelining, create c2-optimization-proposal-7.md, commit design document to repository
- Implemented Phase 7 per-partition dispatch architecture for the cuzk SNARK proving engine, benchmarked its performance, diagnosed GPU utilization gaps caused by static mutex contention, and designed Phase 8 dual-GPU-worker interlock to eliminate CPU-side overhead.Implement Phase 7 per-partition dispatch architecture, Benchmark Phase 7 and analyze GPU utilization gaps, Diagnose static mutex contention in generate_groth16_proofs_c, Design Phase 8 dual-GPU-worker interlock proposal, Commit Phase 7 implementation and Phase 8 design document
- Implemented Phase 8 dual-worker GPU interlock with narrowed C++ mutex, achieving 13-17% throughput improvement, then executed a systematic partition_workers sweep to identify the optimal setting (10-12) for the cuzk SNARK proving engine.Implement Phase 8 dual-worker GPU interlock, Refactor C++ static mutex to narrow scope, Add FFI plumbing for per-GPU mutex, Spawn multiple GPU workers per device, Benchmark Phase 8 GPU efficiency and throughput, Execute partition_workers sweep (10-20), Determine optimal partition_workers setting
- Performed TIMELINE analysis confirming perfect GPU-boundedness, then identified two root causes of GPU utilization dips (non-pinned host memory and Pippenger MSM sync stalls) and designed a two-tier mitigation plan documented in c2-optimization-proposal-9.md.Perform TIMELINE analysis of Phase 8 pw=10 benchmark, Update cuzk-project.md with Phase 6-8 results and TIMELINE analysis, Identify root causes of GPU utilization dips (non-pinned host memory and Pippenger MSM sync stalls), Design two-tier mitigation plan in c2-optimization-proposal-9.md
- Implemented Phase 9 PCIe transfer optimization for the cuzk SNARK proving engine, achieving 14.2% throughput improvement in single-worker mode and identifying PCIe bandwidth contention as the next bottleneck in dual-worker mode.Implement Phase 9 PCIe transfer optimization, Fix OOM failures from dual-worker pre-staging, Benchmark Phase 9 with single-worker, Execute full production benchmark with dual-worker, Analyze system-level performance gap
- Investigated Phase 9 PCIe optimization bottlenecks, designed and implemented Phase 10 two-lock architecture, but discovered fundamental CUDA device-global synchronization conflicts causing OOM and regression, leading to a redesign of the locking strategy.benchmark Phase 9 PCIe optimization, diagnose CPU memory bandwidth contention bottleneck, design Phase 10 two-lock overlap architecture, write Phase 10 optimization proposal document, implement Phase 10 two-lock design in CUDA code, debug Phase 10 OOM and performance regression, identify device-global sync as root cause of serialization
- Abandoned the flawed Phase 10 two-lock GPU interlock design after discovering fundamental CUDA device-global synchronization conflicts, reverted to Phase 9 single-lock, performed comprehensive benchmarking and waterfall timing analysis identifying DDR5 memory bandwidth contention as the bottleneck, then designed and documented Phase 11 with three targeted interventions to reduce contention.Abandon Phase 10 two-lock design and revert code to Phase 9 single-lock, Run comprehensive benchmarks across concurrency levels (c=5..c=20), Perform waterfall timing analysis from daemon logs to identify bottleneck, Design Phase 11 with three interventions to reduce DDR5 memory bandwidth contention, Write c2-optimization-proposal-11.md design spec and update cuzk-project.md with Phase 10 post-mortem and Phase 11 roadmap
- Implemented and benchmarked Phase 11 memory-bandwidth interventions, then designed and implemented Phase 12 split API to hide b_g2_msm latency by decoupling GPU worker critical path from CPU post-processing.Implement Phase 11 memory-bandwidth interventions, Benchmark Phase 11 interventions, Design split API for b_g2_msm offloading, Implement Phase 12 split API in C++ CUDA, Update Rust FFI and integrate split API, Restructure engine worker loop for split finalization
- Completed Phase 12 split GPU proving API implementation with bug fixes and benchmarking, then diagnosed and addressed memory pressure issues through instrumentation and iterative optimization of synthesis/GPU channel capacity.Fix Phase 12 compilation errors in engine.rs and FFI, Fix use-after-free bug in groth16_cuda.cu, Implement early deallocation of NTT evaluation vectors, Build global buffer tracker with atomic counters, Diagnose memory buildup from partition semaphore release, Optimize synthesis/GPU channel capacity for memory/throughput, Benchmark Phase 12 performance (37.1s/proof)
- Implemented memory backpressure for Phase 12 split API by early a/b/c free, channel capacity auto-scaling, and partition permit held through send, achieving pw=12 at 37.7s/proof without OOM.Implement early a/b/c free, Auto-scale channel capacity, Hold permit through channel send, Tune partition_workers parameter, Convert buffer counters to tracing::debug
- Consolidated Phase 12 architecture documentation and performed a systematic low-memory benchmark sweep to characterize memory scaling and throughput, providing deployment guidance for various system sizes.Update cuzk-project.md with Phase 12 architecture details, Update cuzk.example.toml with optimal defaults, Run low-memory benchmark sweep across pw/gw configurations, Derive memory scaling formula and deployment guidance, Commit changes to git as 9bb657e5
- Completed Phase 12 documentation and low-memory benchmarking, then implemented integration of the cuzk proving daemon into Curio's task orchestrator for PoRep, SnapDeals, and proofshare tasks.Finalize Phase 12 documentation and benchmarking, Update example config with RAM-tier guidelines, Create Go gRPC client for cuzk, Wire cuzk into PoRep, SnapDeals, proofshare tasks, Adapt task lifecycle for remote proving
- Finalized upstreaming of cuzk proving engine integration by vendoring Rust crates, extending the Makefile, and committing all changes with documentation.Vendor forked Rust crates in Curio repo, Extend Makefile with cuzk build/install targets, Add cuzk proving daemon documentation page, Stage and commit all integration files, Verify clean build and go vet
- This sub-session identified that the current chunk text was missing from the prompt and requested it, followed by a compaction.identify missing chunk text, request missing content, trigger compaction
- Composed and refined a comprehensive PR description for the cuzk integration branch, covering architecture, optimizations, and integration details.Compose PR description for cuzk integration, Shorten PR description with optimization summary, Format PR description as valid Markdown