-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generalize protogalaxy to multiple instances #5510
Changes from all commits
eb8c280
4908a07
d1dba82
30dbebe
e386a21
6c64e89
f44d46d
256c977
edcc0a4
feaf9e2
4ec0955
0ae2601
4073295
233464d
80570ec
1fd33b4
ba8d500
bbee18f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could delete this script; was used to get a breakdown of protogalaxy bench |
||
from pathlib import Path | ||
|
||
PREFIX = Path("build-op-count-time") | ||
PROTOGALAXY_BENCH_JSON = Path("protogalaxy_bench.json") | ||
BENCHMARK = "fold_k<GoblinUltraFlavor, 3>/16" | ||
|
||
# Single out an independent set of functions accounting for most of BENCHMARK's real_time | ||
to_keep = [ | ||
"ProtogalaxyProver::fold_instances(t)", | ||
] | ||
with open(PREFIX/PROTOGALAXY_BENCH_JSON, "r") as read_file: | ||
read_result = json.load(read_file) | ||
for _bench in read_result["benchmarks"]: | ||
print(_bench) | ||
if _bench["name"] == BENCHMARK: | ||
bench = _bench | ||
bench_components = dict(filter(lambda x: x[0] in to_keep, bench.items())) | ||
|
||
# For each kept time, get the proportion over all kept times. | ||
sum_of_kept_times_ms = sum(float(time) | ||
for _, time in bench_components.items())/1e6 | ||
max_label_length = max(len(label) for label in to_keep) | ||
column = {"function": "function", "ms": "ms", "%": "% sum"} | ||
print( | ||
f"{column['function']:<{max_label_length}}{column['ms']:>8} {column['%']:>8}") | ||
for key in to_keep: | ||
time_ms = bench[key]/1e6 | ||
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}") | ||
|
||
# Validate that kept times account for most of the total measured time. | ||
total_time_ms = bench["real_time"] | ||
totals = '\nTotal time accounted for: {:.0f}ms/{:.0f}ms = {:.2%}' | ||
totals = totals.format( | ||
sum_of_kept_times_ms, total_time_ms, sum_of_kept_times_ms/total_time_ms) | ||
print(totals) | ||
|
||
print("\nMajor contributors:") | ||
print( | ||
f"{column['function']:<{max_label_length}}{column['ms']:>8} {column['%']:>7}") | ||
for key in ['commit(t)', 'compute_combiner(t)', 'compute_perturbator(t)', 'compute_univariate(t)']: | ||
if key not in bench: | ||
time_ms = 0 | ||
else: | ||
time_ms = bench[key]/1e6 | ||
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/sum_of_kept_times_ms:>8.2%}") | ||
|
||
print('\nBreakdown of ProtogalaxyProver::fold_instances:') | ||
protogalaxy_round_labels = [ | ||
"ProtoGalaxyProver_::preparation_round(t)", | ||
"ProtoGalaxyProver_::perturbator_round(t)", | ||
"ProtoGalaxyProver_::combiner_quotient_round(t)", | ||
"ProtoGalaxyProver_::accumulator_update_round(t)" | ||
] | ||
max_label_length = max(len(label) for label in protogalaxy_round_labels) | ||
for key in protogalaxy_round_labels: | ||
time_ms = bench[key]/1e6 | ||
total_time_ms = bench["ProtogalaxyProver::fold_instances(t)"]/1e6 | ||
print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
TARGET="protogalaxy_bench" | ||
FILTER="/16$" | ||
BUILD_DIR=build-op-count-time | ||
|
||
# Move above script dir. | ||
cd $(dirname $0)/.. | ||
|
||
# Measure the benchmarks with ops time counting | ||
./scripts/benchmark_remote.sh protogalaxy_bench\ | ||
"./protogalaxy_bench --benchmark_filter=$FILTER\ | ||
--benchmark_out=$TARGET.json\ | ||
--benchmark_out_format=json"\ | ||
op-count-time\ | ||
build-op-count-time | ||
|
||
# Retrieve output from benching instance | ||
cd $BUILD_DIR | ||
scp $BB_SSH_KEY $BB_SSH_INSTANCE:$BB_SSH_CPP_PATH/build/$TARGET.json . | ||
|
||
# Analyze the results | ||
cd ../ | ||
python3 ./scripts/analyze_protogalaxy_bench.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include "barretenberg/common/op_count_google_bench.hpp" | ||
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" | ||
|
@@ -11,11 +12,11 @@ using namespace benchmark; | |
namespace bb { | ||
|
||
// Fold one instance into an accumulator. | ||
template <typename Flavor> void fold_one(State& state) noexcept | ||
template <typename Flavor, size_t k> void fold_k(State& state) noexcept | ||
{ | ||
using ProverInstance = ProverInstance_<Flavor>; | ||
using Instance = ProverInstance; | ||
using Instances = ProverInstances_<Flavor, 2>; | ||
using Instances = ProverInstances_<Flavor, k + 1>; | ||
using ProtoGalaxyProver = ProtoGalaxyProver_<Instances>; | ||
using Builder = typename Flavor::CircuitBuilder; | ||
|
||
|
@@ -28,19 +29,29 @@ template <typename Flavor> void fold_one(State& state) noexcept | |
MockCircuits::construct_arithmetic_circuit(builder, log2_num_gates); | ||
return std::make_shared<ProverInstance>(builder); | ||
}; | ||
std::vector<std::shared_ptr<Instance>> instances; | ||
// TODO(https://github.com/AztecProtocol/barretenberg/issues/938): Parallelize this loop | ||
for (size_t i = 0; i < k + 1; ++i) { | ||
instances.emplace_back(construct_instance()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mb it's worth paralellising this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its outside the actual benchmark so its fine |
||
} | ||
|
||
std::shared_ptr<Instance> instance_1 = construct_instance(); | ||
std::shared_ptr<Instance> instance_2 = construct_instance(); | ||
|
||
ProtoGalaxyProver folding_prover({ instance_1, instance_2 }); | ||
ProtoGalaxyProver folding_prover(instances); | ||
|
||
for (auto _ : state) { | ||
BB_REPORT_OP_COUNT_IN_BENCH(state); | ||
auto proof = folding_prover.fold_instances(); | ||
} | ||
} | ||
|
||
BENCHMARK(fold_one<UltraFlavor>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
BENCHMARK(fold_one<GoblinUltraFlavor>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
BENCHMARK(fold_k<UltraFlavor, 1>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
BENCHMARK(fold_k<GoblinUltraFlavor, 1>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
|
||
BENCHMARK(fold_k<UltraFlavor, 2>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
BENCHMARK(fold_k<GoblinUltraFlavor, 2>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
|
||
BENCHMARK(fold_k<UltraFlavor, 3>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
BENCHMARK(fold_k<GoblinUltraFlavor, 3>)->/* vary the circuit size */ DenseRange(14, 20)->Unit(kMillisecond); | ||
|
||
} // namespace bb | ||
|
||
BENCHMARK_MAIN(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
making this script less brittle