Skip to content

Commit

Permalink
feat: Benchmark protogalaxy prover (#3958)
Browse files Browse the repository at this point in the history
Benchmark Protogalaxy prover. This just benchmarks the current folding
function. Future PRs will make update and augment with values that will
better reflect performance in production.

Results: uses 16 cores (for the x86 build). `fold_one/N` measures the
time to call the `fold_instances` function to fold a single instance
into an accumulator where the instance sizes are $2^N$. Note this is for
the Ultra arithmetization (so no Goblin, Poseidon2 or DataBus
relations).

```
% taskset -c 0-15 ./bin/protogalaxy_bench                   38s ~/barretenberg-cpp/build cg/pg-bench mainframe
2024-01-11T19:39:49+00:00
Running ./bin/protogalaxy_bench
Run on (128 X 2649.99 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x64)
  L1 Instruction 32 KiB (x64)
  L2 Unified 512 KiB (x64)
  L3 Unified 32768 KiB (x8)
Load Average: 3.48, 8.51, 27.24
------------------------------------------------------
Benchmark            Time             CPU   Iterations
------------------------------------------------------
fold_one/14        417 ms          259 ms            3
fold_one/15        668 ms          409 ms            2
fold_one/16       1158 ms          696 ms            1
fold_one/17       2245 ms         1433 ms            1
fold_one/18       4168 ms         2644 ms            1
fold_one/19       7890 ms         5119 ms            1
fold_one/20      15809 ms        10633 ms            1
```

Closes AztecProtocol/barretenberg#692
  • Loading branch information
codygunton authored Jan 11, 2024
1 parent a9537fb commit 5843722
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ add_subdirectory(plonk_bench)
add_subdirectory(ultra_bench)
add_subdirectory(goblin_bench)
add_subdirectory(relations_bench)
add_subdirectory(widgets_bench)
add_subdirectory(widgets_bench)
add_subdirectory(protogalaxy_bench)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Each source represents a separate benchmark suite
set(BENCHMARK_SOURCES
protogalaxy.bench.cpp
)

# Required libraries for benchmark suites
set(LINKED_LIBRARIES
ultra_honk
protogalaxy
stdlib_primitives
benchmark::benchmark
)

# Add executable and custom target for each suite, e.g. ultra_honk_bench
foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES})
get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension
add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE})
target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES})
add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endforeach()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <benchmark/benchmark.h>

#include "barretenberg/benchmark/ultra_bench/benchmark_utilities.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"

using namespace benchmark;

namespace proof_system::honk {
using Flavor = flavor::Ultra;
using Instance = ProverInstance_<Flavor>;
using Instances = ProverInstances_<Flavor, 2>;
using ProtoGalaxyProver = ProtoGalaxyProver_<Instances>;
using Builder = Flavor::CircuitBuilder;

// Fold one instance into an accumulator.
void fold_one(State& state) noexcept
{
barretenberg::srs::init_crs_factory("../srs_db/ignition");

auto log2_num_gates = static_cast<size_t>(state.range(0));
auto composer = UltraComposer();

const auto construct_instance = [&]() {
Builder builder;
bench_utils::generate_basic_arithmetic_circuit(builder, log2_num_gates);
return composer.create_instance(builder);
};

std::shared_ptr<Instance> instance_1 = construct_instance();
std::shared_ptr<Instance> instance_2 = construct_instance();

auto folding_prover = composer.create_folding_prover({ instance_1, instance_2 }, composer.commitment_key);

for (auto _ : state) {
auto proof = folding_prover.fold_instances();
}
}

BENCHMARK(fold_one)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond);
} // namespace proof_system::honk
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ template <class ProverInstances_> class ProtoGalaxyProver_ {
*
* TODO(https://github.com/AztecProtocol/barretenberg/issues/753): fold goblin polynomials
*/
FoldingResult<Flavor> fold_instances();
BBERG_PROFILE FoldingResult<Flavor> fold_instances();

/**
* @brief For a new round challenge δ at each iteration of the ProtoGalaxy protocol, compute the vector
Expand Down

0 comments on commit 5843722

Please sign in to comment.