Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use structured polys to reduce prover memory #8587

Merged
merged 44 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ff435f3
changed the location of the allocation of the polynomials to where th…
lucasxia01 Sep 17, 2024
b184022
Merge branch 'master' into lx/structurize-prover-polys
lucasxia01 Sep 17, 2024
9942d6e
fix build
lucasxia01 Sep 17, 2024
aa6db5c
set to_be_shifted polys to start_idx=1 and some poly initializations …
lucasxia01 Sep 17, 2024
1362cb4
undo unnecessary shiftable call... which somehow fixes everything
lucasxia01 Sep 17, 2024
da06f55
fix a couple stray tests
lucasxia01 Sep 17, 2024
125d47c
Merge branch 'master' into lx/structurize-prover-polys
lucasxia01 Sep 17, 2024
e906410
structurized lagrange polys and selectors
lucasxia01 Sep 17, 2024
f01b646
add expand class that allows for the unstructured
lucasxia01 Sep 18, 2024
e1e949b
fix tests and allow for polynomials over different active ranges to a…
lucasxia01 Sep 18, 2024
9f5b8bb
fix mega test
lucasxia01 Sep 18, 2024
b045e61
adjust memory for ecc_op wires and selector
lucasxia01 Sep 18, 2024
3cb43fb
fix floating point issue with main.ts
lucasxia01 Sep 18, 2024
c689569
fix commit_sparse to handle non-power-of-two sizes and add new tests
lucasxia01 Sep 18, 2024
f95c018
reduce databus poly memory
lucasxia01 Sep 18, 2024
313c491
updated 4 table and 2 read_count polys
lucasxia01 Sep 18, 2024
f22f7ef
fix noir-packages-test
lucasxia01 Sep 18, 2024
fe91327
Merge remote-tracking branch 'origin/master' into lx/structurize-prov…
lucasxia01 Sep 19, 2024
8277038
remove accidental extra copy
lucasxia01 Sep 19, 2024
d7e7530
made inverse polys structured
lucasxia01 Sep 19, 2024
7e75ce6
Delete barretenberg/acir_tests/crs/grumpkin_size
lucasxia01 Sep 19, 2024
111a037
add issue for databus_id
lucasxia01 Sep 19, 2024
f1b5578
try using commit instead of commit_sparse for ecc_op and databus and …
lucasxia01 Sep 19, 2024
3770913
undo change with databus inverses
lucasxia01 Sep 19, 2024
1080eb6
small cleanup
lucasxia01 Sep 19, 2024
f8a6c00
new tests and cleanup
lucasxia01 Sep 19, 2024
56d36e7
more consts
lucasxia01 Sep 19, 2024
3c8d5d4
cleanup + adding trace_offset to blocks so things are cleaner
lucasxia01 Sep 20, 2024
746a58b
Merge branch 'master' into lx/structurize-prover-polys
lucasxia01 Sep 20, 2024
b4c30ea
Merge branch 'master' into lx/structurize-prover-polys
lucasxia01 Sep 21, 2024
a472716
fix analyze client ivc bench script
lucasxia01 Sep 21, 2024
e770973
tracy debugging
lucasxia01 Sep 23, 2024
1773af7
Merge remote-tracking branch 'origin/master' into lx/structurize-prov…
lucasxia01 Sep 24, 2024
648c014
update Crs size
lucasxia01 Sep 24, 2024
765b074
fix formatting
lucasxia01 Sep 24, 2024
7c193e6
make gate selectors and ecc_op_wires based on the fixed_size rather t…
lucasxia01 Sep 24, 2024
0b03bca
big refactor to allocate all polys in one place and also base sizes o…
lucasxia01 Sep 26, 2024
4162a8c
revert full()
lucasxia01 Sep 26, 2024
006da13
fix tests and small changes
lucasxia01 Sep 26, 2024
7d44083
revert poly tests and disable Expand test
lucasxia01 Sep 26, 2024
3a190d8
poly test fix
lucasxia01 Sep 26, 2024
de71b76
put public inputs stuff back for plonk
lucasxia01 Sep 26, 2024
33d65cb
Merge branch 'master' into lx/structurize-prover-polys
lucasxia01 Sep 26, 2024
8254e6a
clean up for merge
lucasxia01 Sep 26, 2024
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
Empty file modified barretenberg/cpp/scripts/analyze_client_ivc_bench.py
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions barretenberg/cpp/src/barretenberg/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ static constexpr uint32_t CONST_PROOF_SIZE_LOG_N = 28;
// to ensure a constant PG proof size and a PG recursive verifier circuit that is independent of the size of the
// circuits being folded.
static constexpr uint32_t CONST_PG_LOG_N = 20;

