From cf271ac55fc8b756877846b2848ff530fd4a6628 Mon Sep 17 00:00:00 2001 From: maramihali Date: Thu, 5 Dec 2024 10:49:15 +0000 Subject: [PATCH 1/6] preliminary stuff --- .../cpp/scripts/analyze_client_ivc_bench.py | 26 +++++++-- .../client_ivc_bench/client_ivc.bench.cpp | 3 +- .../commitment_schemes/commitment_key.hpp | 1 + .../barretenberg/ecc/fields/field_impl.hpp | 32 ++++++----- .../relations/databus_lookup_relation.hpp | 56 ++++++++++--------- .../relations/logderiv_lookup_relation.hpp | 36 +++++++++--- .../stdlib_circuit_builders/mega_flavor.hpp | 11 ++-- .../stdlib_circuit_builders/ultra_flavor.hpp | 2 +- .../trace_to_polynomials.cpp | 3 +- .../barretenberg/ultra_honk/oink_prover.cpp | 5 +- 10 files changed, 114 insertions(+), 61 deletions(-) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index 600854679c5..c27fab4da7f 100755 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -18,11 +18,27 @@ "construct_circuits(t)", "DeciderProvingKey(Circuit&)(t)", "ProtogalaxyProver::prove(t)", - "Decider::construct_proof(t)", - "ECCVMProver(CircuitBuilder&)(t)", - "ECCVMProver::construct_proof(t)", - "TranslatorProver::construct_proof(t)", - "Goblin::merge(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_polynomial(t)", +"MegaFlavor::get_row(t)", +"logderivative relation(t)", +"databus relation(t)", +"fr::batch_invert(t)", +"thish(t)", +"and thish(t)", +"chunk1(t)", +"chunk2(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: diff --git a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp index 6033648972c..517088579e3 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp @@ -33,7 +33,8 @@ class ClientIVCBench : public benchmark::Fixture { */ BENCHMARK_DEFINE_F(ClientIVCBench, Full)(benchmark::State& state) { - ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; + ClientIVC ivc{ { EXAMPLE_20 } }; + // ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; auto total_num_circuits = 2 * static_cast(state.range(0)); // 2x accounts for kernel circuits auto mocked_vkeys = mock_verification_keys(total_num_circuits); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp index 6440c016a62..6a597e6deb9 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp @@ -212,6 +212,7 @@ template class CommitmentKey { // 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; diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp index 0ed0c481dec..e6a559e2030 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp @@ -406,7 +406,7 @@ template void field::batch_invert(field* coeffs, const size_t n) no template void field::batch_invert(std::span coeffs) noexcept { - BB_OP_COUNT_TRACK_NAME("fr::batch_invert"); + PROFILE_THIS_NAME("fr::batch_invert"); const size_t n = coeffs.size(); auto temporaries_ptr = std::static_pointer_cast(get_mem_slab(n * sizeof(field))); @@ -415,13 +415,16 @@ template void field::batch_invert(std::span 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()) { - skipped[i] = true; - } else { - skipped[i] = false; - accumulator *= coeffs[i]; + { + PROFILE_THIS_NAME("thish"); + for (size_t i = 0; i < n; ++i) { + temporaries[i] = accumulator; + if (coeffs[i].is_zero()) { + skipped[i] = true; + } else { + skipped[i] = false; + accumulator *= coeffs[i]; + } } } @@ -444,11 +447,14 @@ template void field::batch_invert(std::span coeffs) noexcept accumulator = accumulator.invert(); field T0; - for (size_t i = n - 1; i < n; --i) { - if (!skipped[i]) { - T0 = accumulator * temporaries[i]; - accumulator *= coeffs[i]; - coeffs[i] = T0; + { + PROFILE_THIS_NAME("and thish"); + for (size_t i = n - 1; i < n; --i) { + if (!skipped[i]) { + T0 = accumulator * temporaries[i]; + accumulator *= coeffs[i]; + coeffs[i] = T0; + } } } } diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index bb29d9bc8a9..912c829a7c3 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -226,35 +226,41 @@ template class DatabusLookupRelationImpl { * */ template - static void compute_logderivative_inverse(Polynomials& polynomials, - auto& relation_parameters, - const size_t circuit_size) + static void compute_logderivative_inverse( + Polynomials& polynomials, + auto& relation_parameters, + const size_t circuit_size, + [[maybe_unused]] const std::vector>& active_block_ranges) { + PROFILE_THIS_NAME("databus relation"); auto& inverse_polynomial = BusData::inverses(polynomials); bool is_read = false; bool nonzero_read_count = false; - for (size_t i = 0; i < circuit_size; ++i) { - // Determine if the present row contains a databus operation - auto q_busread = polynomials.q_busread[i]; - if constexpr (bus_idx == 0) { // calldata - is_read = q_busread == 1 && polynomials.q_l[i] == 1; - nonzero_read_count = polynomials.calldata_read_counts[i] > 0; - } - if constexpr (bus_idx == 1) { // secondary_calldata - is_read = q_busread == 1 && polynomials.q_r[i] == 1; - nonzero_read_count = polynomials.secondary_calldata_read_counts[i] > 0; - } - if constexpr (bus_idx == 2) { // return data - is_read = q_busread == 1 && polynomials.q_o[i] == 1; - nonzero_read_count = polynomials.return_data_read_counts[i] > 0; - } - // We only compute the inverse if this row contains a read gate or data that has been read - if (is_read || nonzero_read_count) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. - auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! - auto value = compute_read_term(row, relation_parameters) * - compute_write_term(row, relation_parameters); - inverse_polynomial.at(i) = value; + { + PROFILE_THIS_NAME("chunk2"); + for (size_t i = 0; i < circuit_size; ++i) { + // Determine if the present row contains a databus operation + auto q_busread = polynomials.q_busread[i]; + if constexpr (bus_idx == 0) { // calldata + is_read = q_busread == 1 && polynomials.q_l[i] == 1; + nonzero_read_count = polynomials.calldata_read_counts[i] > 0; + } + if constexpr (bus_idx == 1) { // secondary_calldata + is_read = q_busread == 1 && polynomials.q_r[i] == 1; + nonzero_read_count = polynomials.secondary_calldata_read_counts[i] > 0; + } + if constexpr (bus_idx == 2) { // return data + is_read = q_busread == 1 && polynomials.q_o[i] == 1; + nonzero_read_count = polynomials.return_data_read_counts[i] > 0; + } + // We only compute the inverse if this row contains a read gate or data that has been read + if (is_read || nonzero_read_count) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. + auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! + auto value = compute_read_term(row, relation_parameters) * + compute_write_term(row, relation_parameters); + inverse_polynomial.at(i) = value; + } } } // Compute inverse polynomial I in place by inverting the product at each row diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index afd1326a91d..daf7d36ad6b 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -153,20 +153,38 @@ template class LogDerivLookupRelationImpl { template static void compute_logderivative_inverse(Polynomials& polynomials, auto& relation_parameters, - const size_t circuit_size) + [[maybe_unused]] const size_t circuit_size, + const std::vector>& active_ranges) { + PROFILE_THIS_NAME("logderivative relation"); auto& inverse_polynomial = get_inverse_polynomial(polynomials); - for (size_t i = 0; i < circuit_size; ++i) { - // We only compute the inverse if this row contains a lookup gate or data that has been looked up - if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. - auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! - auto value = compute_read_term(row, relation_parameters) * - compute_write_term(row, relation_parameters); - inverse_polynomial.at(i) = value; + { + PROFILE_THIS_NAME("chunk1"); + // for (const auto& [first, second] : active_ranges) { + // for (size_t i = first; i < second; i++) { + // if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { + // // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. + // auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! + // auto value = compute_read_term(row, relation_parameters) * + // compute_write_term(row, relation_parameters); + // inverse_polynomial.at(i) = value; + // } + // } + // } + + for (size_t i = 0; i < circuit_size; ++i) { + // We only compute the inverse if this row contains a lookup gate or data that has been looked up + if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. + auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! + auto value = compute_read_term(row, relation_parameters) * + compute_write_term(row, relation_parameters); + inverse_polynomial.at(i) = value; + } } } + // Compute inverse polynomial I in place by inverting the product at each row FF::batch_invert(inverse_polynomial.coeffs()); }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index f4129c363a3..da95e9fc856 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -492,21 +492,23 @@ class MegaFlavor { */ void compute_logderivative_inverses(const RelationParameters& relation_parameters) { + PROFILE_THIS_NAME("compute_logderivative_inverses"); + // Compute inverses for conventional lookups LogDerivLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size); + this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); // Compute inverses for calldata reads DatabusLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size); + this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); // Compute inverses for secondary_calldata reads DatabusLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size); + this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); // Compute inverses for return data reads DatabusLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size); + this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); } /** @@ -517,6 +519,7 @@ class MegaFlavor { */ void compute_grand_product_polynomial(RelationParameters& relation_parameters, size_t size_override = 0) { + PROFILE_THIS_NAME("compute_grand_product_polynomial"); relation_parameters.public_input_delta = compute_public_input_delta(this->public_inputs, relation_parameters.beta, relation_parameters.gamma, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 6ff45fb338d..feffc7e53c8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -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(); + PROFILE_THIS_NAME("get_row"); AllValues result; for (auto [result_field, polynomial] : zip_view(result.get_all(), get_all())) { result_field = polynomial[row_idx]; diff --git a/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp b/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp index f778a03c503..b9fe370a9f9 100644 --- a/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp +++ b/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp @@ -102,7 +102,7 @@ typename TraceToPolynomials::TraceData TraceToPolynomials::const auto block_size = static_cast(block.size()); // Save ranges over which the blocks are "active" for use in structured commitments - if constexpr (IsUltraFlavor) { + if constexpr (IsUltraFlavor) { // Ultra and Mega if (block.size() > 0) { proving_key.active_block_ranges.emplace_back(offset, offset + block.size()); } @@ -150,6 +150,7 @@ typename TraceToPolynomials::TraceData TraceToPolynomials::const // otherwise, the next block starts immediately following the previous one offset += block.get_fixed_size(is_structured); } + return trace_data; } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index 111497e9175..c394d0392c3 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -206,8 +206,8 @@ template void OinkProver::execute_log_derivative_ { PROFILE_THIS_NAME("COMMIT::lookup_inverses"); - witness_commitments.lookup_inverses = - proving_key->proving_key.commitment_key->commit(proving_key->proving_key.polynomials.lookup_inverses); + witness_commitments.lookup_inverses = proving_key->proving_key.commitment_key->commit_sparse( + proving_key->proving_key.polynomials.lookup_inverses); } transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, witness_commitments.lookup_inverses); @@ -235,6 +235,7 @@ template void OinkProver::execute_grand_product_c { PROFILE_THIS_NAME("OinkProver::execute_grand_product_computation_round"); // Compute the permutation grand product polynomial + proving_key->proving_key.compute_grand_product_polynomial(proving_key->relation_parameters, proving_key->final_active_wire_idx + 1); From ba663daeb448bc118f7d51137e4c8163cb6cb9c5 Mon Sep 17 00:00:00 2001 From: maramihali Date: Thu, 5 Dec 2024 11:10:44 +0000 Subject: [PATCH 2/6] parallelise logderivative construction --- .../client_ivc_bench/client_ivc.bench.cpp | 2 +- .../relations/databus_lookup_relation.hpp | 65 +++++++++++-------- .../relations/logderiv_lookup_relation.hpp | 39 ++++++----- .../trace_to_polynomials.cpp | 2 +- .../barretenberg/ultra_honk/oink_prover.cpp | 4 +- 5 files changed, 66 insertions(+), 46 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp index 6033648972c..7aa1b8910d8 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp @@ -33,7 +33,7 @@ class ClientIVCBench : public benchmark::Fixture { */ BENCHMARK_DEFINE_F(ClientIVCBench, Full)(benchmark::State& state) { - ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; + ClientIVC ivc{ { EXAMPLE_20 } }; auto total_num_circuits = 2 * static_cast(state.range(0)); // 2x accounts for kernel circuits auto mocked_vkeys = mock_verification_keys(total_num_circuits); diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index bb29d9bc8a9..3b00b5bff69 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -3,6 +3,7 @@ #include #include "barretenberg/common/constexpr_utils.hpp" +#include "barretenberg/common/thread.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" @@ -231,32 +232,42 @@ template class DatabusLookupRelationImpl { const size_t circuit_size) { auto& inverse_polynomial = BusData::inverses(polynomials); - bool is_read = false; - bool nonzero_read_count = false; - for (size_t i = 0; i < circuit_size; ++i) { - // Determine if the present row contains a databus operation - auto q_busread = polynomials.q_busread[i]; - if constexpr (bus_idx == 0) { // calldata - is_read = q_busread == 1 && polynomials.q_l[i] == 1; - nonzero_read_count = polynomials.calldata_read_counts[i] > 0; - } - if constexpr (bus_idx == 1) { // secondary_calldata - is_read = q_busread == 1 && polynomials.q_r[i] == 1; - nonzero_read_count = polynomials.secondary_calldata_read_counts[i] > 0; - } - if constexpr (bus_idx == 2) { // return data - is_read = q_busread == 1 && polynomials.q_o[i] == 1; - nonzero_read_count = polynomials.return_data_read_counts[i] > 0; - } - // We only compute the inverse if this row contains a read gate or data that has been read - if (is_read || nonzero_read_count) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. - auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! - auto value = compute_read_term(row, relation_parameters) * - compute_write_term(row, relation_parameters); - inverse_polynomial.at(i) = value; + + size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread + size_t num_threads = bb::calculate_num_threads_pow2(circuit_size, min_iterations_per_thread); + size_t iterations_per_thread = circuit_size / num_threads; // actual iterations per thread + + parallel_for(num_threads, [&](size_t thread_idx) { + size_t start = thread_idx * iterations_per_thread; + size_t end = (thread_idx + 1) * iterations_per_thread; + bool is_read = false; + bool nonzero_read_count = false; + for (size_t i = start; i < end; ++i) { + // Determine if the present row contains a databus operation + auto q_busread = polynomials.q_busread[i]; + if constexpr (bus_idx == 0) { // calldata + is_read = q_busread == 1 && polynomials.q_l[i] == 1; + nonzero_read_count = polynomials.calldata_read_counts[i] > 0; + } + if constexpr (bus_idx == 1) { // secondary_calldata + is_read = q_busread == 1 && polynomials.q_r[i] == 1; + nonzero_read_count = polynomials.secondary_calldata_read_counts[i] > 0; + } + if constexpr (bus_idx == 2) { // return data + is_read = q_busread == 1 && polynomials.q_o[i] == 1; + nonzero_read_count = polynomials.return_data_read_counts[i] > 0; + } + // We only compute the inverse if this row contains a read gate or data that has been read + if (is_read || nonzero_read_count) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. + auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! + auto value = compute_read_term(row, relation_parameters) * + compute_write_term(row, relation_parameters); + inverse_polynomial.at(i) = value; + } } - } + }); + // Compute inverse polynomial I in place by inverting the product at each row // Note: zeroes are ignored as they are not used anyway FF::batch_invert(inverse_polynomial.coeffs()); @@ -299,8 +310,8 @@ template class DatabusLookupRelationImpl { constexpr size_t subrel_idx_1 = 2 * bus_idx; constexpr size_t subrel_idx_2 = 2 * bus_idx + 1; - // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 - // if !inverse_exists. Degree 3 (5) + // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value + // is 0 if !inverse_exists. Degree 3 (5) std::get(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; // Establish validity of the read. Note: no scaling factor here since this constraint is enforced across the diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index afd1326a91d..d0ccce56dea 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -3,6 +3,7 @@ #include #include "barretenberg/common/constexpr_utils.hpp" +#include "barretenberg/common/thread.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/relations/relation_types.hpp" @@ -157,16 +158,25 @@ template class LogDerivLookupRelationImpl { { auto& inverse_polynomial = get_inverse_polynomial(polynomials); - for (size_t i = 0; i < circuit_size; ++i) { - // We only compute the inverse if this row contains a lookup gate or data that has been looked up - if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. - auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! - auto value = compute_read_term(row, relation_parameters) * - compute_write_term(row, relation_parameters); - inverse_polynomial.at(i) = value; + size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread + size_t num_threads = bb::calculate_num_threads_pow2(circuit_size, min_iterations_per_thread); + size_t iterations_per_thread = circuit_size / num_threads; // actual iterations per thread + + parallel_for(num_threads, [&](size_t thread_idx) { + size_t start = thread_idx * iterations_per_thread; + size_t end = (thread_idx + 1) * iterations_per_thread; + for (size_t i = start; i < end; ++i) { + // We only compute the inverse if this row contains a lookup gate or data that has been looked up + if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. + auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! + auto value = compute_read_term(row, relation_parameters) * + compute_write_term(row, relation_parameters); + inverse_polynomial.at(i) = value; + } } - } + }); + // Compute inverse polynomial I in place by inverting the product at each row FF::batch_invert(inverse_polynomial.coeffs()); }; @@ -233,15 +243,14 @@ template class LogDerivLookupRelationImpl { const auto write_inverse = inverses * read_term; // Degree 3 (4) const auto read_inverse = inverses * write_term; // Degree 2 (3) - // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 - // if !inverse_exists. - // Degrees: 2 (3) 1 (2) 1 1 + // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value + // is 0 if !inverse_exists. Degrees: 2 (3) 1 (2) 1 1 std::get<0>(accumulator) += ShortView((read_term * write_term * inverses - inverse_exists) * scaling_factor); // Deg 4 (6) - // Establish validity of the read. Note: no scaling factor here since this constraint is 'linearly dependent, - // i.e. enforced across the entire trace, not on a per-row basis. - // Degrees: 1 2 (3) 1 3 (4) + // Establish validity of the read. Note: no scaling factor here since this constraint is 'linearly + // dependent, i.e. enforced across the entire trace, not on a per-row basis. Degrees: 1 2 (3) 1 + // 3 (4) std::get<1>(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Deg 4 (5) } }; diff --git a/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp b/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp index f778a03c503..549d42564fd 100644 --- a/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp +++ b/barretenberg/cpp/src/barretenberg/trace_to_polynomials/trace_to_polynomials.cpp @@ -102,7 +102,7 @@ typename TraceToPolynomials::TraceData TraceToPolynomials::const auto block_size = static_cast(block.size()); // Save ranges over which the blocks are "active" for use in structured commitments - if constexpr (IsUltraFlavor) { + if constexpr (IsUltraFlavor) { // Mega and Ultra if (block.size() > 0) { proving_key.active_block_ranges.emplace_back(offset, offset + block.size()); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index 111497e9175..c19a43f8f98 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -206,8 +206,8 @@ template void OinkProver::execute_log_derivative_ { PROFILE_THIS_NAME("COMMIT::lookup_inverses"); - witness_commitments.lookup_inverses = - proving_key->proving_key.commitment_key->commit(proving_key->proving_key.polynomials.lookup_inverses); + witness_commitments.lookup_inverses = proving_key->proving_key.commitment_key->commit_sparse( + proving_key->proving_key.polynomials.lookup_inverses); } transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, witness_commitments.lookup_inverses); From 933f352d9a20b9039df070f44a78e9f925af991e Mon Sep 17 00:00:00 2001 From: maramihali Date: Thu, 5 Dec 2024 11:28:22 +0000 Subject: [PATCH 3/6] remove bench modifications --- .../benchmark/client_ivc_bench/client_ivc.bench.cpp | 2 +- .../relations/logderiv_lookup_relation.hpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp index 7aa1b8910d8..6033648972c 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp @@ -33,7 +33,7 @@ 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(state.range(0)); // 2x accounts for kernel circuits auto mocked_vkeys = mock_verification_keys(total_num_circuits); diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index d0ccce56dea..686b751903c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -243,14 +243,15 @@ template class LogDerivLookupRelationImpl { const auto write_inverse = inverses * read_term; // Degree 3 (4) const auto read_inverse = inverses * write_term; // Degree 2 (3) - // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value - // is 0 if !inverse_exists. Degrees: 2 (3) 1 (2) 1 1 + // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 + // if !inverse_exists. + // Degrees: 2 (3) 1 (2) 1 1 std::get<0>(accumulator) += ShortView((read_term * write_term * inverses - inverse_exists) * scaling_factor); // Deg 4 (6) - // Establish validity of the read. Note: no scaling factor here since this constraint is 'linearly - // dependent, i.e. enforced across the entire trace, not on a per-row basis. Degrees: 1 2 (3) 1 - // 3 (4) + // Establish validity of the read. Note: no scaling factor here since this constraint is 'linearly dependent, + // i.e. enforced across the entire trace, not on a per-row basis. + // Degrees: 1 2 (3) 1 3 (4) std::get<1>(accumulator) += read_selector * read_inverse - read_counts * write_inverse; // Deg 4 (5) } }; From 5ab572921434851e6f7ddd1b37a00500c7a8b421 Mon Sep 17 00:00:00 2001 From: maramihali Date: Thu, 5 Dec 2024 12:05:30 +0000 Subject: [PATCH 4/6] yay --- barretenberg/cpp/scripts/analyze_client_ivc_bench.py | 2 +- .../plonk_honk_shared/library/grand_product_library.hpp | 2 ++ .../barretenberg/relations/databus_lookup_relation.hpp | 8 +++----- .../barretenberg/relations/logderiv_lookup_relation.hpp | 8 +++----- .../barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 9 ++++----- .../cpp/src/barretenberg/ultra_honk/oink_prover.hpp | 7 ++++++- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index c27fab4da7f..aed32cea6e1 100755 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -25,7 +25,7 @@ "execute_log_derivative_inverse_round(t)", "compute_logderivative_inverses(t)", "execute_grand_product_computation_round(t)", -"compute_grand_product_polynomial(t)", +"compute_grand_product(t)", "MegaFlavor::get_row(t)", "logderivative relation(t)", "databus relation(t)", diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp index 58b1d35630a..eab650077e0 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp @@ -58,6 +58,8 @@ void compute_grand_product(typename Flavor::ProverPolynomials& full_polynomials, bb::RelationParameters& relation_parameters, size_t size_override = 0) { + PROFILE_THIS_NAME("compute_grand_product"); + using FF = typename Flavor::FF; using Polynomial = typename Flavor::Polynomial; using Accumulator = std::tuple_element_t<0, typename GrandProdRelation::SumcheckArrayOfValuesOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index 8bc564acce7..bcd9d1a21a6 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -227,11 +227,9 @@ template class DatabusLookupRelationImpl { * */ template - static void compute_logderivative_inverse( - Polynomials& polynomials, - auto& relation_parameters, - const size_t circuit_size, - [[maybe_unused]] const std::vector>& active_block_ranges) + static void compute_logderivative_inverse(Polynomials& polynomials, + auto& relation_parameters, + const size_t circuit_size) { PROFILE_THIS_NAME("databus relation"); auto& inverse_polynomial = BusData::inverses(polynomials); diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index 5ea13d892cc..e68e8a50a18 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -152,11 +152,9 @@ template class LogDerivLookupRelationImpl { * */ template - static void compute_logderivative_inverse( - Polynomials& polynomials, - auto& relation_parameters, - [[maybe_unused]] const size_t circuit_size, - [[maybe_unused]] const std::vector>& active_ranges) + static void compute_logderivative_inverse(Polynomials& polynomials, + auto& relation_parameters, + const size_t circuit_size) { PROFILE_THIS_NAME("logderivative relation"); auto& inverse_polynomial = get_inverse_polynomial(polynomials); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index da95e9fc856..fb7e4c9529f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -496,19 +496,19 @@ class MegaFlavor { // Compute inverses for conventional lookups LogDerivLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); + this->polynomials, relation_parameters, this->circuit_size); // Compute inverses for calldata reads DatabusLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); + this->polynomials, relation_parameters, this->circuit_size); // Compute inverses for secondary_calldata reads DatabusLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); + this->polynomials, relation_parameters, this->circuit_size); // Compute inverses for return data reads DatabusLookupRelation::compute_logderivative_inverse( - this->polynomials, relation_parameters, this->circuit_size, this->active_block_ranges); + this->polynomials, relation_parameters, this->circuit_size); } /** @@ -519,7 +519,6 @@ class MegaFlavor { */ void compute_grand_product_polynomial(RelationParameters& relation_parameters, size_t size_override = 0) { - PROFILE_THIS_NAME("compute_grand_product_polynomial"); relation_parameters.public_input_delta = compute_public_input_delta(this->public_inputs, relation_parameters.beta, relation_parameters.gamma, diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp index 8ab9fed7aa1..e6db742510b 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp @@ -19,6 +19,7 @@ // clang-format on #include +#include "barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp" #include "barretenberg/ultra_honk/decider_proving_key.hpp" namespace bb { @@ -40,16 +41,20 @@ template class OinkProver { std::shared_ptr proving_key; std::shared_ptr transcript; std::string domain_separator; + ExecutionTraceUsageTracker trace_usage_tracker; + typename Flavor::WitnessCommitments witness_commitments; typename Flavor::CommitmentLabels commitment_labels; using RelationSeparator = typename Flavor::RelationSeparator; OinkProver(std::shared_ptr proving_key, const std::shared_ptr& transcript = std::make_shared(), - std::string domain_separator = "") + std::string domain_separator = "", + const ExecutionTraceUsageTracker& trace_usage_tracker = ExecutionTraceUsageTracker{}) : proving_key(proving_key) , transcript(transcript) , domain_separator(std::move(domain_separator)) + , trace_usage_tracker(trace_usage_tracker) {} void prove(); From 3c927aa46b5bb77e1c961649b86045da37aac139 Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 6 Dec 2024 12:55:47 +0000 Subject: [PATCH 5/6] improve execute grand product computation round --- .../cpp/scripts/analyze_client_ivc_bench.py | 27 ++++--- .../client_ivc_bench/client_ivc.bench.cpp | 4 +- .../commitment_schemes/commitment_key.hpp | 61 ++++++++------- .../batched_affine_addition.cpp | 1 + .../barretenberg/ecc/fields/field_impl.hpp | 33 ++++----- .../cpp/src/barretenberg/flavor/flavor.hpp | 2 +- .../execution_trace_usage_tracker.hpp | 1 + .../library/grand_product_library.hpp | 36 ++++++--- .../relations/databus_lookup_relation.hpp | 74 +++++++++---------- .../relations/logderiv_lookup_relation.hpp | 41 +++++----- .../stdlib_circuit_builders/mega_flavor.hpp | 2 +- .../barretenberg/ultra_honk/oink_prover.cpp | 5 +- 12 files changed, 151 insertions(+), 136 deletions(-) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index aed32cea6e1..4feaa6577a6 100755 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -19,21 +19,24 @@ "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_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)", +# "compute_grand_product(t)", "MegaFlavor::get_row(t)", -"logderivative relation(t)", -"databus relation(t)", "fr::batch_invert(t)", -"thish(t)", -"and thish(t)", -"chunk1(t)", -"chunk2(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)", diff --git a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp index 517088579e3..6f189179dd9 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp @@ -33,8 +33,8 @@ class ClientIVCBench : public benchmark::Fixture { */ BENCHMARK_DEFINE_F(ClientIVCBench, Full)(benchmark::State& state) { - ClientIVC ivc{ { EXAMPLE_20 } }; - // ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; + // ClientIVC ivc{ { EXAMPLE_20 } }; + ClientIVC ivc{ { CLIENT_IVC_BENCH_STRUCTURE } }; auto total_num_circuits = 2 * static_cast(state.range(0)); // 2x accounts for kernel circuits auto mocked_vkeys = mock_verification_keys(total_num_circuits); diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp index 6a597e6deb9..d7bd87d9db4 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp @@ -85,7 +85,7 @@ template class CommitmentKey { */ Commitment commit(PolynomialSpan polynomial) { - PROFILE_THIS(); + // PROFILE_THIS(); // 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 @@ -133,7 +133,7 @@ template class CommitmentKey { */ Commitment commit_sparse(PolynomialSpan polynomial) { - PROFILE_THIS(); + // PROFILE_THIS(); const size_t poly_size = polynomial.size(); ASSERT(polynomial.end_index() <= srs->get_monomial_size()); @@ -204,9 +204,10 @@ template class CommitmentKey { * @return Commitment */ Commitment commit_structured(PolynomialSpan polynomial, - const std::vector>& active_ranges) + const std::vector>& active_ranges, + size_t final_active_wire_idx = 0) { - BB_OP_COUNT_TIME(); + // BB_OP_COUNT_TIME(); ASSERT(polynomial.end_index() <= srs->get_monomial_size()); // Percentage of nonzero coefficients beyond which we resort to the conventional commit method @@ -219,7 +220,8 @@ template class CommitmentKey { } // Compute "active" percentage of polynomial; resort to standard commit if appropriate - size_t percentage_nonzero = total_num_scalars * 100 / polynomial.size(); + size_t polynomial_size = final_active_wire_idx != 0 ? final_active_wire_idx : polynomial.size(); + size_t percentage_nonzero = total_num_scalars * 100 / polynomial_size; if (percentage_nonzero > NONZERO_THRESHOLD) { return commit(polynomial); } @@ -260,9 +262,10 @@ template class CommitmentKey { * @return Commitment */ Commitment commit_structured_with_nonzero_complement(PolynomialSpan polynomial, - const std::vector>& active_ranges) + const std::vector>& active_ranges, + size_t final_active_wire_idx = 0) { - BB_OP_COUNT_TIME(); + PROFILE_THIS_NAME("total"); ASSERT(polynomial.end_index() <= srs->get_monomial_size()); using BatchedAddition = BatchedAffineAddition; @@ -274,20 +277,22 @@ template 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> active_ranges_complement; + // Compute the 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; - active_ranges_complement.emplace_back(start, end); - } - - // Compute the total number of scalars in the constant regions - size_t total_num_complement_scalars = 0; - for (const auto& range : active_ranges_complement) { - total_num_complement_scalars += range.second - range.first; + if (end > start) { + active_ranges_complement.emplace_back(start, end); + total_num_complement_scalars += end - start; + } } + size_t polynomial_size = final_active_wire_idx != 0 ? final_active_wire_idx : polynomial.size(); // Compute percentage of polynomial comprised of constant blocks; resort to standard commit if appropriate - size_t percentage_constant = total_num_complement_scalars * 100 / polynomial.size(); + size_t percentage_constant = total_num_complement_scalars * 100 / polynomial_size; + if (percentage_constant < CONSTANT_THRESHOLD) { return commit(polynomial); } @@ -298,14 +303,14 @@ template 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 points; - points.reserve(2 * total_num_complement_scalars); - for (const auto& range : active_ranges_complement) { - const size_t start = 2 * range.first; - const size_t end = 2 * range.second; - for (size_t i = start; i < end; i += 2) { - points.emplace_back(point_table[i]); + + points.reserve(total_num_complement_scalars); + for (const auto& [start, end] : active_ranges_complement) { + for (size_t i = start; i < end; i++) { + points.emplace_back(point_table[2 * i]); } } @@ -314,17 +319,17 @@ template class CommitmentKey { std::vector unique_scalars; std::vector sequence_counts; for (const auto& range : active_ranges_complement) { - if (range.second - range.first > 0) { // only ranges with nonzero length - unique_scalars.emplace_back(polynomial.span[range.first]); - sequence_counts.emplace_back(range.second - range.first); - } + unique_scalars.emplace_back(polynomial.span[range.first]); + sequence_counts.emplace_back(range.second - range.first); } // 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 - Commitment result = commit_structured(polynomial, active_ranges); + // 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)) { result = result + point * scalar; } diff --git a/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp b/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp index 447e6039c55..dc6b3022fe9 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp @@ -10,6 +10,7 @@ template std::vector::G1> BatchedAffineAddition::add_in_place( const std::span& points, const std::vector& sequence_counts) { + PROFILE_THIS_NAME("add_in_place"); // Instantiate scratch space for point addition denominators and their calculation std::vector scratch_space_vector(points.size()); std::span scratch_space(scratch_space_vector); diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp index e6a559e2030..a5126513f77 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp @@ -404,6 +404,7 @@ template void field::batch_invert(field* coeffs, const size_t n) no batch_invert(std::span{ coeffs, n }); } +// TODO(https://github.com/AztecProtocol/barretenberg/issues/1166) template void field::batch_invert(std::span coeffs) noexcept { PROFILE_THIS_NAME("fr::batch_invert"); @@ -415,16 +416,14 @@ template void field::batch_invert(std::span coeffs) noexcept auto* skipped = skipped_ptr.get(); field accumulator = one(); - { - PROFILE_THIS_NAME("thish"); - for (size_t i = 0; i < n; ++i) { - temporaries[i] = accumulator; - if (coeffs[i].is_zero()) { - skipped[i] = true; - } else { - skipped[i] = false; - accumulator *= coeffs[i]; - } + + for (size_t i = 0; i < n; ++i) { + temporaries[i] = accumulator; + if (coeffs[i].is_zero()) { + skipped[i] = true; + } else { + skipped[i] = false; + accumulator *= coeffs[i]; } } @@ -447,14 +446,12 @@ template void field::batch_invert(std::span coeffs) noexcept accumulator = accumulator.invert(); field T0; - { - PROFILE_THIS_NAME("and thish"); - for (size_t i = n - 1; i < n; --i) { - if (!skipped[i]) { - T0 = accumulator * temporaries[i]; - accumulator *= coeffs[i]; - coeffs[i] = T0; - } + + for (size_t i = n - 1; i < n; --i) { + if (!skipped[i]) { + T0 = accumulator * temporaries[i]; + accumulator *= coeffs[i]; + coeffs[i] = T0; } } } diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index b9230e4675a..98bdd4b8d51 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -123,7 +123,7 @@ template class ProvingKey_ { // folded element by element. std::vector public_inputs; - // Ranges of the form [start, end) over which the execution trace is "active" + // Ranges of the form [start, end) where witnesses have nontrivial values (hence the execution trace is "active") std::vector> active_block_ranges; ProvingKey_() = default; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp index 683a20a3d63..91837b267dd 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/execution_trace/execution_trace_usage_tracker.hpp @@ -22,6 +22,7 @@ struct ExecutionTraceUsageTracker { MegaTraceFixedBlockSizes fixed_sizes; // fixed size of each block prescribed by structuring // Store active ranges based on the most current accumulator and those based on all but the most recently // accumulated circuit. The former is needed for the combiner calculation and the latter for the perturbator. + // The ranges cover all areas in the trace where relations have nontrivial values. std::vector active_ranges; std::vector previous_active_ranges; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp index eab650077e0..f68826178f3 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp @@ -56,7 +56,8 @@ namespace bb { template void compute_grand_product(typename Flavor::ProverPolynomials& full_polynomials, bb::RelationParameters& relation_parameters, - size_t size_override = 0) + size_t size_override = 0, + std::vector> active_block_ranges = {}) { PROFILE_THIS_NAME("compute_grand_product"); @@ -68,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; - const size_t num_threads = domain_size >= get_num_cpus_pow2() ? get_num_cpus_pow2() : 1; + 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; @@ -86,22 +87,34 @@ void compute_grand_product(typename Flavor::ProverPolynomials& full_polynomials, Polynomial numerator{ domain_size, domain_size }; Polynomial denominator{ domain_size, domain_size }; + auto check_is_active = [&](size_t idx) { + if (active_block_ranges.empty()) { + return true; + } + return std::any_of(active_block_ranges.begin(), active_block_ranges.end(), [idx](const auto& range) { + return idx >= range.first && idx < range.second; + }); + }; + // Step (1) // Populate `numerator` and `denominator` with the algebra described by Relation + FF gamma_fourth = relation_parameters.gamma.pow(4); parallel_for(num_threads, [&](size_t thread_idx) { - typename Flavor::AllValues evaluations; - // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): construction of evaluations is equivalent to - // calling get_row which creates full copies. avoid? + typename Flavor::AllValues row; const size_t start = idx_bounds[thread_idx].first; const size_t end = idx_bounds[thread_idx].second; for (size_t i = start; i < end; ++i) { - for (auto [eval, full_poly] : zip_view(evaluations.get_all(), full_polynomials.get_all())) { - eval = full_poly.size() > i ? full_poly[i] : 0; + if (check_is_active(i)) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940):consider avoiding get_row if possible. + row = full_polynomials.get_row(i); + numerator.at(i) = + GrandProdRelation::template compute_grand_product_numerator(row, relation_parameters); + denominator.at(i) = GrandProdRelation::template compute_grand_product_denominator( + row, relation_parameters); + } else { + numerator.at(i) = gamma_fourth; + denominator.at(i) = gamma_fourth; } - numerator.at(i) = GrandProdRelation::template compute_grand_product_numerator( - evaluations, relation_parameters); - denominator.at(i) = GrandProdRelation::template compute_grand_product_denominator( - evaluations, relation_parameters); } }); @@ -165,6 +178,7 @@ void compute_grand_product(typename Flavor::ProverPolynomials& full_polynomials, auto& grand_product_polynomial = GrandProdRelation::get_grand_product_polynomial(full_polynomials); // We have a 'virtual' 0 at the start (as this is a to-be-shifted polynomial) ASSERT(grand_product_polynomial.start_index() == 1); + parallel_for(num_threads, [&](size_t thread_idx) { const size_t start = idx_bounds[thread_idx].first; const size_t end = idx_bounds[thread_idx].second; diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index bcd9d1a21a6..d51062f991f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -231,47 +231,43 @@ template class DatabusLookupRelationImpl { auto& relation_parameters, const size_t circuit_size) { - PROFILE_THIS_NAME("databus relation"); + PROFILE_THIS_NAME("Databus::compute_logderivative_inverse"); auto& inverse_polynomial = BusData::inverses(polynomials); - { - PROFILE_THIS_NAME("chunk2"); - - size_t min_iterations_per_thread = 1 - << 6; // min number of iterations for which we'll spin up a unique thread - size_t num_threads = bb::calculate_num_threads_pow2(circuit_size, min_iterations_per_thread); - size_t iterations_per_thread = circuit_size / num_threads; // actual iterations per thread - - parallel_for(num_threads, [&](size_t thread_idx) { - size_t start = thread_idx * iterations_per_thread; - size_t end = (thread_idx + 1) * iterations_per_thread; - bool is_read = false; - bool nonzero_read_count = false; - for (size_t i = start; i < end; ++i) { - // Determine if the present row contains a databus operation - auto q_busread = polynomials.q_busread[i]; - if constexpr (bus_idx == 0) { // calldata - is_read = q_busread == 1 && polynomials.q_l[i] == 1; - nonzero_read_count = polynomials.calldata_read_counts[i] > 0; - } - if constexpr (bus_idx == 1) { // secondary_calldata - is_read = q_busread == 1 && polynomials.q_r[i] == 1; - nonzero_read_count = polynomials.secondary_calldata_read_counts[i] > 0; - } - if constexpr (bus_idx == 2) { // return data - is_read = q_busread == 1 && polynomials.q_o[i] == 1; - nonzero_read_count = polynomials.return_data_read_counts[i] > 0; - } - // We only compute the inverse if this row contains a read gate or data that has been read - if (is_read || nonzero_read_count) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. - auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! - auto value = compute_read_term(row, relation_parameters) * - compute_write_term(row, relation_parameters); - inverse_polynomial.at(i) = value; - } + + size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread + size_t num_threads = bb::calculate_num_threads_pow2(circuit_size, min_iterations_per_thread); + size_t iterations_per_thread = circuit_size / num_threads; // actual iterations per thread + + parallel_for(num_threads, [&](size_t thread_idx) { + size_t start = thread_idx * iterations_per_thread; + size_t end = (thread_idx + 1) * iterations_per_thread; + bool is_read = false; + bool nonzero_read_count = false; + for (size_t i = start; i < end; ++i) { + // Determine if the present row contains a databus operation + auto q_busread = polynomials.q_busread[i]; + if constexpr (bus_idx == 0) { // calldata + is_read = q_busread == 1 && polynomials.q_l[i] == 1; + nonzero_read_count = polynomials.calldata_read_counts[i] > 0; + } + if constexpr (bus_idx == 1) { // secondary_calldata + is_read = q_busread == 1 && polynomials.q_r[i] == 1; + nonzero_read_count = polynomials.secondary_calldata_read_counts[i] > 0; + } + if constexpr (bus_idx == 2) { // return data + is_read = q_busread == 1 && polynomials.q_o[i] == 1; + nonzero_read_count = polynomials.return_data_read_counts[i] > 0; } - }); - } + // We only compute the inverse if this row contains a read gate or data that has been read + if (is_read || nonzero_read_count) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. + auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! + auto value = compute_read_term(row, relation_parameters) * + compute_write_term(row, relation_parameters); + inverse_polynomial.at(i) = value; + } + } + }); // Compute inverse polynomial I in place by inverting the product at each row // Note: zeroes are ignored as they are not used anyway diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index e68e8a50a18..dbd45cc2ed5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -156,32 +156,27 @@ template class LogDerivLookupRelationImpl { auto& relation_parameters, const size_t circuit_size) { - PROFILE_THIS_NAME("logderivative relation"); + PROFILE_THIS_NAME("Lookup::compute_logderivative_inverse"); auto& inverse_polynomial = get_inverse_polynomial(polynomials); - { - PROFILE_THIS_NAME("chunk1"); - - size_t min_iterations_per_thread = 1 - << 6; // min number of iterations for which we'll spin up a unique thread - size_t num_threads = bb::calculate_num_threads_pow2(circuit_size, min_iterations_per_thread); - size_t iterations_per_thread = circuit_size / num_threads; // actual iterations per thread - - parallel_for(num_threads, [&](size_t thread_idx) { - size_t start = thread_idx * iterations_per_thread; - size_t end = (thread_idx + 1) * iterations_per_thread; - for (size_t i = start; i < end; ++i) { - // We only compute the inverse if this row contains a lookup gate or data that has been looked up - if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. - auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! - auto value = compute_read_term(row, relation_parameters) * - compute_write_term(row, relation_parameters); - inverse_polynomial.at(i) = value; - } + size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread + size_t num_threads = bb::calculate_num_threads_pow2(circuit_size, min_iterations_per_thread); + size_t iterations_per_thread = circuit_size / num_threads; // actual iterations per thread + + parallel_for(num_threads, [&](size_t thread_idx) { + size_t start = thread_idx * iterations_per_thread; + size_t end = (thread_idx + 1) * iterations_per_thread; + for (size_t i = start; i < end; ++i) { + // We only compute the inverse if this row contains a lookup gate or data that has been looked up + if (polynomials.q_lookup.get(i) == 1 || polynomials.lookup_read_tags.get(i) == 1) { + // TODO(https://github.com/AztecProtocol/barretenberg/issues/940): avoid get_row if possible. + auto row = polynomials.get_row(i); // Note: this is a copy. use sparingly! + auto value = compute_read_term(row, relation_parameters) * + compute_write_term(row, relation_parameters); + inverse_polynomial.at(i) = value; } - }); - } + } + }); // Compute inverse polynomial I in place by inverting the product at each row FF::batch_invert(inverse_polynomial.coeffs()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index fb7e4c9529f..24919feb257 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -527,7 +527,7 @@ class MegaFlavor { // Compute permutation grand product polynomial compute_grand_product>( - this->polynomials, relation_parameters, size_override); + this->polynomials, relation_parameters, size_override, this->active_block_ranges); } uint64_t estimate_memory() diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index c394d0392c3..48a5f7430d7 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -239,12 +239,15 @@ template void OinkProver::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()) { witness_commitments.z_perm = proving_key->proving_key.commitment_key->commit_structured_with_nonzero_complement( - proving_key->proving_key.polynomials.z_perm, proving_key->proving_key.active_block_ranges); + proving_key->proving_key.polynomials.z_perm, + proving_key->proving_key.active_block_ranges, + proving_key->final_active_wire_idx + 1); } else { witness_commitments.z_perm = proving_key->proving_key.commitment_key->commit(proving_key->proving_key.polynomials.z_perm); From b5c19b77b3e86635e978f9dd3ad3789e19ec2a85 Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 6 Dec 2024 14:18:07 +0000 Subject: [PATCH 6/6] cleanup --- .../cpp/scripts/analyze_client_ivc_bench.py | 29 ++++--------------- .../client_ivc_bench/client_ivc.bench.cpp | 1 - .../commitment_schemes/commitment_key.hpp | 21 ++++++-------- .../batched_affine_addition.cpp | 2 +- .../barretenberg/ecc/fields/field_impl.hpp | 2 -- .../cpp/src/barretenberg/flavor/flavor.hpp | 2 +- .../library/grand_product_library.hpp | 2 +- .../stdlib_circuit_builders/ultra_flavor.hpp | 2 +- .../barretenberg/ultra_honk/oink_prover.cpp | 1 - 9 files changed, 18 insertions(+), 44 deletions(-) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index 4feaa6577a6..600854679c5 100755 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -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: diff --git a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp index 6f189179dd9..6033648972c 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/client_ivc_bench/client_ivc.bench.cpp @@ -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(state.range(0)); // 2x accounts for kernel circuits diff --git a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp index d7bd87d9db4..81ef54a2b9d 100644 --- a/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp +++ b/barretenberg/cpp/src/barretenberg/commitment_schemes/commitment_key.hpp @@ -85,7 +85,7 @@ template class CommitmentKey { */ Commitment commit(PolynomialSpan 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 @@ -133,7 +133,7 @@ template class CommitmentKey { */ Commitment commit_sparse(PolynomialSpan polynomial) { - // PROFILE_THIS(); + PROFILE_THIS_NAME("commit_sparse"); const size_t poly_size = polynomial.size(); ASSERT(polynomial.end_index() <= srs->get_monomial_size()); @@ -207,7 +207,7 @@ template class CommitmentKey { const std::vector>& 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 @@ -215,8 +215,8 @@ template class CommitmentKey { // 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 @@ -265,7 +265,7 @@ template class CommitmentKey { const std::vector>& 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; @@ -277,9 +277,8 @@ template 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> 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; @@ -303,8 +302,7 @@ template 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 points; points.reserve(total_num_complement_scalars); @@ -326,8 +324,7 @@ template 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)) { diff --git a/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp b/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp index dc6b3022fe9..058bce37738 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/batched_affine_addition/batched_affine_addition.cpp @@ -10,7 +10,7 @@ template std::vector::G1> BatchedAffineAddition::add_in_place( const std::span& points, const std::vector& 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 scratch_space_vector(points.size()); std::span scratch_space(scratch_space_vector); diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp index a5126513f77..5a747150eb1 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_impl.hpp @@ -416,7 +416,6 @@ template void field::batch_invert(std::span 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()) { @@ -446,7 +445,6 @@ template void field::batch_invert(std::span coeffs) noexcept accumulator = accumulator.invert(); field T0; - for (size_t i = n - 1; i < n; --i) { if (!skipped[i]) { T0 = accumulator * temporaries[i]; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 98bdd4b8d51..e6fe7ef2aa3 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -123,7 +123,7 @@ template class ProvingKey_ { // folded element by element. std::vector 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> active_block_ranges; ProvingKey_() = default; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp index f68826178f3..ee7eeb3c437 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/library/grand_product_library.hpp @@ -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; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index feffc7e53c8..f34d0b48733 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -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]; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index 48a5f7430d7..7377c7b31c7 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -239,7 +239,6 @@ template void OinkProver::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()) {