Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Dec 6, 2024
1 parent 3c927aa commit b5c19b7
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 44 deletions.
29 changes: 5 additions & 24 deletions barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,11 @@
"construct_circuits(t)",
"DeciderProvingKey(Circuit&)(t)",
"ProtogalaxyProver::prove(t)",
"oink_constructor(t)",
# "execute_preamble_round(t)",
# "execute_wire_commitments_round(t)",
# "execute_sorted_list_accumulator_round(t)",
# "execute_log_derivative_inverse_round(t)",
# "compute_logderivative_inverses(t)",
"execute_grand_product_computation_round(t)",
# "compute_grand_product(t)",
"MegaFlavor::get_row(t)",
"fr::batch_invert(t)",
"total(t)",
"inner commit structured(t)",
"this(t)",
"add_in_place(t)",
"finalise_result(t)",
"hum(t)",
"point_table(t)",
"simple commit(t)"

# "Decider::construct_proof(t)",
# "ECCVMProver(CircuitBuilder&)(t)",
# "ECCVMProver::construct_proof(t)",
# "TranslatorProver::construct_proof(t)",
# "Goblin::merge(t)"
"Decider::construct_proof(t)",
"ECCVMProver(CircuitBuilder&)(t)",
"ECCVMProver::construct_proof(t)",
"TranslatorProver::construct_proof(t)",
"Goblin::merge(t)"
]

with open(PREFIX / IVC_BENCH_JSON, "r") as read_file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ClientIVCBench : public benchmark::Fixture {
*/
BENCHMARK_DEFINE_F(ClientIVCBench, Full)(benchmark::State& state)
{
// ClientIVC ivc{ { EXAMPLE_20 } };
ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } };

