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: Mega memory benchmarks #9858

Merged
merged 24 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ add_subdirectory(append_only_tree_bench)
add_subdirectory(ultra_bench)
add_subdirectory(stdlib_hash)
add_subdirectory(circuit_construction_bench)
add_subdirectory(mega_memory_bench)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
barretenberg_module(
mega_memory_bench
ultra_honk
stdlib_primitives
)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ template <typename FF_> class MegaArith {
T lookup;
T overflow; // block gates of arbitrary type that overflow their designated block

std::vector<std::string_view> get_labels() const
{
return { "ecc_op", "pub_inputs", "busread",
"arithmetic", "delta_range", "elliptic",
"aux", "poseidon2_external", "poseidon2_internal",
"lookup" };
}

auto get()
{
return RefArray{ ecc_op,
Expand All @@ -52,6 +60,7 @@ template <typename FF_> class MegaArith {
lookup,
overflow };
}

auto get() const
{
return RefArray{ ecc_op,
Expand Down Expand Up @@ -297,7 +306,11 @@ template <typename FF_> class MegaArith {
{
info("Gate blocks summary: (actual gates / fixed capacity)");
info("goblin ecc op :\t", this->ecc_op.size(), "/", this->ecc_op.get_fixed_size());
info("pub inputs :\t", this->pub_inputs.size(), "/", this->pub_inputs.get_fixed_size());
info("pub inputs :\t",
this->pub_inputs.size(),
"/",
this->pub_inputs.get_fixed_size(),
" (populated in decider pk constructor)");
info("busread :\t", this->busread.size(), "/", this->busread.get_fixed_size());
info("arithmetic :\t", this->arithmetic.size(), "/", this->arithmetic.get_fixed_size());
info("delta range :\t", this->delta_range.size(), "/", this->delta_range.get_fixed_size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,44 @@ template <typename FF> class MegaCircuitBuilder_ : public UltraCircuitBuilder_<M
const BusVector& get_calldata() const { return databus[static_cast<size_t>(BusId::CALLDATA)]; }
const BusVector& get_secondary_calldata() const { return databus[static_cast<size_t>(BusId::SECONDARY_CALLDATA)]; }
const BusVector& get_return_data() const { return databus[static_cast<size_t>(BusId::RETURNDATA)]; }
uint64_t estimate_memory() const
{
vinfo("++Estimating builder memory++");
uint64_t result{ 0 };

// gates:
for (auto [block, label] : zip_view(this->blocks.get(), this->blocks.get_labels())) {
uint64_t size{ 0 };
for (const auto& wire : block.wires) {
size += wire.capacity() * sizeof(uint32_t);
}
for (const auto& selector : block.selectors) {
size += selector.capacity() * sizeof(FF);
}
vinfo(label, " size ", size >> 10, " KiB");
result += size;
}

// variables
size_t to_add{ this->variables.capacity() * sizeof(FF) };
result += to_add;
vinfo("variables: ", to_add);

// public inputs
to_add = this->public_inputs.capacity() * sizeof(uint32_t);
result += to_add;
vinfo("public inputs: ", to_add);

// other variable indices
to_add = this->next_var_index.capacity() * sizeof(uint32_t);
to_add += this->prev_var_index.capacity() * sizeof(uint32_t);
to_add += this->real_variable_index.capacity() * sizeof(uint32_t);
to_add += this->real_variable_tags.capacity() * sizeof(uint32_t);
result += to_add;
vinfo("variable indices: ", to_add);

return result;
}
};
using MegaCircuitBuilder = MegaCircuitBuilder_<bb::fr>;
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,24 @@ class MegaFlavor {
// Compute permutation and lookup grand product polynomials
compute_grand_products<MegaFlavor>(this->polynomials, relation_parameters);
}

uint64_t estimate_memory()
{
vinfo("++Estimating proving key memory++");
for (auto [polynomial, label] : zip_view(polynomials.get_all(), polynomials.get_labels())) {
uint64_t size = polynomial.size();
vinfo(label, " num: ", size, " size: ", (size * sizeof(FF)) >> 10, " KiB");
Copy link
Contributor

Choose a reason for hiding this comment

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

I know you're not counting shifts in the total memory but I was a bit mislead by this print at first because it makes it look like shifts are utilizing their own mem

}

uint64_t result(0);
for (auto& polynomial : polynomials.get_unshifted()) {
result += polynomial.size() * sizeof(FF);
}

result += public_inputs.capacity() * sizeof(FF);

return result;
}
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ enum MultiTableId {
BLAKE_XOR_ROTATE_16,
BLAKE_XOR_ROTATE_8,
BLAKE_XOR_ROTATE_7,
PEDERSEN_IV,
HONK_DUMMY_MULTI,
KECCAK_THETA_OUTPUT,
KECCAK_CHI_OUTPUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ template <IsHonkFlavor Flavor> class DeciderProvingKey_ {
using Polynomial = typename Flavor::Polynomial;
using RelationSeparator = typename Flavor::RelationSeparator;

using Trace = ExecutionTrace_<Flavor>;

// Flag indicating whether the polynomials will be constructed with fixed block sizes for each gate type
bool is_structured;

public:
using Trace = ExecutionTrace_<Flavor>;

ProvingKey proving_key;

bool is_accumulator = false;
Expand Down