Skip to content

Commit

Permalink
Manual client ivc breakdown
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Feb 27, 2024
1 parent 30d92bc commit 8b6c421
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 0 deletions.
38 changes: 38 additions & 0 deletions barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
@@ -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%}")
42 changes: 42 additions & 0 deletions barretenberg/cpp/scripts/benchmark_client_ivc.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ template <IsECCVMFlavor Flavor>
ECCVMProver_<Flavor> ECCVMComposer_<Flavor>::create_prover(CircuitConstructor& circuit_constructor,
const std::shared_ptr<Transcript>& 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);
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ template <IsECCVMFlavor Flavor> HonkProof& ECCVMProver_<Flavor>::export_proof()

template <IsECCVMFlavor Flavor> HonkProof& ECCVMProver_<Flavor>::construct_proof()
{
BB_OP_COUNT_TIME_NAME("eccvm::construct_proof");

execute_preamble_round();

execute_wire_commitments_round();
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/goblin/goblin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ class GoblinTranslatorCircuitBuilder : public CircuitBuilderBase<bb::fr> {
std::shared_ptr<ECCOpQueue> op_queue)
: GoblinTranslatorCircuitBuilder(batching_challenge_v_, evaluation_input_x_)
{
BB_OP_COUNT_TIME_NAME("GoblinTranslatorCircuitBuilder::constructor");
feed_ecc_op_queue_into_circuit(op_queue);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "decider_prover.hpp"
#include "barretenberg/common/op_count.hpp"
#include "barretenberg/sumcheck/sumcheck.hpp"

namespace bb {
Expand Down Expand Up @@ -57,6 +58,7 @@ template <IsUltraFlavor Flavor> HonkProof& DeciderProver_<Flavor>::export_proof(

template <IsUltraFlavor Flavor> HonkProof& DeciderProver_<Flavor>::construct_proof()
{
BB_OP_COUNT_TIME_NAME("Decider::construct_proof");
// Run sumcheck subprotocol.
execute_relation_check_rounds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::accum
template <class ProverInstances>
FoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverInstances>::fold_instances()
{
BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::fold_instances");
preparation_round();
perturbator_round();
combiner_quotient_round();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ void GoblinTranslatorComposer::compute_witness(CircuitBuilder& circuit_builder)
GoblinTranslatorProver GoblinTranslatorComposer::create_prover(CircuitBuilder& circuit_builder,
const std::shared_ptr<Transcript>& transcript)
{
BB_OP_COUNT_TIME_NAME("GoblinTranslatorComposer::create_prover");

// Compute total number of gates, dyadic circuit size, etc.
compute_circuit_size_parameters(circuit_builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 8b6c421

Please sign in to comment.