Skip to content

Commit

Permalink
refactor(avm): remove some codegen bloat (#11418)
Browse files Browse the repository at this point in the history
TL;DR: Removes bloat, old and new witgen are still proving. Please review without nitpicking I recommend just merging if CI passes.

More detail:
* Removes explicit column names, they now get generated via the macro.
* Remove as_vector, replaced uses with get_column (and commented out some other uses).

I also added, in vm2, nice per-namespace stats:

```
Column sizes per namespace:
  precomputed: 2097152 (~2^21)
  execution: 6 (~2^3)
  alu: 1 (~2^0)
  lookup: 196608 (~2^18)
  perm: 6 (~2^3)
```

It autoupdates without us having to add columns manually.
  • Loading branch information
fcarreiro authored and Maddiaa0 committed Jan 22, 2025
1 parent 131e2a3 commit 79769c9
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 1,743 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// AUTOGENERATED FILE
#include "circuit_builder.hpp"
#include "columns.hpp"

#include <mutex>
#include <set>
Expand Down Expand Up @@ -27,7 +28,7 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
// We create a mapping between the polynomial index and the corresponding column index when row
// is expressed as a vector, i.e., column of the trace matrix.
std::unordered_map<std::string, size_t> names_to_col_idx;
const auto names = Row::names();
const auto names = COLUMN_NAMES;
for (size_t i = 0; i < names.size(); i++) {
names_to_col_idx[names[i]] = i;
}
Expand Down Expand Up @@ -63,9 +64,9 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co
// Non-parallel version takes 0.5 second for a trace size of 200k rows.
// A parallel version might be considered in the future.
for (size_t i = 0; i < num_rows; i++) {
const auto row = rows[i].as_vector();
const auto& row = rows[i];
for (size_t col = 0; col < Row::SIZE; col++) {
if (!row[col].is_zero()) {
if (!row.get_column(static_cast<ColumnAndShifts>(col)).is_zero()) {
col_nonzero_size[col] = i + 1;
}
}
Expand Down
10 changes: 10 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/columns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <array>
#include <optional>

#include "barretenberg/common/std_string.hpp"

namespace bb::avm {

// The entities that will be used in the flavor.
Expand Down Expand Up @@ -33,4 +35,12 @@ constexpr auto TO_BE_SHIFTED_COLUMNS_ARRAY = []() { return std::array{ AVM_TO_BE
constexpr auto SHIFTED_COLUMNS_ARRAY = []() { return std::array{ AVM_SHIFTED_COLUMNS }; }();
static_assert(TO_BE_SHIFTED_COLUMNS_ARRAY.size() == SHIFTED_COLUMNS_ARRAY.size());

// Two layers are needed to properly expand the macro. Don't ask why.
#define VARARGS_TO_STRING(...) #__VA_ARGS__
#define UNPACK_TO_STRING(...) VARARGS_TO_STRING(__VA_ARGS__)
inline const std::vector<std::string>& COLUMN_NAMES = []() {
static auto vec = detail::split_and_trim(UNPACK_TO_STRING(AVM_ALL_ENTITIES), ',');
return vec;
}();

} // namespace bb::avm
Loading

0 comments on commit 79769c9

Please sign in to comment.