Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Compile with

- `cmake --preset bench`.
- `cmake --build --preset bench --target relations_acc_bench`.

Run with `( cd build-bench && bin/relations_acc_bench )`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <benchmark/benchmark.h>

#include "barretenberg/common/constexpr_utils.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/vm2/common/field.hpp"
#include "barretenberg/vm2/generated/columns.hpp"
#include "barretenberg/vm2/generated/flavor.hpp"
#include "barretenberg/vm2/generated/full_row.hpp"
#include "barretenberg/vm2/generated/relations/range_check.hpp"

using namespace benchmark;
using namespace bb::avm2;

namespace {

AvmFullRow<FF> get_random_row()
{
AvmFullRow<FF> row;
for (size_t i = 0; i < NUM_COLUMNS_WITH_SHIFTS; i++) {
row.get_column(static_cast<ColumnAndShifts>(i)) = FF::random_element();
}
return row;
}

bb::RelationParameters<FF> get_params()
{
return {
.eta = 0,
.beta = FF::random_element(),
.gamma = FF::random_element(),
.public_input_delta = 0,
.lookup_grand_product_delta = 0,
.beta_sqr = 0,
.beta_cube = 0,
.eccvm_set_permutation_delta = 0,
};
}

template <typename Relation> void BM_accumulate_random(State& state)
{
auto row = get_random_row();
auto params = get_params();
FF scaling_factor = 1;

typename Relation::SumcheckArrayOfValuesOverSubrelations result{};

for (auto _ : state) {
Relation::accumulate(result, row, params, scaling_factor);
}
}

} // namespace

int main(int argc, char** argv)
{
bb::constexpr_for<0, std::tuple_size_v<typename AvmFlavor::MainRelations>, 1>([&]<size_t i>() {
using Relation = std::tuple_element_t<i, typename AvmFlavor::MainRelations>;
BENCHMARK(BM_accumulate_random<Relation>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fcarreiro I guess that get_random_row() and get_params() are accounted for in the timing measurement. Is this negligible? Otherwise, can we remove them from the measurement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I understood from the docs is that only things inside the for loop are accounted for :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Cool.

->Name(std::string(Relation::NAME) + "_acc_random")
->Unit(kMicrosecond);
});

::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
}
18 changes: 18 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <vector>

#include "barretenberg/common/constexpr_utils.hpp"
#include "barretenberg/common/std_array.hpp"
#include "barretenberg/common/thread.hpp"
#include "barretenberg/numeric/bitop/get_msb.hpp"
Expand Down Expand Up @@ -123,6 +124,22 @@ void print_trace_stats(const TraceContainer& trace)
info("Sum of all column rows: ", total_rows, " (~2^", numeric::get_msb(numeric::round_up_power_2(total_rows)), ")");
}

// Check that inverses have been set, if assertions are enabled.
// WARNING: This will not warn you if the interaction is not exercised.
void check_interactions([[maybe_unused]] const TraceContainer& trace)
{
#ifndef NDEBUG
bb::constexpr_for<0, std::tuple_size_v<typename AvmFlavor::LookupRelations>, 1>([&]<size_t i>() {
using Settings = typename std::tuple_element_t<i, typename AvmFlavor::LookupRelations>::Settings;
if (trace.get_column_rows(Settings::SRC_SELECTOR) != 0 && trace.get_column_rows(Settings::INVERSES) == 0) {
std::cerr << "Inverses not set for " << Settings::NAME << ". Did you forget to run a lookup builder?"
<< std::endl;
std::abort();
}
});
#endif
}

} // namespace

TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events)
Expand Down Expand Up @@ -210,6 +227,7 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events)
parallel_for(jobs_interactions.size(), [&](size_t i) { jobs_interactions[i]->process(trace); }));
}

check_interactions(trace);
print_trace_stats(trace);
return trace;
}
Expand Down