feat(polynomials): Accumulator<Fr> + vectorize compute_sum#23210
Draft
notnotraju wants to merge 1 commit into
Draft
feat(polynomials): Accumulator<Fr> + vectorize compute_sum#23210notnotraju wants to merge 1 commit into
notnotraju wants to merge 1 commit into
Conversation
43c0fe0 to
32361fc
Compare
852e6ac to
10ce846
Compare
32361fc to
60358fd
Compare
Add Accumulator<Fr>, the reduction-direction companion to Broadcast<Fr>:
holds a scalar Fr slot plus a VectorField<Fr::Params> vector slot, exposes
operator+=(Fr) and operator+=(VectorField), and reduce() to horizontal-add
the vector lanes into the scalar slot at the end. Lets a `vectorized_for`
kernel express a sum (or any pointwise reduction) in one line:
Accumulator<Fr> acc;
vectorized_for<VECTOR_FIELD_WIDTH, Fr>(0, n, [&](auto ctx) { acc += view[ctx]; });
return acc.reduce();
Migrate polynomial_arithmetic::compute_sum to use this pattern. The
vectorized_for call passes Fr so the bulk SIMD path is correctly gated on
simd_supported_v<Fr> (Bn254FrParams only); Polynomial<bb::fq>'s compute_sum
takes the scalar path under WASM as expected.
10ce846 to
0ecbef7
Compare
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.
Goal. Introduce `Accumulator` — the reduction counterpart to `Broadcast`. `operator+=(Fr)` for ScalarIndex contributions, `operator+=(VectorField)` for ContiguousVectorIndex contributions, `reduce()` horizontal-adds the N vector lanes with the scalar slot. Migrate `polynomial_arithmetic::compute_sum` as the canonical first user.
Non-goal. Migrate other reduction sites. Accumulator is the primitive that compose with Polynomial's existing operator[]; richer reduction kernels (sumcheck partial-evaluate, MLE fold, IPA inner product) live in follow-up work.
Why this is a separate PR. Accumulator is the third of the adapter types (after Broadcast and the implicit Polynomial proxies). It's the design building block for any kernel that reduces over per-iteration contributions, including the dot-product shape (`acc += a[ctx] * b[ctx]`) needed for IPA. Reviewable independently of the abstraction-layer PR — the diff is one new adapter type + one migrated function + one bench file.
Kernel after migration.
```cpp
PolynomialSpan view{0, std::span(src, n)};
Accumulator acc;
vectorized_for<VECTOR_FIELD_WIDTH>(0, n, [&](auto ctx) { acc += view[ctx]; });
return acc.reduce();
```
V8/WASM bench (N=2^16, n=5 reps). From barretenberg-claude where the code originated; file states are bit-identical:
WASM op-count diff (same bench binary, scalar vs vectorized source):
Tests. `polynomials_tests` passes everything mt/bb passes today. `CorrectnessGuard` at `compute_sum_bench` startup verifies bit-equality of scalar vs vectorized on 65k random fr's.
Stack.