-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generalize protogalaxy to multiple instances (#5510)
Closes AztecProtocol/barretenberg#764. This PR aims to generalize protogalaxy to multiple instances. In particular, we care about k=2 (1 accumulator and 2 instances) and k=3 and and their performance relative to folding k=1 instance. We achieve the following numbers: ``` -------------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------------- fold_k<UltraFlavor, 1>/16 1039 ms 908 ms 1 fold_k<UltraFlavor, 2>/16 1744 ms 1562 ms 1 fold_k<UltraFlavor, 3>/16 2755 ms 2484 ms 1 fold_k<GoblinUltraFlavor, 1>/16 1431 ms 1231 ms 1 fold_k<GoblinUltraFlavor, 2>/16 2387 ms 2084 ms 1 fold_k<GoblinUltraFlavor, 3>/16 3734 ms 3291 ms 1 ``` and client IVC benchmark stays the same: ``` -------------------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------------------- ClientIVCBench/Full/6 23140 ms 17976 ms 1 Benchmarking lock deleted. client_ivc_bench.json 100% 3561 106.5KB/s 00:00 function ms % sum construct_circuits(t) 4522 19.75% ProverInstance(Circuit&)(t) 2060 9.00% ProtogalaxyProver::fold_instances(t) 12545 54.81% Decider::construct_proof(t) 734 3.21% ECCVMProver(CircuitBuilder&)(t) 158 0.69% ECCVMProver::construct_proof(t) 1768 7.73% GoblinTranslatorProver::construct_proof(t) 959 4.19% Goblin::merge(t) 145 0.63% Total time accounted for: 22890ms/23140ms = 98.92% Major contributors: function ms % sum commit(t) 4283 18.71% compute_combiner(t) 5702 24.91% compute_perturbator(t) 1250 5.46% compute_univariate(t) 1386 6.05% Breakdown of ProtogalaxyProver::fold_instances: ProtoGalaxyProver_::preparation_round(t) 5297 42.22% ProtoGalaxyProver_::perturbator_round(t) 1250 9.97% ProtoGalaxyProver_::combiner_quotient_round(t) 5704 45.47% ProtoGalaxyProver_::accumulator_update_round(t) 294 2.35% ```
- Loading branch information
1 parent
c496a10
commit f038b70
Showing
10 changed files
with
349 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import json | ||
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%}") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.