static constexpr uint32_t MAX_LOOKUP_TABLES_SIZE = 70000;

static constexpr uint32_t MAX_DATABUS_SIZE = 10;
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
#include "barretenberg/stdlib_circuit_builders/ultra_keccak_flavor.hpp"
namespace bb {

template <class Flavor> void ExecutionTrace_<Flavor>::populate_public_inputs_block(Builder& builder)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this function to public

{
ZoneScopedN("populate_public_inputs_block");
// Update the public inputs block
for (const auto& idx : builder.public_inputs) {
for (size_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) {
if (wire_idx < 2) { // first two wires get a copy of the public inputs
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(idx);
} else { // the remaining wires get zeros
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(builder.zero_idx);
}
}
for (auto& selector : builder.blocks.pub_inputs.selectors) {
selector.emplace_back(0);
}
}
}

template <class Flavor>
void ExecutionTrace_<Flavor>::populate(Builder& builder, typename Flavor::ProvingKey& proving_key, bool is_structured)
{
Expand Down Expand Up @@ -56,10 +74,13 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t
Builder& builder, typename Flavor::ProvingKey& proving_key, bool is_structured)
{
ZoneScopedN("construct_trace_data");
TraceData trace_data{ builder, proving_key };

// Complete the public inputs execution trace block from builder.public_inputs
populate_public_inputs_block(builder);
if constexpr (IsPlonkFlavor<Flavor>) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

only for plonk since for honk, we do in DeciderProvingKey(). We want to do it there for Honk because we want the trace to be completed before computing offsets.

// Complete the public inputs execution trace block from builder.public_inputs
populate_public_inputs_block(builder);
}

TraceData trace_data{ builder, proving_key };

uint32_t offset = Flavor::has_zero_row ? 1 : 0; // Offset at which to place each block in the trace polynomials
// For each block in the trace, populate wire polys, copy cycles and selector polys
Expand Down Expand Up @@ -87,8 +108,7 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t
// Insert the selector values for this block into the selector polynomials at the correct offset
// TODO(https://github.com/AztecProtocol/barretenberg/issues/398): implicit arithmetization/flavor consistency
for (size_t selector_idx = 0; selector_idx < NUM_SELECTORS; selector_idx++) {
auto selector_poly = trace_data.selectors[selector_idx];
auto selector = block.selectors[selector_idx];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this was causing a lot of copying to be done

auto& selector = block.selectors[selector_idx];
for (size_t row_idx = 0; row_idx < block_size; ++row_idx) {
size_t trace_row_idx = row_idx + offset;
trace_data.selectors[selector_idx].set_if_valid_index(trace_row_idx, selector[row_idx]);
Expand All @@ -111,35 +131,19 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t
return trace_data;
}

template <class Flavor> void ExecutionTrace_<Flavor>::populate_public_inputs_block(Builder& builder)
{
ZoneScopedN("populate_public_inputs_block");
// Update the public inputs block
for (auto& idx : builder.public_inputs) {
for (size_t wire_idx = 0; wire_idx < NUM_WIRES; ++wire_idx) {
if (wire_idx < 2) { // first two wires get a copy of the public inputs
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(idx);
} else { // the remaining wires get zeros
builder.blocks.pub_inputs.wires[wire_idx].emplace_back(builder.zero_idx);
}
}
for (auto& selector : builder.blocks.pub_inputs.selectors) {
selector.emplace_back(0);
}
}
}

template <class Flavor>
void ExecutionTrace_<Flavor>::add_ecc_op_wires_to_proving_key(Builder& builder,
typename Flavor::ProvingKey& proving_key)
requires IsGoblinFlavor<Flavor>
{
// Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates
auto& ecc_op_selector = proving_key.polynomials.lagrange_ecc_op;
const size_t op_wire_offset = Flavor::has_zero_row ? 1 : 0;

// Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates
const size_t num_ecc_ops = builder.blocks.ecc_op.size();
for (auto [ecc_op_wire, wire] :
zip_view(proving_key.polynomials.get_ecc_op_wires(), proving_key.polynomials.get_wires())) {
for (size_t i = 0; i < builder.blocks.ecc_op.size(); ++i) {
for (size_t i = 0; i < num_ecc_ops; ++i) {
size_t idx = i + op_wire_offset;
ecc_op_wire.at(idx) = wire[idx];
ecc_op_selector.at(idx) = 1; // construct selector as the indicator on the ecc op block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ template <class Flavor> class ExecutionTrace_ {
for (auto [selector, other_selector] : zip_view(selectors, proving_key.polynomials.get_selectors())) {
selector = other_selector.share();
}
proving_key.polynomials.set_shifted(); // Ensure shifted wires are set correctly
lucasxia01 marked this conversation as resolved.
Show resolved Hide resolved
} else {
// Initialize and share the wire and selector polynomials
for (size_t idx = 0; idx < NUM_WIRES; ++idx) {
Expand Down Expand Up @@ -74,6 +73,14 @@ template <class Flavor> class ExecutionTrace_ {
*/
static void populate(Builder& builder, ProvingKey&, bool is_structured = false);

/**
* @brief Populate the public inputs block
* @details The first two wires are a copy of the public inputs and the other wires and all selectors are zero
*
* @param circuit
*/
static void populate_public_inputs_block(Builder& builder);

private:
/**
* @brief Add the memory records indicating which rows correspond to RAM/ROM reads/writes
Expand Down Expand Up @@ -104,14 +111,6 @@ template <class Flavor> class ExecutionTrace_ {
typename Flavor::ProvingKey& proving_key,
bool is_structured = false);

/**
* @brief Populate the public inputs block
* @details The first two wires are a copy of the public inputs and the other wires and all selectors are zero
*
* @param builder
*/
static void populate_public_inputs_block(Builder& builder);

/**
* @brief Construct and add the goblin ecc op wires to the proving key
* @details The ecc op wires vanish everywhere except on the ecc op block, where they contain a copy of the ecc op
Expand Down
3 changes: 3 additions & 0 deletions barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ concept IsGoblinFlavor = IsAnyOf<T, MegaFlavor,
MegaRecursiveFlavor_<UltraCircuitBuilder>,
MegaRecursiveFlavor_<MegaCircuitBuilder>, MegaRecursiveFlavor_<CircuitSimulatorBN254>>;

template <typename T>
concept HasDataBus = IsGoblinFlavor<T>;

template <typename T>
concept IsRecursiveFlavor = IsAnyOf<T, UltraRecursiveFlavor_<UltraCircuitBuilder>,
UltraRecursiveFlavor_<MegaCircuitBuilder>,
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST(Flavor, Getters)
// set
size_t coset_idx = 0;
for (auto& id_poly : proving_key.polynomials.get_ids()) {
typename Flavor::Polynomial new_poly(proving_key.circuit_size);
id_poly = typename Flavor::Polynomial(proving_key.circuit_size);
for (size_t i = 0; i < proving_key.circuit_size; ++i) {
id_poly.at(i) = coset_idx * proving_key.circuit_size + i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ template <typename FF, size_t NUM_WIRES, size_t NUM_SELECTORS> class ExecutionTr
Selectors selectors;
bool has_ram_rom = false; // does the block contain RAM/ROM gates
bool is_pub_inputs = false; // is this the public inputs block

uint32_t fixed_size = 0; // Fixed size for use in structured trace
uint32_t trace_offset = 0; // where this block starts in the trace

bool operator==(const ExecutionTraceBlock& other) const = default;

Expand Down Expand Up @@ -104,6 +103,8 @@ template <typename FF, size_t NUM_WIRES, size_t NUM_SELECTORS> class ExecutionTr
}
}
#endif
private:
uint32_t fixed_size = 0; // Fixed size for use in structured trace
Copy link
Contributor Author

Choose a reason for hiding this comment

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

made this private to avoid accidentally getting it. Need to call get_fixed_size() instead because it's 0 in the unstructured case.

};

} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ template <typename FF_> class MegaArith {
aux, lookup, busread, poseidon2_external, poseidon2_internal };
}

auto get_gate_blocks()
{
return RefArray{ arithmetic, delta_range, elliptic, aux,
lookup, busread, poseidon2_external, poseidon2_internal };
}

bool operator==(const MegaTraceBlocks& other) const = default;
};

Expand Down Expand Up @@ -153,7 +159,11 @@ template <typename FF_> class MegaArith {

struct TraceBlocks : public MegaTraceBlocks<MegaTraceBlock> {

E2eStructuredBlockSizes fixed_block_sizes;
TraceBlocks()
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
}

// Set fixed block sizes for use in structured trace
void set_fixed_block_sizes(TraceStructure setting)
Expand All @@ -178,10 +188,13 @@ template <typename FF_> class MegaArith {
}
}

TraceBlocks()
void compute_offsets(bool is_structured)
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
for (auto& block : this->get()) {
block.trace_offset = offset;
offset += block.get_fixed_size(is_structured);
}
}

void summarize() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ template <typename FF_> class UltraArith {
aux, lookup, poseidon2_external, poseidon2_internal };
}

auto get_gate_blocks()
{
return RefArray{ arithmetic, delta_range, elliptic, aux, lookup, poseidon2_external, poseidon2_internal };
}

bool operator==(const UltraTraceBlocks& other) const = default;
};

Expand Down Expand Up @@ -90,6 +95,12 @@ template <typename FF_> class UltraArith {

struct TraceBlocks : public UltraTraceBlocks<UltraTraceBlock> {

TraceBlocks()
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
}

// Set fixed block sizes for use in structured trace
void set_fixed_block_sizes(TraceStructure setting)
{
Expand All @@ -110,10 +121,13 @@ template <typename FF_> class UltraArith {
}
}

TraceBlocks()
void compute_offsets(bool is_structured)
{
this->aux.has_ram_rom = true;
this->pub_inputs.is_pub_inputs = true;
uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
for (auto& block : this->get()) {
block.trace_offset = offset;
offset += block.get_fixed_size(is_structured);
}
}

auto get()
Expand All @@ -137,7 +151,7 @@ template <typename FF_> class UltraArith {

size_t get_total_structured_size()
{
size_t total_size = 0;
size_t total_size = 1; // start at 1 because the 0th row is unused for selectors for Honk
for (auto block : this->get()) {
total_size += block.get_fixed_size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace bb {
template <typename Flavor>
void construct_lookup_table_polynomials(const RefArray<typename Flavor::Polynomial, 4>& table_polynomials,
const typename Flavor::CircuitBuilder& circuit,
size_t dyadic_circuit_size,
size_t additional_offset = 0)
const size_t dyadic_circuit_size,
const size_t additional_offset = 0)
{
// Create lookup selector polynomials which interpolate each table column.
// Our selector polys always need to interpolate the full subgroup size, so here we offset so as to
Expand All @@ -22,8 +22,9 @@ void construct_lookup_table_polynomials(const RefArray<typename Flavor::Polynomi
// | table randomness
// ignored, as used for regular constraints and padding to the next power of 2.
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace
ASSERT(dyadic_circuit_size > circuit.get_tables_size() + additional_offset);
size_t offset = dyadic_circuit_size - circuit.get_tables_size() - additional_offset;
const size_t tables_size = circuit.get_tables_size();
ASSERT(dyadic_circuit_size > tables_size + additional_offset);
size_t offset = dyadic_circuit_size - tables_size - additional_offset;

for (const auto& table : circuit.lookup_tables) {
const fr table_index(table.table_index);
Expand All @@ -49,12 +50,12 @@ template <typename Flavor>
void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts,
typename Flavor::Polynomial& read_tags,
typename Flavor::CircuitBuilder& circuit,
size_t dyadic_circuit_size)
const size_t dyadic_circuit_size)
{
const size_t tables_size = circuit.get_tables_size();
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace
size_t offset = dyadic_circuit_size - circuit.get_tables_size();
size_t table_offset = dyadic_circuit_size - tables_size;

size_t table_offset = offset; // offset of the present table in the table polynomials
// loop over all tables used in the circuit; each table contains data about the lookups made on it
for (auto& table : circuit.lookup_tables) {
table.initialize_index_map();
Expand Down
Loading
Loading