From d7fbca14d55e116a8085c9893c6fbf68ee6b0324 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 12 Mar 2024 01:46:15 +0000 Subject: [PATCH 1/3] Move timers and improve benchmark.sh --- .../cpp/scripts/analyze_client_ivc_bench.py | 3 +- barretenberg/cpp/scripts/benchmark.sh | 11 ++-- .../client_ivc_bench/client_ivc.bench.cpp | 61 +++++++++++-------- .../src/barretenberg/goblin/mock_circuits.hpp | 2 - 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index d9b5e047b1f6..c462b9771f13 100644 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -7,8 +7,7 @@ # Single out an independent set of functions accounting for most of BENCHMARK's real_time to_keep = [ - "construct_mock_function_circuit(t)", - "construct_mock_folding_kernel(t)", + "construct_circuits(t)", "ProverInstance(Circuit&)(t)", "ProtogalaxyProver::fold_instances(t)", "Decider::construct_proof(t)", diff --git a/barretenberg/cpp/scripts/benchmark.sh b/barretenberg/cpp/scripts/benchmark.sh index 93b963771732..6b6758700f48 100755 --- a/barretenberg/cpp/scripts/benchmark.sh +++ b/barretenberg/cpp/scripts/benchmark.sh @@ -2,16 +2,19 @@ set -eu BENCHMARK=${1:-goblin_bench} -COMMAND=${2:-./bin/$BENCHMARK} +COMMAND=${2:-./$BENCHMARK} +PRESET=${3:-clang16} +BUILD_DIR=${4:-build} + # Move above script dir. cd $(dirname $0)/.. # Configure and build. -cmake --preset clang16 -cmake --build --preset clang16 --target $BENCHMARK +cmake --preset $PRESET +cmake --build --preset $PRESET --target $BENCHMARK -cd build +cd $BUILD_DIR # Consistency with _wasm.sh targets / shorter $COMMAND. cp ./bin/$BENCHMARK . $COMMAND \ 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 f65385da92e1..2ace58eb6e64 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 @@ -2,6 +2,7 @@ #include #include "barretenberg/client_ivc/client_ivc.hpp" +#include "barretenberg/common/op_count.hpp" #include "barretenberg/common/op_count_google_bench.hpp" #include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" @@ -46,9 +47,12 @@ class ClientIVCBench : public benchmark::Fixture { std::vector initial_function_circuits(2); // Construct 2 starting function circuits in parallel - parallel_for(2, [&](size_t circuit_index) { - GoblinMockCircuits::construct_mock_function_circuit(initial_function_circuits[circuit_index]); - }); + { + BB_OP_COUNT_TIME_NAME("construct_circuits"); + parallel_for(2, [&](size_t circuit_index) { + GoblinMockCircuits::construct_mock_function_circuit(initial_function_circuits[circuit_index]); + }); + }; // Prepend queue to the first circuit initial_function_circuits[0].op_queue->prepend_previous_queue(*ivc.goblin.op_queue); @@ -81,25 +85,28 @@ class ClientIVCBench : public benchmark::Fixture { Builder kernel_circuit{ size_hint, ivc.goblin.op_queue }; Builder function_circuit{ size_hint }; // Construct function and kernel circuits in parallel - parallel_for(2, [&](size_t workload_idx) { - // workload index is 0 for kernel and 1 for function - if (workload_idx == 0) { - if (circuit_idx == 0) { - - // Create the first folding kernel which only verifies the accumulation of a - // function circuit - kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( - kernel_circuit, function_fold_output, {}, kernel_verifier_accumulator); + { + BB_OP_COUNT_TIME_NAME("construct_circuits"); + parallel_for(2, [&](size_t workload_idx) { + // workload index is 0 for kernel and 1 for function + if (workload_idx == 0) { + if (circuit_idx == 0) { + + // Create the first folding kernel which only verifies the accumulation of a + // function circuit + kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( + kernel_circuit, function_fold_output, {}, kernel_verifier_accumulator); + } else { + // Create kernel circuit containing the recursive folding verification of a function circuit + // and a kernel circuit + kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( + kernel_circuit, function_fold_output, kernel_fold_output, kernel_verifier_accumulator); + } } else { - // Create kernel circuit containing the recursive folding verification of a function circuit and - // a kernel circuit - kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( - kernel_circuit, function_fold_output, kernel_fold_output, kernel_verifier_accumulator); + GoblinMockCircuits::construct_mock_function_circuit(function_circuit); } - } else { - GoblinMockCircuits::construct_mock_function_circuit(function_circuit); - } - }); + }); + }; // No need to prepend queue, it's the same after last swap // Accumulate kernel circuit @@ -127,14 +134,20 @@ class ClientIVCBench : public benchmark::Fixture { // Create and accumulate the first folding kernel which only verifies the accumulation of a function circuit Builder kernel_circuit{ size_hint, ivc.goblin.op_queue }; auto kernel_verifier_accumulator = std::make_shared(ivc.vks.first_func_vk); - kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( - kernel_circuit, function_fold_output, {}, kernel_verifier_accumulator); + { + BB_OP_COUNT_TIME_NAME("construct_circuits"); + kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( + kernel_circuit, function_fold_output, {}, kernel_verifier_accumulator); + } auto kernel_fold_proof = ivc.accumulate(kernel_circuit); kernel_fold_output = { kernel_fold_proof, ivc.vks.first_kernel_vk }; } else { Builder kernel_circuit{ size_hint, ivc.goblin.op_queue }; - kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( - kernel_circuit, function_fold_output, kernel_fold_output, kernel_verifier_accumulator); + { + BB_OP_COUNT_TIME_NAME("construct_circuits"); + kernel_verifier_accumulator = GoblinMockCircuits::construct_mock_folding_kernel( + kernel_circuit, function_fold_output, kernel_fold_output, kernel_verifier_accumulator); + } auto kernel_fold_proof = ivc.accumulate(kernel_circuit); kernel_fold_output = { kernel_fold_proof, ivc.vks.kernel_vk }; diff --git a/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp b/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp index 884e5c27ab87..58cc8fc2d2cf 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp @@ -109,7 +109,6 @@ class GoblinMockCircuits { */ static void construct_mock_function_circuit(GoblinUltraBuilder& builder, bool large = false) { - BB_OP_COUNT_TIME(); // Determine number of times to execute the below operations that constitute the mock circuit logic. Note that // the circuit size does not scale linearly with number of iterations due to e.g. amortization of lookup costs const size_t NUM_ITERATIONS_LARGE = 13; // results in circuit size 2^19 (521327 gates) @@ -233,7 +232,6 @@ class GoblinMockCircuits { const VerifierFoldData& kernel, std::shared_ptr& prev_kernel_accum) { - BB_OP_COUNT_TIME(); using GURecursiveFlavor = GoblinUltraRecursiveFlavor_; using RecursiveVerifierInstances = bb::stdlib::recursion::honk::RecursiveVerifierInstances_; From eef04cabb470488d6b5b71b84a305dd22bee3b3a Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 12 Mar 2024 01:55:32 +0000 Subject: [PATCH 2/3] Fix benchmark_client_ivc directory change --- barretenberg/cpp/scripts/benchmark_client_ivc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/scripts/benchmark_client_ivc.sh b/barretenberg/cpp/scripts/benchmark_client_ivc.sh index 08e43f012caa..17a193c6d829 100755 --- a/barretenberg/cpp/scripts/benchmark_client_ivc.sh +++ b/barretenberg/cpp/scripts/benchmark_client_ivc.sh @@ -21,5 +21,5 @@ cd $BUILD_DIR scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build/$TARGET.json . # Analyze the results -cd $(dirname $0)/.. +cd ../ python3 ./scripts/analyze_client_ivc_bench.py From 03140fdad3e4d6b1dc99c6786279b0a328c8408e Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 12 Mar 2024 02:35:17 +0000 Subject: [PATCH 3/3] Breakdown of ECCVM::create_prover --- barretenberg/cpp/scripts/analyze_client_ivc_bench.py | 6 ++++++ barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp | 4 ++++ barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp | 1 + 3 files changed, 11 insertions(+) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index c462b9771f13..0e95053b443f 100644 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -41,3 +41,9 @@ totals = totals.format( sum_of_kept_times_ms, total_time_ms, sum_of_kept_times_ms/total_time_ms) print(totals) + +print('\nBreakdown of ECCVMProver::create_prover:') +for key in ["ECCVMComposer::compute_witness(t)", "ECCVMComposer::create_proving_key(t)"]: + time_ms = bench[key]/1e6 + total_time_ms = bench["ECCVMComposer::create_prover(t)"]/1e6 + print(f"{key:<{MAX_LABEL_LENGTH}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}") diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp index 3f8d20b019f7..bf5b4c7316c8 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp @@ -10,6 +10,8 @@ namespace bb { */ template void ECCVMComposer_::compute_witness(CircuitConstructor& circuit_constructor) { + BB_OP_COUNT_TIME_NAME("ECCVMComposer::compute_witness"); + if (computed_witness) { return; } @@ -67,6 +69,8 @@ template std::shared_ptr ECCVMComposer_::compute_proving_key( CircuitConstructor& circuit_constructor) { + BB_OP_COUNT_TIME_NAME("ECCVMComposer::create_proving_key"); + if (proving_key) { return proving_key; } diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp index 03630f5b239e..a33446e6caa4 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.hpp @@ -70,6 +70,7 @@ template class ECCVMComposer_ { void compute_commitment_key(size_t circuit_size) { + BB_OP_COUNT_TIME_NAME("ECCVMComposer::compute_commitment_key"); commitment_key = std::make_shared(circuit_size); }; };