diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py new file mode 100644 index 000000000000..3454548f759e --- /dev/null +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -0,0 +1,38 @@ +import json +from pathlib import Path + +PREFIX = Path("build-op-count-time") +IVC_BENCH_JSON = Path("ivc_bench.json") +BENCHMARK = "IvcBench/Full/6" + + +ops = {} +to_keep = [ + "construct_mock_function_circuit(t)", + "construct_mock_folding_kernel(t)", + "ProtogalaxyProver::fold_instances(t)", + "Decider::construct_proof(t)", + "ECCVMComposer::create_prover(t)", + "GoblinTranslatorComposer::create_prover(t)", + "eccvm::construct_proof(t)", + "translator::construct_proof(t)", + "Goblin::merge(t)" +] + +to_keep_condition = lambda x: x[0] in to_keep + +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([pair for pair in filter(to_keep_condition, bench.items()) ]) +sum_of_kept_times_ms = sum(float(time) for _, time in bench_components.items())/1e6 +total_time_ms = bench["real_time"] + +print(f'Total time accounted for: {sum_of_kept_times_ms:.0f}ms/{total_time_ms:.0f}ms = {sum_of_kept_times_ms/total_time_ms:.2%}') +print('breakdown:') +for key in to_keep: + time_ms = bench[key]/1e6 + print(key, f"{time_ms: .0f}ms, {time_ms/total_time_ms: .2%}") \ No newline at end of file diff --git a/barretenberg/cpp/scripts/benchmark_client_ivc.sh b/barretenberg/cpp/scripts/benchmark_client_ivc.sh new file mode 100755 index 000000000000..857d25aafbcf --- /dev/null +++ b/barretenberg/cpp/scripts/benchmark_client_ivc.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -eu + +TARGET="ivc_bench" +FILTER="IvcBench/Full/6$" + +BUILD_DIR=build-op-count-time + +# Move above script dir. +cd $(dirname $0)/.. + +# Measure the benchmarks with ops time counting +./scripts/benchmark_remote.sh ivc_bench\ + "./ivc_bench --benchmark_filter=Full/6$\ + --benchmark_out=$TARGET.json\ + --benchmark_out_format=json"\ + op-count-time\ + build-op-count-time + +cd $BUILD_DIR +scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build/$TARGET.json . + +# # If needed, benchmark the basic Fr operations +# FIELD_OP_COSTS=field_op_costs.json +# if [ ! -f $FIELD_OP_COSTS ]; then +# cd ../ +# FIELD_OPS_TARGET=fr_straight_bench +# cmake --preset clang16 +# cmake --build --preset clang16 --target $FIELD_OPS_TARGET +# cd build +# ./bin/$FIELD_OPS_TARGET --benchmark_out=../$BUILD_DIR/$FIELD_OP_COSTS \ +# --benchmark_out_format=json +# fi + +# # Compute the singly-threaded benchmarks for comparison +# cd ../ +# ./scripts/benchmark_remote.sh goblin_bench "taskset -c 0 ./goblin_bench --benchmark_filter=Full/1$" + +cd ../ + +# Analyze the results +python3 ./scripts/analyze_client_ivc_bench.py diff --git a/barretenberg/cpp/scripts/benchmark_wasm_client_ivc.sh b/barretenberg/cpp/scripts/benchmark_wasm_client_ivc.sh new file mode 100644 index 000000000000..67c9bc8c8704 --- /dev/null +++ b/barretenberg/cpp/scripts/benchmark_wasm_client_ivc.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -eu + +TARGET="ivc_bench" +FILTER="IvcBench/Full/6$" + +BUILD_DIR=build-op-count-time + +# Move above script dir. +cd $(dirname $0)/.. + +# Measure the benchmarks with ops time counting +./scripts/benchmark_wasm_remote.sh ivc_bench\ + "./ivc_bench --benchmark_filter=Full/6$\ + --benchmark_out=$TARGET.json\ + --benchmark_out_format=json"\ + op-count-time\ + build-op-count-time + +cd $BUILD_DIR +scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build/$TARGET.json . + +cd ../ + +# Analyze the results +python3 ./scripts/analyze_client_ivc_bench.py diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp index 0b524505d7e0..dcf158348013 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp @@ -30,6 +30,7 @@ void ClientIVC::initialize(ClientCircuit& circuit) */ ClientIVC::FoldProof ClientIVC::accumulate(ClientCircuit& circuit) { + BB_OP_COUNT_TIME_NAME("ClientIVC::accumulate"); goblin.merge(circuit); // Add recursive merge verifier and construct new merge proof Composer composer; prover_instance = composer.create_prover_instance(circuit); diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp index e111aac9469a..3f8d20b019f7 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp @@ -30,6 +30,8 @@ template ECCVMProver_ ECCVMComposer_::create_prover(CircuitConstructor& circuit_constructor, const std::shared_ptr& transcript) { + BB_OP_COUNT_TIME_NAME("ECCVMComposer::create_prover"); + compute_proving_key(circuit_constructor); compute_witness(circuit_constructor); compute_commitment_key(proving_key->circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp index 58e525278e9b..e0d740c12f72 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp @@ -282,6 +282,8 @@ template HonkProof& ECCVMProver_::export_proof() template HonkProof& ECCVMProver_::construct_proof() { + BB_OP_COUNT_TIME_NAME("eccvm::construct_proof"); + execute_preamble_round(); execute_wire_commitments_round(); diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index fdfed9ef41d7..6bf7cdcd9e19 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -130,6 +130,7 @@ class Goblin { */ void merge(GoblinUltraCircuitBuilder& circuit_builder) { + BB_OP_COUNT_TIME_NAME("Goblin::merge"); // Complete the circuit logic by recursively verifying previous merge proof if it exists if (merge_proof_exists) { RecursiveMergeVerifier merge_verifier{ &circuit_builder }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp index 14c2c368f233..e261871d210d 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp @@ -364,6 +364,7 @@ class GoblinTranslatorCircuitBuilder : public CircuitBuilderBase { std::shared_ptr op_queue) : GoblinTranslatorCircuitBuilder(batching_challenge_v_, evaluation_input_x_) { + BB_OP_COUNT_TIME_NAME("GoblinTranslatorCircuitBuilder::constructor"); feed_ecc_op_queue_into_circuit(op_queue); } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp index ccac06c79282..f589506b384a 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/decider_prover.cpp @@ -1,4 +1,5 @@ #include "decider_prover.hpp" +#include "barretenberg/common/op_count.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" namespace bb { @@ -57,6 +58,7 @@ template HonkProof& DeciderProver_::export_proof( template HonkProof& DeciderProver_::construct_proof() { + BB_OP_COUNT_TIME_NAME("Decider::construct_proof"); // Run sumcheck subprotocol. execute_relation_check_rounds(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index ec7d9dbaa912..8d505a509592 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -249,6 +249,7 @@ template void ProtoGalaxyProver_::accum template FoldingResult ProtoGalaxyProver_::fold_instances() { + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::fold_instances"); preparation_round(); perturbator_round(); combiner_quotient_round(); diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp index 50b111ef9bc5..24767656fd65 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_composer.cpp @@ -190,6 +190,7 @@ void GoblinTranslatorComposer::compute_witness(CircuitBuilder& circuit_builder) GoblinTranslatorProver GoblinTranslatorComposer::create_prover(CircuitBuilder& circuit_builder, const std::shared_ptr& transcript) { + BB_OP_COUNT_TIME_NAME("GoblinTranslatorComposer::create_prover"); // Compute total number of gates, dyadic circuit size, etc. compute_circuit_size_parameters(circuit_builder); diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_prover.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_prover.cpp index 11a557a1b98f..19c6be126651 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/goblin_translator_prover.cpp @@ -176,6 +176,8 @@ HonkProof& GoblinTranslatorProver::export_proof() HonkProof& GoblinTranslatorProver::construct_proof() { + BB_OP_COUNT_TIME_NAME("translator::construct_proof"); + // Add circuit size public input size and public inputs to transcript. execute_preamble_round();