Skip to content

Cache per-level FFT twiddle tables and batch evaluator slice math - #290

Closed
lamb356 wants to merge 4 commits into
zakura-core:mainfrom
lamb356:devin/split-6-fft-eval
Closed

Cache per-level FFT twiddle tables and batch evaluator slice math#290
lamb356 wants to merge 4 commits into
zakura-core:mainfrom
lamb356:devin/split-6-fft-eval

Conversation

@lamb356

@lamb356 lamb356 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Caches per-level FFT twiddle tables in the proving key and batches the evaluator's hot slice math through the Pasta batched field ops.

poly/domain.rs:

  • ProvingKeyTwiddles now also retains base_inverse_tables / extended_forward_tables: per-recursion-level contiguous twiddle tables (butterfly_twiddle_tables), built once per proving key.
  • Butterfly nodes with half-size > BUTTERFLY_BATCH_MIN_HALF = 32 multiply the right half against the cached contiguous table via batch::mul_slice instead of strided per-element twiddles[(i+1)*chunk] reads; smaller nodes keep the scalar loop. Composes with the paired-chunk interleaving from Interleave paired field FFT chunks #284 (the paired helper carries the cached tables too).
  • Inverse FFT completion uses batched scaling.

poly/evaluator.rs:

  • Chunk scheduling changed from 8 chunks/thread to 1 (EVALUATOR_CHUNKS_PER_THREAD = 1) — larger contiguous slices make the batched ops effective.
  • Product, square, and Horner-style AST nodes go through assign_rotated_chunk + mul_rotated_chunk / batch::sqr_slice, dispatching to the IFMA slice kernels when available and to the scalar loop otherwise.

The batched slice ops come from the IFMA PR (piece 2, #286); this branch includes that commit so it builds standalone — only the top commits are new here; it rebases cleanly once piece 2 merges. Without AVX-512 IFMA the batch dispatch falls back to scalar loops, and the twiddle caching + scheduling changes still help on their own.

Several ms end-to-end at 8 threads in the full stack. 16-core numbers welcome:
RAYON_NUM_THREADS=16 ORCHARD_K11_PROVER_THREADS=16 cargo bench -p zakura-orchard --features circuit,orbits --bench orchard_k11_prover

Part of the split of #273 (piece 6 of 6, depends on piece 2, #286).

Testing

  • cargo test --release -p zakura-halo2-proofs (137 tests pass, FFT round-trip and proof tests included).
  • cargo check --locked --all-features --all-targets, MSRV (1.91) check, cargo clippy (no new warnings vs main), and cargo fmt --all -- --check clean.

lamb356 and others added 4 commits August 31, 2026 16:34
Adds an ifma feature to zakura-pasta-curves with 8-way AVX-512 IFMA
kernels for batched Montgomery multiplication, squaring, scaling, and a
deferred-reduction dot product over Fp/Fq, with runtime CPU detection
and scalar fallbacks. halo2 gains a TypeId-dispatched batch module used
for iFFT divisor scaling and deferred inner products.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Proving-key twiddles now retain contiguous per-recursion-level twiddle
tables so the butterfly combine step multiplies the right half against
a contiguous table with the batched slice multiplier instead of a
strided walk. The polynomial evaluator uses the batched elementwise
multiply/square helpers for product, square, and Horner nodes, and
processes one chunk per thread.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@ValarDragon

Copy link
Copy Markdown
Contributor

Thank you! Extracted the FFT part of this into github.com//pull/324 , and added you as a commit co-author to it (appears in both PR and main's squash commit!) TYSM!

@ValarDragon ValarDragon closed this Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants