-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an external_bench file with benchmarks we use for external benchmarking projects
- Loading branch information
Showing
7 changed files
with
212 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM alpine:3.17 AS builder | ||
RUN apk update \ | ||
&& apk upgrade \ | ||
&& apk add --no-cache \ | ||
build-base \ | ||
clang15 \ | ||
openmp-dev \ | ||
cmake \ | ||
ninja \ | ||
git \ | ||
curl \ | ||
perl | ||
|
||
WORKDIR /usr/src/barretenberg/cpp | ||
|
||
COPY . . | ||
# Build everything to ensure everything builds. All tests will be run from the result of this build. | ||
RUN cmake --preset default && cmake --build --preset default --target external_bench | ||
|
||
FROM alpine:3.17 | ||
RUN apk update && apk add curl openmp | ||
COPY --from=builder /usr/src/barretenberg/cpp/srs_db /usr/src/barretenberg/cpp/srs_db | ||
COPY --from=builder /usr/src/barretenberg/cpp/build/bin/*_bench /usr/src/barretenberg/cpp/build/bin/ |
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,2 @@ | ||
add_subdirectory(sha256) | ||
add_subdirectory(external) |
1 change: 1 addition & 0 deletions
1
cpp/src/barretenberg/stdlib/hash/benchmarks/external/CMakeLists.txt
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 @@ | ||
barretenberg_module(external stdlib_primitives crypto_sha256 stdlib_sha256 stdlib_blake3s) |
182 changes: 182 additions & 0 deletions
182
cpp/src/barretenberg/stdlib/hash/benchmarks/external/external.bench.cpp
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,182 @@ | ||
/** | ||
* @file external.bench.cpp | ||
* @author Kesha (Rumata888) | ||
* @brief Benchmarks for external benchmarking projects (e.g. delendum-xyz) | ||
* | ||
*/ | ||
#include "../../sha256/sha256.hpp" | ||
#include "../../blake3s/blake3s.hpp" | ||
#include <benchmark/benchmark.h> | ||
#include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
#include "barretenberg/plonk/composer/ultra_composer.hpp" | ||
#include "barretenberg/plonk/proof_system/prover/prover.hpp" | ||
#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" | ||
|
||
using namespace benchmark; | ||
|
||
using Composer = proof_system::plonk::UltraComposer; | ||
using Prover = proof_system::plonk::UltraProver; | ||
using Verifier = proof_system::plonk::UltraVerifier; | ||
|
||
constexpr size_t PROOF_COUNT_LOG = 10; | ||
constexpr size_t NUM_PROOFS = 3; | ||
|
||
/** | ||
* @brief Main function generating a circuit with num_iterations sequential sha256 hashes, where the output of a | ||
* previous iteration is fed into the next one | ||
* | ||
* @param composer | ||
* @param num_iterations | ||
*/ | ||
void generate_test_sha256_plonk_circuit(Composer& composer, size_t num_iterations) | ||
{ | ||
std::string in; | ||
in.resize(32); | ||
for (size_t i = 0; i < 32; ++i) { | ||
in[i] = 0; | ||
} | ||
proof_system::plonk::stdlib::packed_byte_array<Composer> input(&composer, in); | ||
for (size_t i = 0; i < num_iterations; i++) { | ||
input = proof_system::plonk::stdlib::sha256<Composer>(input); | ||
} | ||
} | ||
|
||
Composer external_composers[NUM_PROOFS]; | ||
Prover external_provers[NUM_PROOFS]; | ||
Verifier external_verifiers[NUM_PROOFS]; | ||
plonk::proof external_proofs[NUM_PROOFS]; | ||
|
||
/** | ||
* @brief Construct the circuit for sequential sha256 proofs and compute the proof for each case | ||
* | ||
* @param state | ||
*/ | ||
void generate_sha256_proof_bench(State& state) noexcept | ||
{ | ||
for (auto _ : state) { | ||
|
||
size_t idx = static_cast<size_t>(state.range(0)); | ||
size_t num_iterations = 1; | ||
for (size_t i = 0; i < idx; i++) { | ||
num_iterations *= PROOF_COUNT_LOG; | ||
} | ||
external_composers[idx] = Composer(); | ||
generate_test_sha256_plonk_circuit(external_composers[idx], num_iterations); | ||
external_provers[idx] = external_composers[idx].create_prover(); | ||
external_proofs[idx] = external_provers[idx].construct_proof(); | ||
// info("Proof Size for SHA256 hash count ", num_iterations, ": ", external_proofs[idx].proof_data.size()); | ||
} | ||
} | ||
|
||
/** | ||
* @brief We have to warm up the benchmarking function first, otherwise we spend 50% more time than expected | ||
* | ||
*/ | ||
BENCHMARK(generate_sha256_proof_bench)->DenseRange(0, 2)->MinWarmUpTime(10)->MinTime(2)->Unit(benchmark::kMillisecond); | ||
/** | ||
* @brief Create sha256 verifier | ||
* | ||
* @details We don't want to benchmark this | ||
* | ||
* @param state | ||
*/ | ||
static void generate_sha256_verifier(const State& state) | ||
{ | ||
|
||
size_t idx = static_cast<size_t>(state.range(0)); | ||
external_verifiers[idx] = external_composers[idx].create_verifier(); | ||
} | ||
/** | ||
* @brief Benchmark sha256 verification | ||
* | ||
* @param state | ||
*/ | ||
void verify_sha256_proof_bench(State& state) noexcept | ||
{ | ||
for (auto _ : state) { | ||
|
||
size_t idx = static_cast<size_t>(state.range(0)); | ||
external_verifiers[idx].verify_proof(external_proofs[idx]); | ||
} | ||
} | ||
|
||
BENCHMARK(verify_sha256_proof_bench)->DenseRange(0, 2)->Setup(generate_sha256_verifier)->Unit(benchmark::kMillisecond); | ||
|
||
/** | ||
* @brief Main function for generating Blake 3 circuits | ||
* | ||
* @param composer | ||
* @param num_iterations | ||
*/ | ||
void generate_test_blake3s_plonk_circuit(Composer& composer, size_t num_iterations) | ||
{ | ||
std::string in; | ||
in.resize(32); | ||
for (size_t i = 0; i < 32; ++i) { | ||
in[i] = 0; | ||
} | ||
proof_system::plonk::stdlib::packed_byte_array<Composer> input(&composer, in); | ||
for (size_t i = 0; i < num_iterations; i++) { | ||
input = proof_system::plonk::stdlib::blake3s<Composer>(input); | ||
} | ||
} | ||
|
||
/** | ||
* @brief Blake3 circuit construction and proof creation benchmark function | ||
* | ||
* @param state | ||
*/ | ||
void generate_blake3s_proof_bench(State& state) noexcept | ||
{ | ||
for (auto _ : state) { | ||
|
||
size_t idx = static_cast<size_t>(state.range(0)); | ||
size_t num_iterations = 1; | ||
for (size_t i = 0; i < idx; i++) { | ||
num_iterations *= PROOF_COUNT_LOG; | ||
} | ||
external_composers[idx] = Composer(); | ||
generate_test_blake3s_plonk_circuit(external_composers[idx], num_iterations); | ||
external_provers[idx] = external_composers[idx].create_prover(); | ||
external_proofs[idx] = external_provers[idx].construct_proof(); | ||
// Proof size with no public inputs is always 2144 | ||
// info("Proof Size for Blake3s hash count ", num_iterations, ": ", external_proofs[idx].proof_data.size()); | ||
} | ||
} | ||
|
||
BENCHMARK(generate_blake3s_proof_bench)->DenseRange(0, 2)->MinWarmUpTime(10)->MinTime(2)->Unit(benchmark::kMillisecond); | ||
|
||
/** | ||
* @brief Create blake 3 verifier | ||
* | ||
* @details We don't benchmark verifier creation | ||
* | ||
* @param state | ||
*/ | ||
static void generate_blake3s_verifier(const State& state) | ||
{ | ||
|
||
size_t idx = static_cast<size_t>(state.range(0)); | ||
external_verifiers[idx] = external_composers[idx].create_verifier(); | ||
} | ||
|
||
/** | ||
* @brief Benchmark blake3 proof verification | ||
* | ||
* @param state | ||
*/ | ||
void verify_blake3s_proof_bench(State& state) noexcept | ||
{ | ||
for (auto _ : state) { | ||
|
||
size_t idx = static_cast<size_t>(state.range(0)); | ||
external_verifiers[idx].verify_proof(external_proofs[idx]); | ||
} | ||
} | ||
|
||
BENCHMARK(verify_blake3s_proof_bench) | ||
->DenseRange(0, 2) | ||
->Setup(generate_blake3s_verifier) | ||
->Unit(benchmark::kMillisecond); | ||
|
||
BENCHMARK_MAIN(); |
1 change: 1 addition & 0 deletions
1
cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/CMakeLists.txt
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 @@ | ||
barretenberg_module(stdlib_sha256_just stdlib_sha256) |
2 changes: 1 addition & 1 deletion
2
...nberg/stdlib/hash/sha256/sha256.bench.cpp → ...b/hash/benchmarks/sha256/sha256.bench.cpp
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