Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
relations_acc.bench.cpp
Go to the documentation of this file.
1#include <benchmark/benchmark.h>
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <random>
7#include <tuple>
8
15
18
19using namespace benchmark;
20using namespace bb::avm2;
21
22namespace {
23
24// Using a row of MAX_PARTIAL_RELATION_LENGTH univariates is a better approximation of what proving does.
25// Benchmarking with this would then take into account any gains via the use of Accumulator::View.
26// However, compilation time for the benchmark becomes as long as for prover.cpp.
27struct FakeUnivariateAllEntities {
28 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = AvmFlavor::MAX_PARTIAL_RELATION_LENGTH;
30
31 // We use a large amount of random values to have a better approximation.
32 std::array<DataType, 10000> fixed_random_values;
33
34 FakeUnivariateAllEntities()
35 {
36 for (DataType& value : fixed_random_values) {
38 }
39 }
40 const DataType& get(ColumnAndShifts) const
41 {
42 size_t index = static_cast<size_t>(rand()) % fixed_random_values.size();
43 return fixed_random_values[index];
44 }
45};
46
47FakeUnivariateAllEntities get_random_row()
48{
49 static FakeUnivariateAllEntities instance;
50 return instance;
51}
52
53template <typename Relation> auto allocate_result()
54{
56}
57
59{
60 return {
61 .eta = 0,
62 .beta = FF::random_element(),
63 .gamma = FF::random_element(),
64 .public_input_delta = 0,
65 .beta_sqr = 0,
66 .beta_cube = 0,
67 .eccvm_set_permutation_delta = 0,
68 };
69}
70
71template <typename Relation> void BM_accumulate_relation(State& state)
72{
73 auto row = get_random_row();
74 auto params = get_params();
75 FF scaling_factor = 1;
76
77 auto result = allocate_result<Relation>();
78
79 for (auto _ : state) {
80 Relation::accumulate(result, row, params, scaling_factor);
81 }
82}
83
84template <typename Relation> constexpr size_t get_interactions_count()
85{
86 size_t count = 0;
87 using AllInteractions = typename AvmFlavor::LookupRelations;
88 bb::constexpr_for<0, std::tuple_size_v<AllInteractions>, 1>([&]<size_t i>() {
90 if constexpr (Relation::NAME == Interaction::RELATION_NAME) {
91 count++;
92 }
93 });
94 return count;
95}
96
97template <typename Relation> void BM_accumulate_interactions(State& state)
98{
99 using AllInteractions = typename AvmFlavor::LookupRelations;
100 bb::constexpr_for<0, std::tuple_size_v<AllInteractions>, 1>([&]<size_t i>() {
102 if constexpr (Relation::NAME == Interaction::RELATION_NAME) {
103 BM_accumulate_relation<Interaction>(state);
104 }
105 });
106}
107
108} // namespace
109
110int main(int argc, char** argv)
111{
112 bb::constexpr_for<0, std::tuple_size_v<typename AvmFlavor::MainRelations>, 1>([&]<size_t i>() {
114 BENCHMARK(BM_accumulate_relation<Relation>)->Name(std::string(Relation::NAME) + "_acc")->Unit(kMicrosecond);
115
116// This adds a lot of compilation time, so only do it locally.
117#ifdef AVM_BENCHMARK_WITH_LOOKUPS
118 if (get_interactions_count<Relation>() > 0) {
119 BENCHMARK(BM_accumulate_interactions<Relation>)
120 ->Name(std::string(Relation::NAME) + "_interactions_acc")
121 ->Unit(kMicrosecond);
122 }
123#endif // AVM_BENCHMARK_WITH_LOOKUPS
124 });
125
126 ::benchmark::Initialize(&argc, argv);
127 ::benchmark::RunSpecifiedBenchmarks();
128}
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
TupleOfUnivariates< FF, RelationImpl::SUBRELATION_PARTIAL_LENGTHS > SumcheckTupleOfUnivariatesOverSubrelations
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
static Univariate random_element()
LookupRelations_< FF > LookupRelations
Definition flavor.hpp:78
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
Definition flavor.hpp:88
ColumnAndShifts
Definition columns.hpp:34
BENCHMARK(extend_2_to_11)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
int main(int argc, char **argv)
Container for parameters used by the grand product (permutation, lookup) Honk relations.
static field random_element(numeric::RNG *engine=nullptr) noexcept