chore: cleanup polynomials module#20585
Conversation
8283495 to
d1e9cce
Compare
| static constexpr bool value = true; | ||
| }; | ||
|
|
||
| 3) There should be more thorough testing of this class in isolation. |
There was a problem hiding this comment.
More tests included to cover the stdlib runtime path
| , domain_inverse(domain.invert()) | ||
| , generator(Fr::template coset_generator<0>()) | ||
| , generator_inverse(Fr::template coset_generator<0>().invert()) | ||
| , four_inverse(Fr(4).invert()) |
| , generator_size(other.generator_size) | ||
| , root(Fr::get_root_of_unity(log2_size)) | ||
| , root_inverse(root.invert()) | ||
| , root(other.root) |
There was a problem hiding this comment.
Use other's root parameters, to avoid computing root_of_unity for Grumpkin, similar to the behaviour of the primary constructor.
| * corresponds to the start_index of the destination polynomial and also that the number of elements we want to copy | ||
| * corresponds to the size of the polynomial. This is quirky behavior and we might want to improve the UX. | ||
| * | ||
| * @todo https://github.com/AztecProtocol/barretenberg/issues/1292 |
There was a problem hiding this comment.
Removed the todo as it is marked as closed. Also clarified the function’s usage in the comment.
|
|
||
| // hard code exception for when the domain size is tiny - we won't execute the next loop, so need to manually | ||
| // reduce + copy | ||
| if (domain.size <= 2) { |
There was a problem hiding this comment.
Removed this copying back into coeffs as for domain.size <= 2 the final output is already in target, andcoeffs should not be modified in this overload of fft_inner_parallel. This was probably copied from the previous overload.
ledwards2225
left a comment
There was a problem hiding this comment.
Overall LGTM, made some small suggestions. Would you mind doing a follow on here where you're really ruthless about removing unused code? E.g. I was under the impression that the only FFT related method we use is ifft in SSIPA
| // pre-computable arrays in BarycentricData need to be constexpr and it takes some trickery to share these functions | ||
| // with the non-constexpr setting. Right now everything is more or less duplicated across BarycentricDataCompileTime and | ||
| // BarycentricDataRunTime. There should be a way to share more of the logic. | ||
| /* Future improvements (see https://github.com/AztecProtocol/barretenberg/issues/10): The code works for its intended |
There was a problem hiding this comment.
Maybe (2) here is something we leave as a note but (1) and (3) should probably be handled. Can you evaluate whether there is something needed to address them, do it if so, then remove?
There was a problem hiding this comment.
For (1), added compile-time guards for domain_size, num_evals. This should take care of invalid sizes. For (3), I had already added stdlib runtime tests which were missing earlier. Updated the note accordingly.
| if (coeffs[i] == 0) { | ||
| skipped[i] = true; | ||
| // For native field types, == 0 is a plain constexpr comparison. For stdlib field_t, | ||
| // operator== would create circuit constraints and return bool_t, so we use get_value() |
There was a problem hiding this comment.
suggestion: add some protection around the get_value call to reflect the assumption stated in comments e.g. BB_ASSERT(coeffs[i].is_constant());
| // TODO(https://github.com/AztecProtocol/barretenberg/issues/1096): Make this a Polynomial with | ||
| // DontZeroMemory::FLAG | ||
| auto tmp_ptr = _allocate_aligned_memory<Fr_>(sizeof(Fr_) * n_l); | ||
| // IMPROVEMENT: tmp is fully overwritten. We could make this a Polynomial with DontZeroMemory::FLAG. See |
There was a problem hiding this comment.
Can you make an assessment one way or the other on this one too?
There was a problem hiding this comment.
although tmp is fully overwritten, switching it to Polynomial<Fr_> with DontZeroMemory may not reduce work here because it would still allocate backing memory and introduce additional overhead for setting up the metadata for SharedShiftedVirtualZeroesArray. The current allocation already avoids zeroing the memory. Also, the linked issue (#1096) is about get_row copying and doesn’t look related to this mle temporary buffer. So I have removed the improvement comment and the issue reference to avoid confusion.
| result.value_at(idx + 1) = result.value_at(idx) + delta; | ||
| } | ||
| } else if constexpr (LENGTH == 3) { | ||
| static constexpr Fr inverse_two = Fr(2).invert(); |
There was a problem hiding this comment.
yes, it is used to compute a = (f(2) + f(0) - 2f(1)) / 2 in the lines following it
| } | ||
| } else if constexpr (LENGTH == 3) { | ||
| static constexpr Fr inverse_two = Fr(2).invert(); | ||
| // Based off https://hackmd.io/@aztec-network/SyR45cmOq?type=view |
There was a problem hiding this comment.
This wont be accessible to most - can you see if this hackmd says anything useful and if so port some version of that to the comments here?
There was a problem hiding this comment.
it slipped my mind that the hackmd may not be accessible. The hackmd doesn’t have anything additional except for some rough cost accounting. So I have removed the link and added a short comment note that this special case path is cheaper than the generic method.
| return output; | ||
| }; | ||
|
|
||
| /* |
There was a problem hiding this comment.
was this meant to be deleted altogether?
…ltiplicative_subgroup, unused coset_fft overload, compute_barycentric_evaluation, unnecessary if block from fft_inner_parallel, update array declarations, add test for coset_fft scaling.
…e, and update constructors for consistent root handling
0e9cb38 to
64adc29
Compare
…#20988) - Replace `ITERATE_OVER_DOMAIN_START` and `ITERATE_OVER_DOMAIN_END` macros with a `parallel_for` loop in `ifft()` - The macro was only used in `ifft()`. Replacing it with an inline loop makes the control flow clearer and allows removing the unused header. - Delete the now-unused `iterate_over_domain.hpp` - Address race condition in `try_allocate_file_backed` in `backing_memory.hpp` - Remove old improvement note in `barycentric.hpp`, as it is addressed in PR [#20585](#20585)
Cleanup and minor changes in the polynomial module.
Changes:
- Delete unused methods in `univariate_coefficient_basis.hpp`
- `is_zero`
- `random_element`
- `to_buffer`
- `serialize_from_buffer`
- `size`
- `get_random`
- Delete unused methods in `polynomial.hpp/cpp`
- `clear()`
- `right_shifted()`
- `debug_hash()`
- `compute_barycentric_evaluation()`
- `in_place_operation_viable`
- overload of evaluate `evaluate(const Fr& z, size_t target_size)`
- Delete unused methods in `polynomial_arithmetic.hpp/cpp`
- `compute_multiplicative_subgroup`
- `compute_barycentric_evaluation `
- `fft`, `coset_fft`, unused overloads of `fft_inner_parallel` and
`ifft`
- Delete unused `compute_generator_table` and `four_inverse` in
`evaluation_domain.hpp`
- Fixed `_allocate_aligned_memory` call to pass element count (`n_l`)
instead of byte size.
- Add new tests in `barycentric.test.cpp` covering the `stdlib` runtime
path
- Deduplicate compile-time and runtime `BarycentricData` logic via a
shared base class (resolves TODO
[#674](AztecProtocol/barretenberg#674))
…#20988) - Replace `ITERATE_OVER_DOMAIN_START` and `ITERATE_OVER_DOMAIN_END` macros with a `parallel_for` loop in `ifft()` - The macro was only used in `ifft()`. Replacing it with an inline loop makes the control flow clearer and allows removing the unused header. - Delete the now-unused `iterate_over_domain.hpp` - Address race condition in `try_allocate_file_backed` in `backing_memory.hpp` - Remove old improvement note in `barycentric.hpp`, as it is addressed in PR [#20585](#20585)
Cleanup and minor changes in the polynomial module.
Changes:
univariate_coefficient_basis.hppis_zerorandom_elementto_bufferserialize_from_buffersizeget_randompolynomial.hpp/cppclear()right_shifted()debug_hash()compute_barycentric_evaluation()in_place_operation_viableevaluate(const Fr& z, size_t target_size)polynomial_arithmetic.hpp/cppcompute_multiplicative_subgroupcompute_barycentric_evaluationfft,coset_fft, unused overloads offft_inner_parallelandifftcompute_generator_tableandfour_inverseinevaluation_domain.hpp_allocate_aligned_memorycall to pass element count (n_l) instead of byte size.barycentric.test.cppcovering thestdlibruntime pathBarycentricDatalogic via a shared base class (resolves TODO #674)