Skip to content

Commit

Permalink
Move timers and improve benchmark.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Mar 12, 2024
1 parent 401557e commit d7fbca1
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 32 deletions.
3 changes: 1 addition & 2 deletions barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
11 changes: 7 additions & 4 deletions barretenberg/cpp/scripts/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <benchmark/benchmark.h>

#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"
Expand Down Expand Up @@ -46,9 +47,12 @@ class ClientIVCBench : public benchmark::Fixture {
std::vector<Builder> 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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ClientIVC::VerifierInstance>(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 };
Expand Down
2 changes: 0 additions & 2 deletions barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -233,7 +232,6 @@ class GoblinMockCircuits {
const VerifierFoldData& kernel,
std::shared_ptr<VerifierInstance>& prev_kernel_accum)
{
BB_OP_COUNT_TIME();
using GURecursiveFlavor = GoblinUltraRecursiveFlavor_<GoblinUltraBuilder>;
using RecursiveVerifierInstances =
bb::stdlib::recursion::honk::RecursiveVerifierInstances_<GURecursiveFlavor, 2>;
Expand Down

0 comments on commit d7fbca1

Please sign in to comment.