-
Notifications
You must be signed in to change notification settings - Fork 268
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
Changes from 43 commits
ff435f3
b184022
9942d6e
aa6db5c
1362cb4
da06f55
125d47c
e906410
f01b646
e1e949b
9f5b8bb
b045e61
3cb43fb
c689569
f95c018
313c491
f22f7ef
fe91327
8277038
d7e7530
7e75ce6
111a037
f1b5578
3770913
1080eb6
f8a6c00
56d36e7
3c8d5d4
746a58b
b4c30ea
a472716
e770973
1773af7
648c014
765b074
7c193e6
0b03bca
4162a8c
006da13
7d44083
3a190d8
de71b76
33d65cb
8254e6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
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) | ||
{ | ||
|
@@ -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>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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