auto total_num_circuits = 2 * static_cast<size_t>(state.range(0)); // 2x accounts for kernel circuits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ template <class Curve> class CommitmentKey {
*/
Commitment commit(PolynomialSpan<const Fr> polynomial)
{
// PROFILE_THIS();
PROFILE_THIS_NAME("commit");
// We must have a power-of-2 SRS points *after* subtracting by start_index.
size_t dyadic_poly_size = numeric::round_up_power_2(polynomial.size());
// Because pippenger prefers a power-of-2 size, we must choose a starting index for the points so that we don't
Expand Down Expand Up @@ -133,7 +133,7 @@ template <class Curve> class CommitmentKey {
*/
Commitment commit_sparse(PolynomialSpan<const Fr> polynomial)
{
// PROFILE_THIS();
PROFILE_THIS_NAME("commit_sparse");
const size_t poly_size = polynomial.size();
ASSERT(polynomial.end_index() <= srs->get_monomial_size());

Expand Down Expand Up @@ -207,16 +207,16 @@ template <class Curve> class CommitmentKey {
const std::vector<std::pair<size_t, size_t>>& active_ranges,
size_t final_active_wire_idx = 0)
{
// BB_OP_COUNT_TIME();
PROFILE_THIS_NAME("commit_structured");
ASSERT(polynomial.end_index() <= srs->get_monomial_size());

// Percentage of nonzero coefficients beyond which we resort to the conventional commit method
constexpr size_t NONZERO_THRESHOLD = 75;

// Compute the number of non-zero coefficients in the polynomial
size_t total_num_scalars = 0;
for (const auto& range : active_ranges) {
total_num_scalars += range.second - range.first;
for (const auto& [first, second] : active_ranges) {
total_num_scalars += second - first;
}

// Compute "active" percentage of polynomial; resort to standard commit if appropriate
Expand Down Expand Up @@ -265,7 +265,7 @@ template <class Curve> class CommitmentKey {
const std::vector<std::pair<size_t, size_t>>& active_ranges,
size_t final_active_wire_idx = 0)
{
PROFILE_THIS_NAME("total");
PROFILE_THIS_NAME("commit_structured_with_nonzero_complement");
ASSERT(polynomial.end_index() <= srs->get_monomial_size());

using BatchedAddition = BatchedAffineAddition<Curve>;
Expand All @@ -277,9 +277,8 @@ template <class Curve> class CommitmentKey {
// Note: the range from the end of the last active range to the end of the polynomial is excluded from the
// complement since the polynomial is assumed to be zero there.
std::vector<std::pair<size_t, size_t>> active_ranges_complement;
// Compute the total number of scalars in the constant regions
// Also compute total number of scalars in the constant regions
size_t total_num_complement_scalars = 0;

for (size_t i = 0; i < active_ranges.size() - 1; ++i) {
const size_t start = active_ranges[i].second;
const size_t end = active_ranges[i + 1].first;
Expand All @@ -303,8 +302,7 @@ template <class Curve> class CommitmentKey {

// Copy the raw SRS points (no endo points) corresponding to the constant regions into contiguous memory
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1131): Peak memory usage could be improved by
// performing this copy and the subsequent summation as a precomputation prior to constructing the point
// table.
// performing this copy and the subsequent summation as a precomputation prior to constructing the point table.
std::vector<G1> points;

points.reserve(total_num_complement_scalars);
Expand All @@ -326,8 +324,7 @@ template <class Curve> class CommitmentKey {
// Reduce each sequence to a single point
auto reduced_points = BatchedAddition::add_in_place(points, sequence_counts);

// Compute the full commitment as the sum of the "active" region commitment and the constant region
// contribution
// Compute the full commitment as the sum of the "active" region commitment and the constant region contribution
Commitment result = commit_structured(polynomial, active_ranges, final_active_wire_idx);

for (auto [scalar, point] : zip_view(unique_scalars, reduced_points)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ template <typename Curve>
std::vector<typename BatchedAffineAddition<Curve>::G1> BatchedAffineAddition<Curve>::add_in_place(
const std::span<G1>& points, const std::vector<size_t>& sequence_counts)
{
PROFILE_THIS_NAME("add_in_place");
PROFILE_THIS_NAME("BatchedAffineAddition::add_in_place");
// Instantiate scratch space for point addition denominators and their calculation
std::vector<Fq> scratch_space_vector(points.size());
std::span<Fq> scratch_space(scratch_space_vector);
Expand Down
2 changes: 0 additions & 2 deletions barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ template <class T> void field<T>::batch_invert(std::span<field> coeffs) noexcept
auto* skipped = skipped_ptr.get();

field accumulator = one();

for (size_t i = 0; i < n; ++i) {
temporaries[i] = accumulator;
if (coeffs[i].is_zero()) {
Expand Down Expand Up @@ -446,7 +445,6 @@ template <class T> void field<T>::batch_invert(std::span<field> coeffs) noexcept
accumulator = accumulator.invert();

field T0;

for (size_t i = n - 1; i < n; --i) {
if (!skipped[i]) {
T0 = accumulator * temporaries[i];
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ template <typename FF, typename CommitmentKey_> class ProvingKey_ {
// folded element by element.
std::vector<FF> public_inputs;

// Ranges of the form [start, end) where witnesses have nontrivial values (hence the execution trace is "active")
// Ranges of the form [start, end) where witnesses have non-zero values (hence the execution trace is "active")
std::vector<std::pair<size_t, size_t>> active_block_ranges;

ProvingKey_() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void compute_grand_product(typename Flavor::ProverPolynomials& full_polynomials,
// the permutation grand product does not need to be computed beyond the index of the last active wire
size_t domain_size = size_override == 0 ? full_polynomials.get_polynomial_size() : size_override;

size_t num_threads = domain_size >= get_num_cpus_pow2() ? get_num_cpus_pow2() : 1;
const size_t num_threads = domain_size >= get_num_cpus_pow2() ? get_num_cpus_pow2() : 1;
const size_t block_size = domain_size / num_threads;
const size_t final_idx = domain_size - 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class UltraFlavor {
[[nodiscard]] size_t get_polynomial_size() const { return q_c.size(); }
[[nodiscard]] AllValues get_row(const size_t row_idx) const
{
PROFILE_THIS_NAME("get_row");
PROFILE_THIS_NAME("UltraFlavor::get_row");
AllValues result;
for (auto [result_field, polynomial] : zip_view(result.get_all(), get_all())) {
result_field = polynomial[row_idx];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ template <IsUltraFlavor Flavor> void OinkProver<Flavor>::execute_grand_product_c
proving_key->proving_key.compute_grand_product_polynomial(proving_key->relation_parameters,
proving_key->final_active_wire_idx + 1);

info("final active wire ", proving_key->final_active_wire_idx + 1);
{
PROFILE_THIS_NAME("COMMIT::z_perm");
if (proving_key->get_is_structured()) {
Expand Down

0 comments on commit b5c19b7

Please sign in to comment.