From f086573a75b133e7408ef4d9bdca50d07666024b Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 30 Apr 2024 00:43:26 +0000 Subject: [PATCH 01/18] make structure more flexible --- .../client_ivc_bench/client_ivc.bench.cpp | 37 ++++++ .../barretenberg/client_ivc/client_ivc.cpp | 3 +- .../barretenberg/client_ivc/client_ivc.hpp | 2 + .../execution_trace/execution_trace.cpp | 2 +- .../arithmetization/arithmetization.hpp | 106 +++++++++++++++--- .../barretenberg/relations/relation_types.hpp | 2 +- .../standard_circuit_builder.hpp | 1 - .../ultra_circuit_builder.hpp | 1 - .../sumcheck/instance/prover_instance.hpp | 7 +- .../barretenberg/sumcheck/sumcheck_round.hpp | 2 +- 10 files changed, 139 insertions(+), 24 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 dcbcd0c39a5f..e630efcfe0ef 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 @@ -173,6 +173,25 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Full)(benchmark::State& state) } } +/** + * @brief Benchmark the prover work for the full PG-Goblin IVC protocol + * + */ +BENCHMARK_DEFINE_F(ClientIVCBench, FullStructured)(benchmark::State& state) +{ + ClientIVC ivc; + ivc.structured_flag = true; + ivc.precompute_folding_verification_keys(); + for (auto _ : state) { + BB_REPORT_OP_COUNT_IN_BENCH(state); + // Perform a specified number of iterations of function/kernel accumulation + perform_ivc_accumulation_rounds(state, ivc); + + // Construct IVC scheme proof (fold, decider, merge, eccvm, translator) + ivc.prove(); + } +} + /** * @brief Benchmark only the accumulation rounds * @@ -188,6 +207,22 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Accumulate)(benchmark::State& state) } } +/** + * @brief Benchmark only the accumulation rounds + * + */ +BENCHMARK_DEFINE_F(ClientIVCBench, AccumulateStructured)(benchmark::State& state) +{ + ClientIVC ivc; + ivc.structured_flag = true; + ivc.precompute_folding_verification_keys(); + // Perform a specified number of iterations of function/kernel accumulation + for (auto _ : state) { + BB_REPORT_OP_COUNT_IN_BENCH(state); + perform_ivc_accumulation_rounds(state, ivc); + } +} + /** * @brief Benchmark only the Decider component * @@ -252,7 +287,9 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Translator)(benchmark::State& state) ->Arg(1 << 6) BENCHMARK_REGISTER_F(ClientIVCBench, Full)->Unit(benchmark::kMillisecond)->ARGS; +BENCHMARK_REGISTER_F(ClientIVCBench, FullStructured)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, Accumulate)->Unit(benchmark::kMillisecond)->ARGS; +BENCHMARK_REGISTER_F(ClientIVCBench, AccumulateStructured)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, Decide)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, ECCVM)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, Translator)->Unit(benchmark::kMillisecond)->ARGS; diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index eef0001e0c2a..0559c7fe3165 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -24,7 +24,8 @@ void ClientIVC::initialize(ClientCircuit& circuit) ClientIVC::FoldProof ClientIVC::accumulate(ClientCircuit& circuit) { goblin.merge(circuit); // Add recursive merge verifier and construct new merge proof - prover_instance = std::make_shared(circuit); + prover_instance = std::make_shared(circuit, structured_flag); + // circuit.blocks.summarize(); FoldingProver folding_prover({ prover_fold_output.accumulator, prover_instance }); prover_fold_output = folding_prover.fold_instances(); return prover_fold_output.folding_data; diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp index f2e0ee309c3b..71f8837d2029 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp @@ -63,6 +63,8 @@ class ClientIVC { // be needed in the real IVC as they are provided as inputs std::shared_ptr prover_instance; + bool structured_flag = false; + void initialize(ClientCircuit& circuit); FoldProof accumulate(ClientCircuit& circuit); diff --git a/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp b/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp index d582089921ec..286728ca1468 100644 --- a/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/execution_trace/execution_trace.cpp @@ -118,7 +118,7 @@ typename ExecutionTrace_::TraceData ExecutionTrace_::construct_t // If the trace is structured, we populate the data from the next block at a fixed block size offset if (is_structured) { - offset += builder.FIXED_BLOCK_SIZE; + offset += block.get_fixed_size(); } else { // otherwise, the next block starts immediately following the previous one offset += block_size; } diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp index c864af55e7c9..508fa33ef777 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp @@ -51,6 +51,8 @@ template class ExecutionTr bool has_ram_rom = false; // does the block contain RAM/ROM gates bool is_pub_inputs = false; // is this the public inputs block + size_t fixed_size; // Fixed size for use in structured trace + bool operator==(const ExecutionTraceBlock& other) const = default; size_t size() const { return std::get<0>(this->wires).size(); } @@ -64,6 +66,9 @@ template class ExecutionTr p.reserve(size_hint); } } + + size_t get_fixed_size() const { return fixed_size; } + void set_fixed_size(size_t size_in) { fixed_size = size_in; } }; // These are not magic numbers and they should not be written with global constants. These parameters are not @@ -119,7 +124,7 @@ template class UltraArith { public: static constexpr size_t NUM_WIRES = 4; static constexpr size_t NUM_SELECTORS = 11; - static constexpr size_t FIXED_BLOCK_SIZE = 1 << 10; // Size of each block in a structured trace (arbitrary for now) + static constexpr size_t FIXED_BLOCK_SIZE = 1 << 3; // Size of each block in a structured trace (arbitrary for now) using FF = FF_; class UltraTraceBlock : public ExecutionTraceBlock { @@ -158,10 +163,23 @@ template class UltraArith { UltraTraceBlock aux; UltraTraceBlock lookup; + std::array fixed_block_sizes{ + 1 << 3, // pub_inputs; + FIXED_BLOCK_SIZE, // arithmetic; + FIXED_BLOCK_SIZE, // delta_range; + FIXED_BLOCK_SIZE, // elliptic; + FIXED_BLOCK_SIZE, // aux; + FIXED_BLOCK_SIZE // lookup; + }; + TraceBlocks() { aux.has_ram_rom = true; pub_inputs.is_pub_inputs = true; + // Set fixed block sizes for use in structured trace + for (auto [block, size] : zip_view(this->get(), fixed_block_sizes)) { + block.set_fixed_size(size); + } } auto get() { return RefArray{ pub_inputs, arithmetic, delta_range, elliptic, aux, lookup }; } @@ -178,6 +196,31 @@ template class UltraArith { info(""); } + size_t get_total_structured_size() + { + size_t total_size = 0; + for (auto block : this->get()) { + total_size += block.get_fixed_size(); + } + return total_size; + } + + /** + * @brief Check that the number of rows poulated in each block does not exceed the specified fixed size + * @note This check is only applicable when utilizing a structured trace + * + */ + void check_within_fixed_sizes() + { + for (auto block : this->get()) { + if (block.size() > block.get_fixed_size()) { + info("WARNING: Num gates in circuit block exceeds the specified fixed size - execution trace will " + "not be constructed correctly!"); + ASSERT(false); + } + } + } + bool operator==(const TraceBlocks& other) const = default; }; @@ -197,7 +240,7 @@ template class UltraHonkArith { public: static constexpr size_t NUM_WIRES = 4; static constexpr size_t NUM_SELECTORS = 14; - static constexpr size_t FIXED_BLOCK_SIZE = 1 << 10; // Size of each block in a structured trace (arbitrary for now) + static constexpr size_t FIXED_BLOCK_SIZE = 1 << 15; // Size of each block in a structured trace (arbitrary for now) using FF = FF_; @@ -270,10 +313,27 @@ template class UltraHonkArith { UltraHonkTraceBlock poseidon_external; UltraHonkTraceBlock poseidon_internal; + std::array fixed_block_sizes{ + 1 << 10, // ecc_op; + 1 << 7, // pub_inputs; + 1 << 16, // arithmetic; + 1 << 15, // delta_range; + 1 << 14, // elliptic; + 1 << 16, // aux; + 1 << 15, // lookup; + 1 << 7, // busread; + 1 << 11, // poseidon_external; + 1 << 14 // poseidon_internal; + }; + TraceBlocks() { aux.has_ram_rom = true; pub_inputs.is_pub_inputs = true; + // Set fixed block sizes for use in structiured trace + for (auto [block, size] : zip_view(this->get(), fixed_block_sizes)) { + block.set_fixed_size(size); + } } auto get() @@ -284,20 +344,40 @@ template class UltraHonkArith { void summarize() const { - info("Gate blocks summary:"); - info("goblin ecc op:\t", ecc_op.size()); - info("pub inputs:\t", pub_inputs.size()); - info("arithmetic:\t", arithmetic.size()); - info("delta range:\t", delta_range.size()); - info("elliptic:\t", elliptic.size()); - info("auxiliary:\t", aux.size()); - info("lookups:\t", lookup.size()); - info("busread:\t", busread.size()); - info("poseidon ext:\t", poseidon_external.size()); - info("poseidon int:\t", poseidon_internal.size()); + info("Gate blocks summary: (size/capacity)"); + info("goblin ecc op:\t", ecc_op.size(), "/", ecc_op.get_fixed_size()); + info("pub inputs:\t", pub_inputs.size(), "/", pub_inputs.get_fixed_size()); + info("arithmetic:\t", arithmetic.size(), "/", arithmetic.get_fixed_size()); + info("delta range:\t", delta_range.size(), "/", delta_range.get_fixed_size()); + info("elliptic:\t\t", elliptic.size(), "/", elliptic.get_fixed_size()); + info("auxiliary:\t\t", aux.size(), "/", aux.get_fixed_size()); + info("lookups:\t\t", lookup.size(), "/", lookup.get_fixed_size()); + info("busread:\t\t", busread.size(), "/", busread.get_fixed_size()); + info("poseidon ext:\t", poseidon_external.size(), "/", poseidon_external.get_fixed_size()); + info("poseidon int:\t", poseidon_internal.size(), "/", poseidon_internal.get_fixed_size()); info(""); } + size_t get_total_structured_size() + { + size_t total_size = 0; + for (auto block : this->get()) { + total_size += block.get_fixed_size(); + } + return total_size; + } + + void check_within_fixed_sizes() + { + for (auto block : this->get()) { + if (block.size() > block.get_fixed_size()) { + info("WARNING: Num gates in circuit block exceeds the specified fixed size - execution trace will " + "not be constructed correctly!"); + ASSERT(false); + } + } + } + bool operator==(const TraceBlocks& other) const = default; }; diff --git a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp index aa4ba8820b7c..e134c4e03413 100644 --- a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp @@ -122,7 +122,7 @@ consteval std::array compute_composed_subrelation_part template concept isSkippable = requires(const AllEntities& input) { { - Relation::is_active(input) + Relation::skip(input) } -> std::same_as; }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.hpp index a421a10adaa1..e6ede171ffa8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.hpp @@ -15,7 +15,6 @@ template class StandardCircuitBuilder_ : public CircuitBuilderBase using Arithmetization = StandardArith; using GateBlocks = typename Arithmetization::TraceBlocks; static constexpr size_t NUM_WIRES = Arithmetization::NUM_WIRES; - static constexpr size_t FIXED_BLOCK_SIZE = 0; // not used, for compatibility only // Keeping NUM_WIRES, at least temporarily, for backward compatibility static constexpr size_t program_width = Arithmetization::NUM_WIRES; static constexpr size_t num_selectors = Arithmetization::NUM_SELECTORS; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index 90dde82d76c0..feecbf0938d4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -33,7 +33,6 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase class ProverInstance_ { circuit.finalize_circuit(); // If using a structured trace, ensure that no block exceeds the fixed size if (is_structured) { - for (auto& block : circuit.blocks.get()) { - ASSERT(block.size() <= circuit.FIXED_BLOCK_SIZE); - } + circuit.blocks.check_within_fixed_sizes(); } // TODO(https://github.com/AztecProtocol/barretenberg/issues/905): This is adding ops to the op queue but NOT to @@ -109,8 +107,7 @@ template class ProverInstance_ { */ size_t compute_structured_dyadic_size(Circuit& builder) { - size_t num_blocks = builder.blocks.get().size(); - size_t minimum_size = num_blocks * builder.FIXED_BLOCK_SIZE; + size_t minimum_size = builder.blocks.get_total_structured_size(); return builder.get_circuit_subgroup_size(minimum_size); } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index de237e915de3..c1ac763379ab 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -245,7 +245,7 @@ template class SumcheckProverRound { std::get(univariate_accumulators), extended_edges, relation_parameters, scaling_factor); } else { // If so, only compute the contribution if the relation is active - if (!Relation::skip(extended_edges, relation_parameters)) { + if (!Relation::skip(extended_edges)) { Relation::accumulate(std::get(univariate_accumulators), extended_edges, relation_parameters, From 00988a5731bcc5e0d0bd44d92a920f3759ed29b8 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 30 Apr 2024 00:52:19 +0000 Subject: [PATCH 02/18] turn on skipping in PG plus skip methods for gob ecc and databus --- .../protogalaxy/protogalaxy_prover.hpp | 25 +++++++++++++++++-- .../relations/databus_lookup_relation.hpp | 8 ++++++ .../relations/ecc_op_queue_relation.hpp | 6 +++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index d9cffcca9c70..b916cdb98505 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -289,8 +289,28 @@ template class ProtoGalaxyProver_ { const FF& scaling_factor) { using Relation = std::tuple_element_t; - Relation::accumulate( - std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); + + // Check if the relation is skippable to speed up accumulation + if constexpr (!isSkippable) { + // info("NOT SKIPPABLE!"); + // If not, accumulate normally + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } else { + // info("SKIPPABLE!"); + // If so, only compute the contribution if the relation is active + if (!Relation::skip(extended_univariates)) { + // info("NOT skipping!", relation_idx); + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } else { + // info("Skipping!", relation_idx); + } + } // Repeat for the next relation. if constexpr (relation_idx + 1 < Flavor::NUM_RELATIONS) { @@ -330,6 +350,7 @@ template class ProtoGalaxyProver_ { extended_univariates.resize(num_threads); // Accumulate the contribution from each sub-relation + // num_threads = 1; 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; diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index 7a68d156b38d..5c74773f955d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -63,6 +63,14 @@ template class DatabusLookupRelationImpl { true, false, true, false }; + template inline static bool skip([[maybe_unused]] const AllEntities& in) + { + // WORKTODO: comments + return in.q_busread.value_at(0).is_zero() && in.q_busread.value_at(1).is_zero() && + in.calldata_read_counts.value_at(0).is_zero() && in.calldata_read_counts.value_at(1).is_zero() && + in.return_data_read_counts.value_at(0).is_zero() && in.return_data_read_counts.value_at(1).is_zero(); + } + // Interface for easy access of databus components by column (bus_idx) template struct BusData; diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp index faf2f0da162d..f374bf4ccdfd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp @@ -18,6 +18,12 @@ template class EccOpQueueRelationImpl { 3 // op-queue-wire vanishes sub-relation 4 }; + template inline static bool skip([[maybe_unused]] const AllEntities& in) + { + // WORKTODO: comments + return in.lagrange_ecc_op.value_at(0).is_zero() && in.lagrange_ecc_op.value_at(1).is_zero(); + } + /** * @brief Expression for the generalized permutation sort gate. * @details The relation is defined as C(in(X)...) = From f42733875ce0ab882d16aa3fffae3f2f1e103c19 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 30 Apr 2024 18:16:30 +0000 Subject: [PATCH 03/18] update relations bench with sumcheck and pg univariate numbers --- .../relations_bench/relations.bench.cpp | 131 +++++++++++++----- 1 file changed, 100 insertions(+), 31 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 48959e431e9b..3744ba9d6e82 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -1,4 +1,5 @@ #include "barretenberg/eccvm/eccvm_flavor.hpp" +#include "barretenberg/protogalaxy/protogalaxy_prover.hpp" #include "barretenberg/stdlib_circuit_builders/goblin_ultra_flavor.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include "barretenberg/translator_vm/goblin_translator_flavor.hpp" @@ -13,46 +14,114 @@ namespace bb::benchmark::relations { using Fr = bb::fr; using Fq = grumpkin::fr; -template void execute_relation(::benchmark::State& state) +template void execute_relation_for_values(::benchmark::State& state) { using FF = typename Flavor::FF; - using AllValues = typename Flavor::AllValues; - using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; + using Input = typename Flavor::AllValues; + using Accumulator = typename Relation::SumcheckArrayOfValuesOverSubrelations; auto params = bb::RelationParameters::get_random(); - // Extract an array containing all the polynomial evaluations at a given row i - AllValues new_value{}; - // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to zero - SumcheckArrayOfValuesOverSubrelations accumulator; - // Evaluate each constraint in the relation and check that each is satisfied + // Instantiate zero-initialized inputs and accumulator + Input input_values{}; + Accumulator accumulator; for (auto _ : state) { - Relation::accumulate(accumulator, new_value, params, 1); + Relation::accumulate(accumulator, input_values, params, 1); } } -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); - -BENCHMARK(execute_relation>); - -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); - -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); -BENCHMARK(execute_relation>); + +template void execute_relation_for_univariates(::benchmark::State& state) +{ + using FF = typename Flavor::FF; + using Input = typename Flavor::ExtendedEdges; + using Accumulator = typename Relation::SumcheckTupleOfUnivariatesOverSubrelations; + + auto params = bb::RelationParameters::get_random(); + + // Instantiate zero-initialized inputs and accumulator + Input input_univariates{}; + Accumulator accumulator; + + for (auto _ : state) { + Relation::accumulate(accumulator, input_univariates, params, 1); + } +} + +template void execute_relation_for_univariates_pg(::benchmark::State& state) +{ + using FF = typename Flavor::FF; + using ProverInstances = ProverInstances_; + using ProtoGalaxyProver = ProtoGalaxyProver_; + using Input = ProtoGalaxyProver::ExtendedUnivariates; + using Accumulator = typename Relation::template ProtogalaxyTupleOfUnivariatesOverSubrelations; + + auto params = bb::RelationParameters::get_random(); + + // Instantiate zero-initialized inputs and accumulator + Input input_univariates{}; + Accumulator accumulator; + + for (auto _ : state) { + Relation::accumulate(accumulator, input_univariates, params, 1); + } +} + +// Ultra relations (PG prover work) +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); + +// Goblin-Ultra only relations (PG prover work) +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); +BENCHMARK(execute_relation_for_univariates_pg>); + +// Ultra relations (Sumcheck prover work) +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); + +// Goblin-Ultra only relations (Sumcheck prover work) +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); +BENCHMARK(execute_relation_for_univariates>); + +// Ultra relations (verifier work) +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); + +// Goblin-Ultra only relations (verifier work) +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); + +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); + +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); +BENCHMARK(execute_relation_for_values>); } // namespace bb::benchmark::relations From 6c0aba7a68bd26c8201090799da6af3865668323 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 30 Apr 2024 18:40:29 +0000 Subject: [PATCH 04/18] fixed block size cleanuop and comment --- .../arithmetization/arithmetization.hpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp index 508fa33ef777..a22b965e5ab1 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp @@ -313,6 +313,11 @@ template class UltraHonkArith { UltraHonkTraceBlock poseidon_external; UltraHonkTraceBlock poseidon_internal; + // This is a set of fixed block sizes that accomodates the circuits currently processed in the ClientIvc bench. + // Note 1: The individual block sizes do NOT need to be powers of 2, this is just for conciseness. + // Note 2: Current sizes result in a full trace size of 2^18. It's not possible to define a fixed structure + // that accomdates both the kernel and the function circuit while remaining under 2^17. This is because the + // circuits differ in structure but are also both designed to be "full" within the 2^17 size. std::array fixed_block_sizes{ 1 << 10, // ecc_op; 1 << 7, // pub_inputs; @@ -330,7 +335,7 @@ template class UltraHonkArith { { aux.has_ram_rom = true; pub_inputs.is_pub_inputs = true; - // Set fixed block sizes for use in structiured trace + // Set fixed block sizes for use in structured trace for (auto [block, size] : zip_view(this->get(), fixed_block_sizes)) { block.set_fixed_size(size); } @@ -344,15 +349,15 @@ template class UltraHonkArith { void summarize() const { - info("Gate blocks summary: (size/capacity)"); + info("Gate blocks summary: (actual gates / fixed capacity)"); info("goblin ecc op:\t", ecc_op.size(), "/", ecc_op.get_fixed_size()); info("pub inputs:\t", pub_inputs.size(), "/", pub_inputs.get_fixed_size()); info("arithmetic:\t", arithmetic.size(), "/", arithmetic.get_fixed_size()); info("delta range:\t", delta_range.size(), "/", delta_range.get_fixed_size()); - info("elliptic:\t\t", elliptic.size(), "/", elliptic.get_fixed_size()); - info("auxiliary:\t\t", aux.size(), "/", aux.get_fixed_size()); - info("lookups:\t\t", lookup.size(), "/", lookup.get_fixed_size()); - info("busread:\t\t", busread.size(), "/", busread.get_fixed_size()); + info("elliptic:\t", elliptic.size(), "/", elliptic.get_fixed_size()); + info("auxiliary:\t", aux.size(), "/", aux.get_fixed_size()); + info("lookups:\t", lookup.size(), "/", lookup.get_fixed_size()); + info("busread:\t", busread.size(), "/", busread.get_fixed_size()); info("poseidon ext:\t", poseidon_external.size(), "/", poseidon_external.get_fixed_size()); info("poseidon int:\t", poseidon_internal.size(), "/", poseidon_internal.get_fixed_size()); info(""); From ac2fd34caa84eab0644b1d85fdd77077c8944ecb Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 1 May 2024 14:57:19 +0000 Subject: [PATCH 05/18] convert to univ is zero skip condition --- .../cpp/src/barretenberg/polynomials/univariate.hpp | 11 +++++++++++ .../src/barretenberg/relations/auxiliary_relation.hpp | 7 ++----- .../relations/databus_lookup_relation.hpp | 5 ++--- .../relations/delta_range_constraint_relation.hpp | 3 ++- .../barretenberg/relations/ecc_op_queue_relation.hpp | 3 ++- .../src/barretenberg/relations/elliptic_relation.hpp | 6 ++---- .../barretenberg/relations/permutation_relation.hpp | 4 ++-- .../relations/poseidon2_external_relation.hpp | 3 ++- .../relations/poseidon2_internal_relation.hpp | 3 ++- .../relations/ultra_arithmetic_relation.hpp | 6 ++---- 10 files changed, 29 insertions(+), 22 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index aedc13537875..79556993686a 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -62,6 +62,17 @@ template class Univariate const Fr& value_at(size_t i) const { return evaluations[i - domain_start]; }; size_t size() { return evaluations.size(); }; + // Check if the univariate is identically zero + bool is_zero() const + { + for (auto& val : evaluations) { + if (!val.is_zero()) { + return false; + }; + } + return true; + } + // Write the Univariate evaluations to a buffer [[nodiscard]] std::vector to_buffer() const { return ::to_buffer(evaluations); } diff --git a/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp index ea8e4b40e73b..5bb956d8ac48 100644 --- a/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp @@ -53,10 +53,7 @@ template class AuxiliaryRelationImpl { * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * */ - template inline static bool skip(const AllEntities& in) - { - return (in.q_aux.value_at(0).is_zero() && in.q_aux.value_at(1).is_zero()); - } + template inline static bool skip(const AllEntities& in) { return in.q_aux.is_zero(); } /** * @brief Expression for the generalized permutation sort gate. @@ -98,7 +95,7 @@ template class AuxiliaryRelationImpl { const Parameters& params, const FF& scaling_factor) { - + BB_OP_COUNT_TIME_NAME("Auxiliary::accumulate"); // All subrelations have the same length so we use the same length view for all calculations using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index 5c74773f955d..bfcbc8fc0b36 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -66,9 +66,7 @@ template class DatabusLookupRelationImpl { template inline static bool skip([[maybe_unused]] const AllEntities& in) { // WORKTODO: comments - return in.q_busread.value_at(0).is_zero() && in.q_busread.value_at(1).is_zero() && - in.calldata_read_counts.value_at(0).is_zero() && in.calldata_read_counts.value_at(1).is_zero() && - in.return_data_read_counts.value_at(0).is_zero() && in.return_data_read_counts.value_at(1).is_zero(); + return in.q_busread.is_zero() && in.calldata_read_counts.is_zero() && in.return_data_read_counts.is_zero(); } // Interface for easy access of databus components by column (bus_idx) @@ -239,6 +237,7 @@ template class DatabusLookupRelationImpl { const Parameters& params, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("DatabusRead::accumulate"); using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; diff --git a/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp index 25429fbc0028..b2bef8ea7910 100644 --- a/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp @@ -20,7 +20,7 @@ template class DeltaRangeConstraintRelationImpl { */ template inline static bool skip(const AllEntities& in) { - return (in.q_delta_range.value_at(0).is_zero() && in.q_delta_range.value_at(1).is_zero()); + return in.q_delta_range.is_zero(); } /** @@ -44,6 +44,7 @@ template class DeltaRangeConstraintRelationImpl { const Parameters&, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("DeltaRange::accumulate"); using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; auto w_1 = View(in.w_l); diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp index f374bf4ccdfd..2f6fe65ddaf8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp @@ -21,7 +21,7 @@ template class EccOpQueueRelationImpl { template inline static bool skip([[maybe_unused]] const AllEntities& in) { // WORKTODO: comments - return in.lagrange_ecc_op.value_at(0).is_zero() && in.lagrange_ecc_op.value_at(1).is_zero(); + return in.lagrange_ecc_op.is_zero(); } /** @@ -49,6 +49,7 @@ template class EccOpQueueRelationImpl { const Parameters&, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("EccOp::accumulate"); using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; diff --git a/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp index 2c0b2a850627..7fcd8df4b56f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp @@ -18,10 +18,7 @@ template class EllipticRelationImpl { * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * */ - template inline static bool skip(const AllEntities& in) - { - return (in.q_elliptic.value_at(0).is_zero() && in.q_elliptic.value_at(1).is_zero()); - } + template inline static bool skip(const AllEntities& in) { return in.q_elliptic.is_zero(); } // TODO(@zac-williamson #2609 find more generic way of doing this) static constexpr FF get_curve_b() @@ -51,6 +48,7 @@ template class EllipticRelationImpl { const Parameters&, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("Elliptic::accumulate"); // TODO(@zac - williamson #2608 when Pedersen refactor is completed, // replace old addition relations with these ones and // remove endomorphism coefficient in ecc add gate(not used)) diff --git a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp index 8ff08be35d2c..b904fabeb956 100644 --- a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp @@ -25,8 +25,7 @@ template class UltraPermutationRelationImpl { { // If z_perm == z_perm_shift, this implies that none of the wire values for the present input are involved in // non-trivial copy constraints. - return (in.z_perm.value_at(0) == in.z_perm_shift.value_at(0) && - in.z_perm.value_at(1) == in.z_perm_shift.value_at(1)); + return (in.z_perm - in.z_perm_shift).is_zero(); } inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } @@ -96,6 +95,7 @@ template class UltraPermutationRelationImpl { const Parameters& params, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("Permutation::accumulate"); // Contribution (1) [&]() { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp index 29d082b4a4e0..11de33a20796 100644 --- a/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp @@ -19,7 +19,7 @@ template class Poseidon2ExternalRelationImpl { */ template inline static bool skip(const AllEntities& in) { - return (in.q_poseidon2_external.value_at(0).is_zero() && in.q_poseidon2_external.value_at(1).is_zero()); + return in.q_poseidon2_external.is_zero(); } /** @@ -52,6 +52,7 @@ template class Poseidon2ExternalRelationImpl { const Parameters&, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("PoseidonExt::accumulate"); using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; auto w_l = View(in.w_l); diff --git a/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp index e21999358682..0014db76971e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp @@ -21,7 +21,7 @@ template class Poseidon2InternalRelationImpl { */ template inline static bool skip(const AllEntities& in) { - return (in.q_poseidon2_internal.value_at(0).is_zero() && in.q_poseidon2_internal.value_at(1).is_zero()); + return in.q_poseidon2_internal.is_zero(); } /** @@ -49,6 +49,7 @@ template class Poseidon2InternalRelationImpl { const Parameters&, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("PoseidonInt::accumulate"); using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; auto w_l = View(in.w_l); diff --git a/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp index 7a5a1e0d9178..d99b57fb7165 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp @@ -16,10 +16,7 @@ template class UltraArithmeticRelationImpl { * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * */ - template inline static bool skip(const AllEntities& in) - { - return (in.q_arith.value_at(0).is_zero() && in.q_arith.value_at(1).is_zero()); - } + template inline static bool skip(const AllEntities& in) { return in.q_arith.is_zero(); } /** * @brief Expression for the Ultra Arithmetic gate. @@ -78,6 +75,7 @@ template class UltraArithmeticRelationImpl { const Parameters&, const FF& scaling_factor) { + BB_OP_COUNT_TIME_NAME("Arithmetic::accumulate"); { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; From de0216bb5af315ffedd5feb28116fa549454493b Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 1 May 2024 19:50:41 +0000 Subject: [PATCH 06/18] WiP --- barretenberg/cpp/CMakePresets.json | 2 +- .../cpp/scripts/analyze_client_ivc_bench.py | 44 ++++++++++++++++- .../cpp/scripts/benchmark_client_ivc.sh | 3 +- .../barretenberg/client_ivc/client_ivc.cpp | 1 + .../client_ivc/client_ivc.test.cpp | 2 +- .../arithmetization/arithmetization.hpp | 2 +- .../protogalaxy/protogalaxy.test.cpp | 30 +++++++++--- .../protogalaxy/protogalaxy_prover.hpp | 47 +++++++++++-------- .../relations/lookup_relation.hpp | 2 +- .../relations/permutation_relation.hpp | 9 +++- .../sumcheck/instance/prover_instance.hpp | 1 + 11 files changed, 110 insertions(+), 33 deletions(-) diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index 24538c08c0b5..ffd2c0e37e41 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -210,7 +210,7 @@ "displayName": "Release build with operation counts", "description": "Build with op counting", "inherits": "clang16", - "binaryDir": "build-op-count", + "binaryDir": "build", "environment": { "CXXFLAGS": "-DBB_USE_OP_COUNT -DBB_USE_OP_COUNT_TRACK_ONLY" } diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index 46a37826efae..f4b484115c6d 100644 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -3,7 +3,8 @@ PREFIX = Path("build-op-count-time") IVC_BENCH_JSON = Path("client_ivc_bench.json") -BENCHMARK = "ClientIVCBench/Full/6" +BENCHMARK = "ClientIVCBench/FullStructured/6" +# BENCHMARK = "ClientIVCBench/Full/6" # Single out an independent set of functions accounting for most of BENCHMARK's real_time to_keep = [ @@ -71,3 +72,44 @@ print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}") +# Relations breakdown +print('\n Relation contributions:') +relations = [ + "Arithmetic::accumulate(t)", + "Permutation::accumulate(t)", + "Lookup::accumulate(t)", + "DeltaRange::accumulate(t)", + "Elliptic::accumulate(t)", + "Auxiliary::accumulate(t)", + "EccOp::accumulate(t)", + "DatabusRead::accumulate(t)", + "PoseidonExt::accumulate(t)", + "PoseidonInt::accumulate(t)", +] +with open(PREFIX/IVC_BENCH_JSON, "r") as read_file: + read_result = json.load(read_file) + for _bench in read_result["benchmarks"]: + if _bench["name"] == BENCHMARK: + bench = _bench +bench_components = dict(filter(lambda x: x[0] in relations, bench.items())) + +# For each kept time, get the proportion over all kept times. +sum_of_kept_times_ms = sum(float(time) + for _, time in bench_components.items())/1e6 +max_label_length = max(len(label) for label in relations) +column = {"function": "function", "ms": "ms", "%": "% sum"} +print( + f"{column['function']:<{max_label_length}}{column['ms']:>8} {column['%']:>8}") +for key in relations: + if key not in bench: + time_ms = 0 + else: + time_ms = bench[key]/1e6 + print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}") + +# Validate that kept times account for most of the total measured time. +total_time_ms = bench["real_time"] +totals = '\nTotal time accounted for: {:.0f}ms/{:.0f}ms = {:.2%}' +totals = totals.format( + sum_of_kept_times_ms, total_time_ms, sum_of_kept_times_ms/total_time_ms) +print(totals) \ No newline at end of file diff --git a/barretenberg/cpp/scripts/benchmark_client_ivc.sh b/barretenberg/cpp/scripts/benchmark_client_ivc.sh index 17a193c6d829..2e1d7407b921 100755 --- a/barretenberg/cpp/scripts/benchmark_client_ivc.sh +++ b/barretenberg/cpp/scripts/benchmark_client_ivc.sh @@ -2,7 +2,8 @@ set -eu TARGET="client_ivc_bench" -FILTER="ClientIVCBench/Full/6$" +FILTER="ClientIVCBench/FullStructured/6$" +# FILTER="ClientIVCBench/Full/6$" BUILD_DIR=build-op-count-time # Move above script dir. diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 0559c7fe3165..bdc00ded564d 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -25,6 +25,7 @@ ClientIVC::FoldProof ClientIVC::accumulate(ClientCircuit& circuit) { goblin.merge(circuit); // Add recursive merge verifier and construct new merge proof prover_instance = std::make_shared(circuit, structured_flag); + info("CIRCUIT SIZE = ", prover_instance->proving_key.circuit_size); // circuit.blocks.summarize(); FoldingProver folding_prover({ prover_fold_output.accumulator, prover_instance }); prover_fold_output = folding_prover.fold_instances(); diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 0dd189112b84..592b1371ed8a 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -113,7 +113,7 @@ class ClientIVCTests : public ::testing::Test { */ // TODO fix with https://github.com/AztecProtocol/barretenberg/issues/930 // intermittent failures, presumably due to uninitialized memory -TEST_F(ClientIVCTests, DISABLED_Full) +TEST_F(ClientIVCTests, Full) { using VerificationKey = Flavor::VerificationKey; diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp index a22b965e5ab1..7e597e2fa86d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp @@ -124,7 +124,7 @@ template class UltraArith { public: static constexpr size_t NUM_WIRES = 4; static constexpr size_t NUM_SELECTORS = 11; - static constexpr size_t FIXED_BLOCK_SIZE = 1 << 3; // Size of each block in a structured trace (arbitrary for now) + static constexpr size_t FIXED_BLOCK_SIZE = 1 << 10; // Size of each block in a structured trace (arbitrary for now) using FF = FF_; class UltraTraceBlock : public ExecutionTraceBlock { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 0b51c91f57b4..61b26493afaf 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -1,3 +1,4 @@ +#include "barretenberg/common/op_count.hpp" #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/polynomials/pow.hpp" #include "barretenberg/protogalaxy/decider_prover.hpp" @@ -313,14 +314,15 @@ template class ProtoGalaxyTests : public testing::Test { { TupleOfInstances insts = construct_instances(2); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(insts), get<1>(insts)); - check_accumulator_target_sum_manual(prover_accumulator, true); + // check_accumulator_target_sum_manual(prover_accumulator, true); - TupleOfInstances insts_2 = construct_instances(1); // just one set of prover/verifier instances - auto [prover_accumulator_2, verifier_accumulator_2] = - fold_and_verify({ prover_accumulator, get<0>(insts_2)[0] }, { verifier_accumulator, get<1>(insts_2)[0] }); - check_accumulator_target_sum_manual(prover_accumulator_2, true); + // TupleOfInstances insts_2 = construct_instances(1); // just one set of prover/verifier instances + // auto [prover_accumulator_2, verifier_accumulator_2] = + // fold_and_verify({ prover_accumulator, get<0>(insts_2)[0] }, { verifier_accumulator, get<1>(insts_2)[0] + // }); + // check_accumulator_target_sum_manual(prover_accumulator_2, true); - decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); + // decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); } /** @@ -333,6 +335,22 @@ template class ProtoGalaxyTests : public testing::Test { TupleOfInstances instances = construct_instances(2, structured); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(instances), get<1>(instances)); + + size_t accum_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["Permutation::accumulate"]; + size_t zero_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-ZERO"]; + size_t zero_cond_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-ZERO-cond"]; + size_t non_zero_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-non-zero"]; + size_t skip_attempt_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-attempt-skip"]; + size_t skip_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-skip"]; + size_t no_skip_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-no-skip"]; + info("accum_count = ", accum_count); + info("ZERO Count = ", zero_count); + info("ZERO condition Count = ", zero_cond_count); + info("non-zero Count = ", non_zero_count); + info("skip_attempt_count = ", skip_attempt_count); + info("skip_count = ", skip_count); + info("no_skip_count = ", no_skip_count); + check_accumulator_target_sum_manual(prover_accumulator, true); TupleOfInstances instances_2 = construct_instances(1, structured); // just one set of prover/verifier instances diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index b916cdb98505..1baf90a0d31e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -290,28 +290,35 @@ template class ProtoGalaxyProver_ { { using Relation = std::tuple_element_t; - // Check if the relation is skippable to speed up accumulation - if constexpr (!isSkippable) { - // info("NOT SKIPPABLE!"); - // If not, accumulate normally - Relation::accumulate(std::get(univariate_accumulators), - extended_univariates, - relation_parameters, - scaling_factor); - } else { - // info("SKIPPABLE!"); - // If so, only compute the contribution if the relation is active - if (!Relation::skip(extended_univariates)) { - // info("NOT skipping!", relation_idx); - Relation::accumulate(std::get(univariate_accumulators), - extended_univariates, - relation_parameters, - scaling_factor); - } else { - // info("Skipping!", relation_idx); - } + Relation::accumulate( + std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); + + if constexpr (isSkippable) { + Relation::skip(extended_univariates); } + // // Check if the relation is skippable to speed up accumulation + // if constexpr (!isSkippable) { + // // info("NOT SKIPPABLE!"); + // // If not, accumulate normally + // Relation::accumulate(std::get(univariate_accumulators), + // extended_univariates, + // relation_parameters, + // scaling_factor); + // } else { + // // info("SKIPPABLE!"); + // // If so, only compute the contribution if the relation is active + // if (!Relation::skip(extended_univariates)) { + // // info("NOT skipping!", relation_idx); + // Relation::accumulate(std::get(univariate_accumulators), + // extended_univariates, + // relation_parameters, + // scaling_factor); + // } else { + // // info("Skipping!", relation_idx); + // } + // } + // Repeat for the next relation. if constexpr (relation_idx + 1 < Flavor::NUM_RELATIONS) { accumulate_relation_univariates( diff --git a/barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp index 337469bd5c80..46b70df7cabf 100644 --- a/barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/lookup_relation.hpp @@ -184,7 +184,7 @@ template class LookupRelationImpl { const Parameters& params, const FF& scaling_factor) { - + BB_OP_COUNT_TIME_NAME("Lookup::accumulate"); { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; diff --git a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp index b904fabeb956..8503696e3a10 100644 --- a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp @@ -25,7 +25,14 @@ template class UltraPermutationRelationImpl { { // If z_perm == z_perm_shift, this implies that none of the wire values for the present input are involved in // non-trivial copy constraints. - return (in.z_perm - in.z_perm_shift).is_zero(); + bool cond = (in.z_perm - in.z_perm_shift).is_zero(); + BB_OP_COUNT_TIME_NAME("PERM-attempt-skip"); + if (cond) { + BB_OP_COUNT_TIME_NAME("PERM-skip"); + } else { + BB_OP_COUNT_TIME_NAME("PERM-no-skip"); + } + return cond; } inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index de9305bf2b88..5c983ec876ee 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -50,6 +50,7 @@ template class ProverInstance_ { if (is_structured) { circuit.blocks.check_within_fixed_sizes(); } + // circuit.blocks.summarize(); // TODO(https://github.com/AztecProtocol/barretenberg/issues/905): This is adding ops to the op queue but NOT to // the circuit, meaning the ECCVM/Translator will use different ops than the main circuit. This will lead to From 1f54d4a08b804228749c862724b91b1ac315a9ef Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 1 May 2024 21:33:21 +0000 Subject: [PATCH 07/18] fix client ivc initialize --- .../barretenberg/client_ivc/client_ivc.cpp | 4 +- .../protogalaxy/protogalaxy_prover.hpp | 53 ++++++++++--------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index bdc00ded564d..6efaa188d9ec 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -11,7 +11,7 @@ namespace bb { void ClientIVC::initialize(ClientCircuit& circuit) { goblin.merge(circuit); // Construct new merge proof - prover_fold_output.accumulator = std::make_shared(circuit); + prover_fold_output.accumulator = std::make_shared(circuit, structured_flag); } /** @@ -25,7 +25,7 @@ ClientIVC::FoldProof ClientIVC::accumulate(ClientCircuit& circuit) { goblin.merge(circuit); // Add recursive merge verifier and construct new merge proof prover_instance = std::make_shared(circuit, structured_flag); - info("CIRCUIT SIZE = ", prover_instance->proving_key.circuit_size); + // info("CIRCUIT SIZE = ", prover_instance->proving_key.circuit_size); // circuit.blocks.summarize(); FoldingProver folding_prover({ prover_fold_output.accumulator, prover_instance }); prover_fold_output = folding_prover.fold_instances(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 1baf90a0d31e..211a145a935e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -290,35 +290,36 @@ template class ProtoGalaxyProver_ { { using Relation = std::tuple_element_t; - Relation::accumulate( - std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); + // Relation::accumulate( + // std::get(univariate_accumulators), extended_univariates, relation_parameters, + // scaling_factor); - if constexpr (isSkippable) { - Relation::skip(extended_univariates); - } - - // // Check if the relation is skippable to speed up accumulation - // if constexpr (!isSkippable) { - // // info("NOT SKIPPABLE!"); - // // If not, accumulate normally - // Relation::accumulate(std::get(univariate_accumulators), - // extended_univariates, - // relation_parameters, - // scaling_factor); - // } else { - // // info("SKIPPABLE!"); - // // If so, only compute the contribution if the relation is active - // if (!Relation::skip(extended_univariates)) { - // // info("NOT skipping!", relation_idx); - // Relation::accumulate(std::get(univariate_accumulators), - // extended_univariates, - // relation_parameters, - // scaling_factor); - // } else { - // // info("Skipping!", relation_idx); - // } + // if constexpr (isSkippable) { + // Relation::skip(extended_univariates); // } + // Check if the relation is skippable to speed up accumulation + if constexpr (!isSkippable) { + // info("NOT SKIPPABLE!"); + // If not, accumulate normally + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } else { + // info("SKIPPABLE!"); + // If so, only compute the contribution if the relation is active + if (!Relation::skip(extended_univariates)) { + // info("NOT skipping!", relation_idx); + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } else { + // info("Skipping!", relation_idx); + } + } + // Repeat for the next relation. if constexpr (relation_idx + 1 < Flavor::NUM_RELATIONS) { accumulate_relation_univariates( From f9ba3dec9f7ed1bf39f98a5718b0ee95cdbc8a39 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 2 May 2024 17:24:45 +0000 Subject: [PATCH 08/18] cleanup --- .../protogalaxy/protogalaxy_prover.hpp | 13 ------------- .../relations/permutation_relation.hpp | 9 +-------- .../cpp/src/barretenberg/relations/utils.hpp | 19 +++++++++++++++++-- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 211a145a935e..880ef696057b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -290,33 +290,20 @@ template class ProtoGalaxyProver_ { { using Relation = std::tuple_element_t; - // Relation::accumulate( - // std::get(univariate_accumulators), extended_univariates, relation_parameters, - // scaling_factor); - - // if constexpr (isSkippable) { - // Relation::skip(extended_univariates); - // } - // Check if the relation is skippable to speed up accumulation if constexpr (!isSkippable) { - // info("NOT SKIPPABLE!"); // If not, accumulate normally Relation::accumulate(std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); } else { - // info("SKIPPABLE!"); // If so, only compute the contribution if the relation is active if (!Relation::skip(extended_univariates)) { - // info("NOT skipping!", relation_idx); Relation::accumulate(std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); - } else { - // info("Skipping!", relation_idx); } } diff --git a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp index 8503696e3a10..b904fabeb956 100644 --- a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp @@ -25,14 +25,7 @@ template class UltraPermutationRelationImpl { { // If z_perm == z_perm_shift, this implies that none of the wire values for the present input are involved in // non-trivial copy constraints. - bool cond = (in.z_perm - in.z_perm_shift).is_zero(); - BB_OP_COUNT_TIME_NAME("PERM-attempt-skip"); - if (cond) { - BB_OP_COUNT_TIME_NAME("PERM-skip"); - } else { - BB_OP_COUNT_TIME_NAME("PERM-no-skip"); - } - return cond; + return (in.z_perm - in.z_perm_shift).is_zero(); } inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } diff --git a/barretenberg/cpp/src/barretenberg/relations/utils.hpp b/barretenberg/cpp/src/barretenberg/relations/utils.hpp index 0eced14c1957..abbfdd56e1cd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/utils.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/utils.hpp @@ -158,8 +158,23 @@ template class RelationUtils { const FF& partial_evaluation_result) { using Relation = std::tuple_element_t; - Relation::accumulate( - std::get(relation_evaluations), evaluations, relation_parameters, partial_evaluation_result); + + // Check if the relation is skippable to speed up accumulation + if constexpr (!isSkippable || !std::is_same_v) { + // If not, accumulate normally + Relation::accumulate(std::get(relation_evaluations), + evaluations, + relation_parameters, + partial_evaluation_result); + } else { + // If so, only compute the contribution if the relation is active + if (!Relation::skip(evaluations)) { + Relation::accumulate(std::get(relation_evaluations), + evaluations, + relation_parameters, + partial_evaluation_result); + } + } // Repeat for the next relation. if constexpr (relation_idx + 1 < NUM_RELATIONS) { From ce993581f91676809abe15d9b370668a41730860 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 2 May 2024 18:05:47 +0000 Subject: [PATCH 09/18] clean --- barretenberg/cpp/CMakePresets.json | 2 +- .../cpp/scripts/analyze_client_ivc_bench.py | 13 ++-- .../client_ivc_bench/client_ivc.bench.cpp | 17 ----- .../relations_bench/relations.bench.cpp | 71 +++++++++---------- .../barretenberg/client_ivc/client_ivc.cpp | 2 - .../barretenberg/client_ivc/client_ivc.hpp | 1 + .../client_ivc/client_ivc.test.cpp | 2 +- .../protogalaxy/protogalaxy.test.cpp | 30 ++------ .../protogalaxy/protogalaxy_prover.hpp | 1 - .../relations/databus_lookup_relation.hpp | 2 +- .../relations/ecc_op_queue_relation.hpp | 2 +- .../sumcheck/instance/prover_instance.hpp | 1 - .../ultra_honk/goblin_ultra_composer.test.cpp | 1 - 13 files changed, 48 insertions(+), 97 deletions(-) diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index ffd2c0e37e41..24538c08c0b5 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -210,7 +210,7 @@ "displayName": "Release build with operation counts", "description": "Build with op counting", "inherits": "clang16", - "binaryDir": "build", + "binaryDir": "build-op-count", "environment": { "CXXFLAGS": "-DBB_USE_OP_COUNT -DBB_USE_OP_COUNT_TRACK_ONLY" } diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index f4b484115c6d..e2bc5f1e9e79 100644 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -73,7 +73,9 @@ # Relations breakdown -print('\n Relation contributions:') +# Note: The timings here are off likely because the tracking is occuring in a hot loop but +# they should be meaningful relative to one another +print('\nRelation contributions (times to be interpreted relatively):') relations = [ "Arithmetic::accumulate(t)", "Permutation::accumulate(t)", @@ -105,11 +107,4 @@ time_ms = 0 else: time_ms = bench[key]/1e6 - print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}") - -# Validate that kept times account for most of the total measured time. -total_time_ms = bench["real_time"] -totals = '\nTotal time accounted for: {:.0f}ms/{:.0f}ms = {:.2%}' -totals = totals.format( - sum_of_kept_times_ms, total_time_ms, sum_of_kept_times_ms/total_time_ms) -print(totals) \ No newline at end of file + print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}") \ No newline at end of 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 e630efcfe0ef..ded7acc08f14 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 @@ -207,22 +207,6 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Accumulate)(benchmark::State& state) } } -/** - * @brief Benchmark only the accumulation rounds - * - */ -BENCHMARK_DEFINE_F(ClientIVCBench, AccumulateStructured)(benchmark::State& state) -{ - ClientIVC ivc; - ivc.structured_flag = true; - ivc.precompute_folding_verification_keys(); - // Perform a specified number of iterations of function/kernel accumulation - for (auto _ : state) { - BB_REPORT_OP_COUNT_IN_BENCH(state); - perform_ivc_accumulation_rounds(state, ivc); - } -} - /** * @brief Benchmark only the Decider component * @@ -289,7 +273,6 @@ BENCHMARK_DEFINE_F(ClientIVCBench, Translator)(benchmark::State& state) BENCHMARK_REGISTER_F(ClientIVCBench, Full)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, FullStructured)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, Accumulate)->Unit(benchmark::kMillisecond)->ARGS; -BENCHMARK_REGISTER_F(ClientIVCBench, AccumulateStructured)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, Decide)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, ECCVM)->Unit(benchmark::kMillisecond)->ARGS; BENCHMARK_REGISTER_F(ClientIVCBench, Translator)->Unit(benchmark::kMillisecond)->ARGS; diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index 3744ba9d6e82..af040b8da4b8 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -14,72 +14,65 @@ namespace bb::benchmark::relations { using Fr = bb::fr; using Fq = grumpkin::fr; -template void execute_relation_for_values(::benchmark::State& state) +// Generic helper for executing Relation::accumulate for the template specified input type +template +void execute_relation(::benchmark::State& state) { using FF = typename Flavor::FF; - using Input = typename Flavor::AllValues; - using Accumulator = typename Relation::SumcheckArrayOfValuesOverSubrelations; auto params = bb::RelationParameters::get_random(); // Instantiate zero-initialized inputs and accumulator - Input input_values{}; + Input input{}; Accumulator accumulator; for (auto _ : state) { - Relation::accumulate(accumulator, input_values, params, 1); + Relation::accumulate(accumulator, input, params, 1); } } +// Single execution of relation on values (FF), e.g. Sumcheck verifier / PG perturbator work +template void execute_relation_for_values(::benchmark::State& state) +{ + using Input = typename Flavor::AllValues; + using Accumulator = typename Relation::SumcheckArrayOfValuesOverSubrelations; + + execute_relation(state); +} + +// Single execution of relation on Sumcheck univariates, i.e. Sumcheck/Decider prover work template void execute_relation_for_univariates(::benchmark::State& state) { - using FF = typename Flavor::FF; using Input = typename Flavor::ExtendedEdges; using Accumulator = typename Relation::SumcheckTupleOfUnivariatesOverSubrelations; - auto params = bb::RelationParameters::get_random(); - - // Instantiate zero-initialized inputs and accumulator - Input input_univariates{}; - Accumulator accumulator; - - for (auto _ : state) { - Relation::accumulate(accumulator, input_univariates, params, 1); - } + execute_relation(state); } -template void execute_relation_for_univariates_pg(::benchmark::State& state) +// Single execution of relation on PG univariates, i.e. PG combiner work +template void execute_relation_for_pg_univariates(::benchmark::State& state) { - using FF = typename Flavor::FF; using ProverInstances = ProverInstances_; using ProtoGalaxyProver = ProtoGalaxyProver_; using Input = ProtoGalaxyProver::ExtendedUnivariates; using Accumulator = typename Relation::template ProtogalaxyTupleOfUnivariatesOverSubrelations; - auto params = bb::RelationParameters::get_random(); - - // Instantiate zero-initialized inputs and accumulator - Input input_univariates{}; - Accumulator accumulator; - - for (auto _ : state) { - Relation::accumulate(accumulator, input_univariates, params, 1); - } + execute_relation(state); } -// Ultra relations (PG prover work) -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); +// Ultra relations (PG prover combiner work) +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); -// Goblin-Ultra only relations (PG prover work) -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); -BENCHMARK(execute_relation_for_univariates_pg>); +// Goblin-Ultra only relations (PG prover combiner work) +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); +BENCHMARK(execute_relation_for_pg_univariates>); // Ultra relations (Sumcheck prover work) BENCHMARK(execute_relation_for_univariates>); @@ -109,6 +102,7 @@ BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); +// Translator VM BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); @@ -116,6 +110,7 @@ BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); +// ECCVM BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); BENCHMARK(execute_relation_for_values>); diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 6efaa188d9ec..73f3ed00ab2e 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -25,8 +25,6 @@ ClientIVC::FoldProof ClientIVC::accumulate(ClientCircuit& circuit) { goblin.merge(circuit); // Add recursive merge verifier and construct new merge proof prover_instance = std::make_shared(circuit, structured_flag); - // info("CIRCUIT SIZE = ", prover_instance->proving_key.circuit_size); - // circuit.blocks.summarize(); FoldingProver folding_prover({ prover_fold_output.accumulator, prover_instance }); prover_fold_output = folding_prover.fold_instances(); return prover_fold_output.folding_data; diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp index 71f8837d2029..b05cea9c3f02 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp @@ -63,6 +63,7 @@ class ClientIVC { // be needed in the real IVC as they are provided as inputs std::shared_ptr prover_instance; + // A flag indicating whether or not to construct a structured trace in the ProverInstance bool structured_flag = false; void initialize(ClientCircuit& circuit); diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 592b1371ed8a..0dd189112b84 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -113,7 +113,7 @@ class ClientIVCTests : public ::testing::Test { */ // TODO fix with https://github.com/AztecProtocol/barretenberg/issues/930 // intermittent failures, presumably due to uninitialized memory -TEST_F(ClientIVCTests, Full) +TEST_F(ClientIVCTests, DISABLED_Full) { using VerificationKey = Flavor::VerificationKey; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 61b26493afaf..0b51c91f57b4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -1,4 +1,3 @@ -#include "barretenberg/common/op_count.hpp" #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/polynomials/pow.hpp" #include "barretenberg/protogalaxy/decider_prover.hpp" @@ -314,15 +313,14 @@ template class ProtoGalaxyTests : public testing::Test { { TupleOfInstances insts = construct_instances(2); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(insts), get<1>(insts)); - // check_accumulator_target_sum_manual(prover_accumulator, true); + check_accumulator_target_sum_manual(prover_accumulator, true); - // TupleOfInstances insts_2 = construct_instances(1); // just one set of prover/verifier instances - // auto [prover_accumulator_2, verifier_accumulator_2] = - // fold_and_verify({ prover_accumulator, get<0>(insts_2)[0] }, { verifier_accumulator, get<1>(insts_2)[0] - // }); - // check_accumulator_target_sum_manual(prover_accumulator_2, true); + TupleOfInstances insts_2 = construct_instances(1); // just one set of prover/verifier instances + auto [prover_accumulator_2, verifier_accumulator_2] = + fold_and_verify({ prover_accumulator, get<0>(insts_2)[0] }, { verifier_accumulator, get<1>(insts_2)[0] }); + check_accumulator_target_sum_manual(prover_accumulator_2, true); - // decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); + decide_and_verify(prover_accumulator_2, verifier_accumulator_2, true); } /** @@ -335,22 +333,6 @@ template class ProtoGalaxyTests : public testing::Test { TupleOfInstances instances = construct_instances(2, structured); auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(instances), get<1>(instances)); - - size_t accum_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["Permutation::accumulate"]; - size_t zero_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-ZERO"]; - size_t zero_cond_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-ZERO-cond"]; - size_t non_zero_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-non-zero"]; - size_t skip_attempt_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-attempt-skip"]; - size_t skip_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-skip"]; - size_t no_skip_count = bb::detail::GLOBAL_OP_COUNTS.get_aggregate_counts()["PERM-no-skip"]; - info("accum_count = ", accum_count); - info("ZERO Count = ", zero_count); - info("ZERO condition Count = ", zero_cond_count); - info("non-zero Count = ", non_zero_count); - info("skip_attempt_count = ", skip_attempt_count); - info("skip_count = ", skip_count); - info("no_skip_count = ", no_skip_count); - check_accumulator_target_sum_manual(prover_accumulator, true); TupleOfInstances instances_2 = construct_instances(1, structured); // just one set of prover/verifier instances diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 880ef696057b..7086b51e19fc 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -345,7 +345,6 @@ template class ProtoGalaxyProver_ { extended_univariates.resize(num_threads); // Accumulate the contribution from each sub-relation - // num_threads = 1; 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; diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index bfcbc8fc0b36..3c897ce39090 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -65,7 +65,7 @@ template class DatabusLookupRelationImpl { template inline static bool skip([[maybe_unused]] const AllEntities& in) { - // WORKTODO: comments + // Ensure the input does not contain a read gate or data that is being read return in.q_busread.is_zero() && in.calldata_read_counts.is_zero() && in.return_data_read_counts.is_zero(); } diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp index 2f6fe65ddaf8..4eee0115cf57 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp @@ -20,7 +20,7 @@ template class EccOpQueueRelationImpl { template inline static bool skip([[maybe_unused]] const AllEntities& in) { - // WORKTODO: comments + // WORKTODO: Can we just skip this always? input should be zero if its honest.. return in.lagrange_ecc_op.is_zero(); } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 5c983ec876ee..de9305bf2b88 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -50,7 +50,6 @@ template class ProverInstance_ { if (is_structured) { circuit.blocks.check_within_fixed_sizes(); } - // circuit.blocks.summarize(); // TODO(https://github.com/AztecProtocol/barretenberg/issues/905): This is adding ops to the op queue but NOT to // the circuit, meaning the ECCVM/Translator will use different ops than the main circuit. This will lead to diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp index dc5f8e76dc08..d33607a6bdbc 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_composer.test.cpp @@ -88,7 +88,6 @@ TEST_F(GoblinUltraHonkComposerTests, BasicStructured) // Construct and verify Honk proof using a structured trace bool structured = true; auto instance = std::make_shared>(builder, structured); - builder.blocks.summarize(); GoblinUltraProver prover(instance); auto verification_key = std::make_shared(instance->proving_key); GoblinUltraVerifier verifier(verification_key); From f1c9eb24f9952487d5fae3d862ead69a88e711b5 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 2 May 2024 19:24:01 +0000 Subject: [PATCH 10/18] turn off ecc relation for prover and add no skip method for verif --- .../arithmetization/arithmetization.hpp | 3 +- .../relations/ecc_op_queue_relation.hpp | 5 ++-- .../cpp/src/barretenberg/relations/utils.hpp | 28 +++++++++++++++++++ .../barretenberg/sumcheck/sumcheck_round.hpp | 3 +- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp index 7e597e2fa86d..2f2ad945cc10 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp @@ -124,7 +124,6 @@ template class UltraArith { public: static constexpr size_t NUM_WIRES = 4; static constexpr size_t NUM_SELECTORS = 11; - static constexpr size_t FIXED_BLOCK_SIZE = 1 << 10; // Size of each block in a structured trace (arbitrary for now) using FF = FF_; class UltraTraceBlock : public ExecutionTraceBlock { @@ -163,6 +162,7 @@ template class UltraArith { UltraTraceBlock aux; UltraTraceBlock lookup; + static constexpr size_t FIXED_BLOCK_SIZE = 1 << 10; // (Arbitrary for now) std::array fixed_block_sizes{ 1 << 3, // pub_inputs; FIXED_BLOCK_SIZE, // arithmetic; @@ -240,7 +240,6 @@ template class UltraHonkArith { public: static constexpr size_t NUM_WIRES = 4; static constexpr size_t NUM_SELECTORS = 14; - static constexpr size_t FIXED_BLOCK_SIZE = 1 << 15; // Size of each block in a structured trace (arbitrary for now) using FF = FF_; diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp index 4eee0115cf57..29d23be4e651 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp @@ -20,8 +20,9 @@ template class EccOpQueueRelationImpl { template inline static bool skip([[maybe_unused]] const AllEntities& in) { - // WORKTODO: Can we just skip this always? input should be zero if its honest.. - return in.lagrange_ecc_op.is_zero(); + // The prover can skip execution of this relation altogether since an honest input will lead to a zero + // contribution at every row, even when the selector lagrange_ecc_op is on + return true; } /** diff --git a/barretenberg/cpp/src/barretenberg/relations/utils.hpp b/barretenberg/cpp/src/barretenberg/relations/utils.hpp index abbfdd56e1cd..b7ea4edce09d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/utils.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/utils.hpp @@ -141,6 +141,34 @@ template class RelationUtils { } } + /** + * @brief Calculate the contribution of each relation to the expected value of the full Honk relation. + * + * @details For each relation, use the purported values (supplied by the prover) of the multivariates to + * calculate a contribution to the purported value of the full Honk relation. These are stored in `evaluations`. + * Adding these together, with appropriate scaling factors, produces the expected value of the full Honk + * relation. This value is checked against the final value of the target total sum (called sigma_0 in the + * thesis). + */ + template + // TODO(#224)(Cody): Input should be an array? + inline static void accumulate_relation_evaluations_without_skipping(PolynomialEvaluations evaluations, + RelationEvaluations& relation_evaluations, + const Parameters& relation_parameters, + const FF& partial_evaluation_result) + { + using Relation = std::tuple_element_t; + + Relation::accumulate( + std::get(relation_evaluations), evaluations, relation_parameters, partial_evaluation_result); + + // Repeat for the next relation. + if constexpr (relation_idx + 1 < NUM_RELATIONS) { + accumulate_relation_evaluations( + evaluations, relation_evaluations, relation_parameters, partial_evaluation_result); + } + } + /** * @brief Calculate the contribution of each relation to the expected value of the full Honk relation. * diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index c1ac763379ab..51bdf4466058 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -336,7 +336,8 @@ template class SumcheckVerifierRound { const bb::PowPolynomial& pow_polynomial, const RelationSeparator alpha) { - Utils::template accumulate_relation_evaluations<>( + // The verifier should never skip computation of contributions from any relation + Utils::template accumulate_relation_evaluations_without_skipping<>( purported_evaluations, relation_evaluations, relation_parameters, pow_polynomial.partial_evaluation_result); auto running_challenge = FF(1); From b9b36464c9f5080b99ad5ef00175c97ef53a84ac Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 2 May 2024 19:41:21 +0000 Subject: [PATCH 11/18] size_t issue --- .../arithmetization/arithmetization.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp index 2f2ad945cc10..c71e50ee3c3a 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp @@ -51,7 +51,7 @@ template class ExecutionTr bool has_ram_rom = false; // does the block contain RAM/ROM gates bool is_pub_inputs = false; // is this the public inputs block - size_t fixed_size; // Fixed size for use in structured trace + uint32_t fixed_size; // Fixed size for use in structured trace bool operator==(const ExecutionTraceBlock& other) const = default; @@ -67,8 +67,8 @@ template class ExecutionTr } } - size_t get_fixed_size() const { return fixed_size; } - void set_fixed_size(size_t size_in) { fixed_size = size_in; } + uint32_t get_fixed_size() const { return fixed_size; } + void set_fixed_size(uint32_t size_in) { fixed_size = size_in; } }; // These are not magic numbers and they should not be written with global constants. These parameters are not @@ -162,8 +162,8 @@ template class UltraArith { UltraTraceBlock aux; UltraTraceBlock lookup; - static constexpr size_t FIXED_BLOCK_SIZE = 1 << 10; // (Arbitrary for now) - std::array fixed_block_sizes{ + static constexpr uint32_t FIXED_BLOCK_SIZE = 1 << 10; // (Arbitrary for now) + std::array fixed_block_sizes{ 1 << 3, // pub_inputs; FIXED_BLOCK_SIZE, // arithmetic; FIXED_BLOCK_SIZE, // delta_range; @@ -317,7 +317,7 @@ template class UltraHonkArith { // Note 2: Current sizes result in a full trace size of 2^18. It's not possible to define a fixed structure // that accomdates both the kernel and the function circuit while remaining under 2^17. This is because the // circuits differ in structure but are also both designed to be "full" within the 2^17 size. - std::array fixed_block_sizes{ + std::array fixed_block_sizes{ 1 << 10, // ecc_op; 1 << 7, // pub_inputs; 1 << 16, // arithmetic; From a2b66374ced0babffca45510e128c0c3e65e0308 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 2 May 2024 20:09:23 +0000 Subject: [PATCH 12/18] comments --- barretenberg/cpp/scripts/analyze_client_ivc_bench.py | 3 +-- barretenberg/cpp/scripts/benchmark_client_ivc.sh | 4 ++-- .../plonk_honk_shared/arithmetization/arithmetization.hpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index e2bc5f1e9e79..07809f1f1cc7 100644 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -3,8 +3,7 @@ PREFIX = Path("build-op-count-time") IVC_BENCH_JSON = Path("client_ivc_bench.json") -BENCHMARK = "ClientIVCBench/FullStructured/6" -# BENCHMARK = "ClientIVCBench/Full/6" +BENCHMARK = "ClientIVCBench/Full/6" # Single out an independent set of functions accounting for most of BENCHMARK's real_time to_keep = [ diff --git a/barretenberg/cpp/scripts/benchmark_client_ivc.sh b/barretenberg/cpp/scripts/benchmark_client_ivc.sh index 2e1d7407b921..7991ef879407 100755 --- a/barretenberg/cpp/scripts/benchmark_client_ivc.sh +++ b/barretenberg/cpp/scripts/benchmark_client_ivc.sh @@ -2,8 +2,8 @@ set -eu TARGET="client_ivc_bench" -FILTER="ClientIVCBench/FullStructured/6$" -# FILTER="ClientIVCBench/Full/6$" +# Note: to run structured trace version, change "Full" to "FullStructured" here and in analyze script +FILTER="ClientIVCBench/Full/6$" BUILD_DIR=build-op-count-time # Move above script dir. diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp index c71e50ee3c3a..f71b77021eed 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/arithmetization/arithmetization.hpp @@ -206,7 +206,7 @@ template class UltraArith { } /** - * @brief Check that the number of rows poulated in each block does not exceed the specified fixed size + * @brief Check that the number of rows populated in each block does not exceed the specified fixed size * @note This check is only applicable when utilizing a structured trace * */ From 32b672aa0e2bc30745bb63d7e9b716d9da25aa42 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 2 May 2024 21:13:08 +0000 Subject: [PATCH 13/18] disable skipping to see if things work --- .../protogalaxy/protogalaxy_prover.hpp | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 1e4bc8e89f74..4c2a07b3b407 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -324,22 +324,26 @@ template class ProtoGalaxyProver_ { { using Relation = std::tuple_element_t; - // Check if the relation is skippable to speed up accumulation - if constexpr (!isSkippable) { - // If not, accumulate normally - Relation::accumulate(std::get(univariate_accumulators), - extended_univariates, - relation_parameters, - scaling_factor); - } else { - // If so, only compute the contribution if the relation is active - if (!Relation::skip(extended_univariates)) { - Relation::accumulate(std::get(univariate_accumulators), - extended_univariates, - relation_parameters, - scaling_factor); - } - } + Relation::accumulate( + std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); + + // WORKTODO: disable skipping for the combiner for now.. + // // Check if the relation is skippable to speed up accumulation + // if constexpr (!isSkippable) { + // // If not, accumulate normally + // Relation::accumulate(std::get(univariate_accumulators), + // extended_univariates, + // relation_parameters, + // scaling_factor); + // } else { + // // If so, only compute the contribution if the relation is active + // if (!Relation::skip(extended_univariates)) { + // Relation::accumulate(std::get(univariate_accumulators), + // extended_univariates, + // relation_parameters, + // scaling_factor); + // } + // } // Repeat for the next relation. if constexpr (relation_idx + 1 < Flavor::NUM_RELATIONS) { From cbd58811529adc70e8e1a9041de8a0c6b7b579bc Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Tue, 7 May 2024 14:25:36 +0000 Subject: [PATCH 14/18] fix --- .../barretenberg/polynomials/univariate.hpp | 9 ++-- .../protogalaxy/protogalaxy_prover.hpp | 53 ++++++++++++------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index 5096eebf1d99..e4821a242954 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -89,10 +89,13 @@ template class ProtoGalaxyProver_ { Relation::accumulate( std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); - // WORKTODO: disable skipping for the combiner for now.. - // // Check if the relation is skippable to speed up accumulation - // if constexpr (!isSkippable) { - // // If not, accumulate normally - // Relation::accumulate(std::get(univariate_accumulators), - // extended_univariates, - // relation_parameters, - // scaling_factor); - // } else { - // // If so, only compute the contribution if the relation is active - // if (!Relation::skip(extended_univariates)) { - // Relation::accumulate(std::get(univariate_accumulators), - // extended_univariates, - // relation_parameters, - // scaling_factor); - // } - // } + // Check if the relation is skippable to speed up accumulation + if constexpr (!isSkippable) { + // If not, accumulate normally + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } else { + // If so, only compute the contribution if the relation is active + if (!Relation::skip(extended_univariates)) { + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } + } // Repeat for the next relation. if constexpr (relation_idx + 1 < Flavor::NUM_RELATIONS) { @@ -368,9 +367,23 @@ template class ProtoGalaxyProver_ { const FF& scaling_factor) { using Relation = std::tuple_element_t; - Relation::accumulate( - std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); - + // WORKTODO: disable skipping for the combiner for now.. + // Check if the relation is skippable to speed up accumulation + if constexpr (!isSkippable) { + // If not, accumulate normally + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } else { + // If so, only compute the contribution if the relation is active + if (!Relation::skip(extended_univariates)) { + Relation::accumulate(std::get(univariate_accumulators), + extended_univariates, + relation_parameters, + scaling_factor); + } + } // Repeat for the next relation. if constexpr (relation_idx + 1 < Flavor::NUM_RELATIONS) { accumulate_relation_univariates< From 00574cf4cd1820c5e741adc40c15058cf01d8399 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Tue, 7 May 2024 15:36:29 +0000 Subject: [PATCH 15/18] fix --- .../cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 58099180755c..6629142a5188 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -324,9 +324,6 @@ template class ProtoGalaxyProver_ { { using Relation = std::tuple_element_t; - Relation::accumulate( - std::get(univariate_accumulators), extended_univariates, relation_parameters, scaling_factor); - // Check if the relation is skippable to speed up accumulation if constexpr (!isSkippable) { // If not, accumulate normally From 5cc888680d38c5754bbdcecc8b46ec320fe12e30 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 7 May 2024 20:38:06 +0000 Subject: [PATCH 16/18] Add remote wasm comparison script; update other to match. --- .../compare_branch_vs_baseline_remote.sh | 17 ++----- .../compare_branch_vs_baseline_remote_wasm.sh | 50 +++++++++++++++++++ 2 files changed, 53 insertions(+), 14 deletions(-) create mode 100755 barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh diff --git a/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh index 27d1af8966ae..1e1953734295 100755 --- a/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh +++ b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh @@ -11,7 +11,7 @@ # Specify the benchmark suite and the "baseline" branch against which to compare BENCHMARK=${1:-goblin_bench} -FILTER=${2:-""} +FILTER=${2:-"*."} PRESET=${3:-clang16} BUILD_DIR=${4:-build} HARDWARE_CONCURRENCY=${HARDWARE_CONCURRENCY:-16} @@ -24,12 +24,7 @@ echo -e "\nComparing $BENCHMARK between $BASELINE_BRANCH and current branch:" # Move above script dir. cd $(dirname $0)/.. -# Configure and build benchmark in feature branch -echo -e "\nConfiguring and building $BENCHMARK in current feature branch...\n" -cmake --preset $PRESET -cmake --build --preset $PRESET --target $BENCHMARK - -# Run bench in current branch +# Run benchmark in current branch echo -e "\nRunning benchmark in feature branch.." ./scripts/benchmark_remote.sh $BENCHMARK\ "./$BENCHMARK --benchmark_filter=$FILTER\ @@ -40,13 +35,7 @@ echo -e "\nRunning benchmark in feature branch.." scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build/results_after.json $BUILD_DIR/ -# Configure and build benchmark in $BASELINE branch -echo -e "\nConfiguring and building $BENCHMARK in $BASELINE_BRANCH...\n" -git checkout $BASELINE_BRANCH -cmake --preset $PRESET -cmake --build --preset $PRESET --target $BENCHMARK - -# Run bench in current branch +# Run benchmark in $BASELINE branch echo -e "\nRunning benchmark in feature branch.." ./scripts/benchmark_remote.sh $BENCHMARK\ "./$BENCHMARK --benchmark_filter=$FILTER\ diff --git a/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh new file mode 100755 index 000000000000..d4e8d338fb24 --- /dev/null +++ b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +# Install requirements (numpy + scipy) for comparison script if necessary. +# Note: By default, installation will occur in $HOME/.local/bin. +# pip3 install --user -r $BUILD_DIR/_deps/benchmark-src/requirements.txt + + +# This script is used to compare a suite of benchmarks between baseline (default: master) and +# the branch from which the script is run. Simply check out the branch of interest, ensure +# it is up to date with local master, and run the script. + +# Specify the benchmark suite and the "baseline" branch against which to compare +BENCHMARK=${1:-goblin_bench} +FILTER=${2:-"*."} +PRESET=${3:-wasm-threads} +BUILD_DIR=${4:-build-wasm-threads} +HARDWARE_CONCURRENCY=${HARDWARE_CONCURRENCY:-16} + +BASELINE_BRANCH="master" +BENCH_TOOLS_DIR="$BUILD_DIR/_deps/benchmark-src/tools" + +echo -e "\nComparing $BENCHMARK between $BASELINE_BRANCH and current branch:" + +# Move above script dir. +cd $(dirname $0)/.. + +# Run benchmark in feature branch +echo -e "\nRunning benchmark in feature branch.." +./scripts/benchmark_wasm_remote.sh $BENCHMARK\ + "./$BENCHMARK --benchmark_filter=$FILTER\ + --benchmark_out=../results_after.json\ + --benchmark_out_format=json" + +scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/results_after.json $BUILD_DIR/ + +# Run benchmark in $BASELINE branch +echo -e "\nRunning benchmark in feature branch.." +./scripts/benchmark_wasm_remote.sh $BENCHMARK\ + "./$BENCHMARK --benchmark_filter=$FILTER\ + --benchmark_out=../results_before.json\ + --benchmark_out_format=json" + +scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/results_before.json $BUILD_DIR/ + +# Call compare.py on the results (json) to get high level statistics. +# See docs at https://github.com/google/benchmark/blob/main/docs/tools.md for more details. +$BENCH_TOOLS_DIR/compare.py benchmarks $BUILD_DIR/results_before.json $BUILD_DIR/results_after.json + +# Return to branch from which the script was called +git checkout - \ No newline at end of file From 87cd43b53eeb45c474b275534d189c81dfa24f6e Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 7 May 2024 21:17:17 +0000 Subject: [PATCH 17/18] Fix scripts to actually check out master --- barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh | 3 ++- .../cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh index 1e1953734295..edd23d05119a 100755 --- a/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh +++ b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote.sh @@ -35,7 +35,8 @@ echo -e "\nRunning benchmark in feature branch.." scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build/results_after.json $BUILD_DIR/ -# Run benchmark in $BASELINE branch +# Run benchmark in baseline branch +git checkout $BASELINE_BRANCH echo -e "\nRunning benchmark in feature branch.." ./scripts/benchmark_remote.sh $BENCHMARK\ "./$BENCHMARK --benchmark_filter=$FILTER\ diff --git a/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh index d4e8d338fb24..d7732ffc41a8 100755 --- a/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh +++ b/barretenberg/cpp/scripts/compare_branch_vs_baseline_remote_wasm.sh @@ -34,7 +34,9 @@ echo -e "\nRunning benchmark in feature branch.." scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/results_after.json $BUILD_DIR/ # Run benchmark in $BASELINE branch -echo -e "\nRunning benchmark in feature branch.." + +echo -e "\nRunning benchmark in baseline branch.." +git checkout $BASELINE_BRANCH ./scripts/benchmark_wasm_remote.sh $BENCHMARK\ "./$BENCHMARK --benchmark_filter=$FILTER\ --benchmark_out=../results_before.json\ From 5bc929bd501241dd2fa3cf1293ee224a0a466b42 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 7 May 2024 21:35:53 +0000 Subject: [PATCH 18/18] Make specific script for client ivc. --- barretenberg/cpp/scripts/compare_client_ivc_bench.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 barretenberg/cpp/scripts/compare_client_ivc_bench.sh diff --git a/barretenberg/cpp/scripts/compare_client_ivc_bench.sh b/barretenberg/cpp/scripts/compare_client_ivc_bench.sh new file mode 100755 index 000000000000..aa4179d6df07 --- /dev/null +++ b/barretenberg/cpp/scripts/compare_client_ivc_bench.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eu + +./scripts/compare_branch_vs_baseline_remote_wasm.sh client_ivc_bench 'Full/6$' \ No newline at end of file