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#ifdef AVM_COMPILE_BENCHMARKS
2
3#include <benchmark/benchmark.h>
4
5#include <cstddef>
6#include <cstdint>
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.
27#ifdef AVM_USE_UNIVARIATES
28
29struct FakeUnivariateAllEntities {
30 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = AvmFlavor::MAX_PARTIAL_RELATION_LENGTH;
32
33 DataType fixed_random_value;
34
35 FakeUnivariateAllEntities(const DataType& fixed_random_value)
36 : fixed_random_value(fixed_random_value)
37 {}
38 const DataType& get(ColumnAndShifts) const { return fixed_random_value; }
39};
40
41FakeUnivariateAllEntities get_random_row()
42{
43 return FakeUnivariateAllEntities(FakeUnivariateAllEntities::DataType::random_element());
44}
45
46template <typename Relation> auto allocate_result()
47{
49}
50
51// Otherwise, we use a fake row of FFs, which is closer to what check-circuit does.
52// This disregards any gains via the use of Accumulator::View.
53#else
54
55struct FakeAvmFullRow {
56 using DataType = FF;
57
58 FakeAvmFullRow(const FF& fixed_random_value)
59 : fixed_random_value(fixed_random_value)
60 {}
61 const FF& get(ColumnAndShifts) const { return fixed_random_value; }
62
63 FF fixed_random_value;
64};
65
66FakeAvmFullRow get_random_row()
67{
68 return FakeAvmFullRow(FF::random_element());
69}
70
71template <typename Relation> auto allocate_result()
72{
74}
75
76#endif // AVM_USE_UNIVARIATES
77
79{
80 return {
81 .eta = 0,
82 .beta = FF::random_element(),
83 .gamma = FF::random_element(),
84 .public_input_delta = 0,
85 .beta_sqr = 0,
86 .beta_cube = 0,
87 .eccvm_set_permutation_delta = 0,
88 };
89}
90
91template <typename Relation> void BM_accumulate_relation(State& state)
92{
93 auto row = get_random_row();
94 auto params = get_params();
95 FF scaling_factor = 1;
96
97 auto result = allocate_result<Relation>();
98
99 for (auto _ : state) {
100 Relation::accumulate(result, row, params, scaling_factor);
101 }
102}
103
104template <typename Relation> constexpr size_t get_interactions_count()
105{
106 size_t count = 0;
107 using AllInteractions = typename AvmFlavor::LookupRelations;
108 bb::constexpr_for<0, std::tuple_size_v<AllInteractions>, 1>([&]<size_t i>() {
110 if constexpr (Relation::NAME == Interaction::RELATION_NAME) {
111 count++;
112 }
113 });
114 return count;
115}
116
117template <typename Relation> void BM_accumulate_interactions(State& state)
118{
119 using AllInteractions = typename AvmFlavor::LookupRelations;
120 bb::constexpr_for<0, std::tuple_size_v<AllInteractions>, 1>([&]<size_t i>() {
122 if constexpr (Relation::NAME == Interaction::RELATION_NAME) {
123 BM_accumulate_relation<Interaction>(state);
124 }
125 });
126}
127
128} // namespace
129
130int main(int argc, char** argv)
131{
132 bb::constexpr_for<0, std::tuple_size_v<typename AvmFlavor::MainRelations>, 1>([&]<size_t i>() {
134 BENCHMARK(BM_accumulate_relation<Relation>)->Name(std::string(Relation::NAME) + "_acc")->Unit(kMicrosecond);
135 if (get_interactions_count<Relation>() > 0) {
136 BENCHMARK(BM_accumulate_interactions<Relation>)
137 ->Name(std::string(Relation::NAME) + "_interactions_acc")
138 ->Unit(kMicrosecond);
139 }
140 });
141
142 ::benchmark::Initialize(&argc, argv);
143 ::benchmark::RunSpecifiedBenchmarks();
144}
145
146#else
147
148#include <iostream>
149
150int main(int, char**)
151{
152 std::cout << "This benchmark is disabled. To enable it, define AVM_COMPILE_BENCHMARKS." << std::endl;
153 return 0;
154}
155
156#endif // AVM_COMPILE_BENCHMARKS
bb::fr FF
BENCHMARK(parallel_for_field_element_addition) -> Unit(kMicrosecond) ->DenseRange(0, MAX_REPETITION_LOG)
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
ArrayOfValues< FF, RelationImpl::SUBRELATION_PARTIAL_LENGTHS > SumcheckArrayOfValuesOverSubrelations
TupleOfUnivariates< FF, RelationImpl::SUBRELATION_PARTIAL_LENGTHS > SumcheckTupleOfUnivariatesOverSubrelations
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
ColumnAndShifts
Definition columns.hpp:35
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
int main(int, char **)
Container for parameters used by the grand product (permutation, lookup) Honk relations.
static field random_element(numeric::RNG *engine=nullptr) noexcept