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

chore: optimise polynomial initialisation #10073

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 13 additions & 1 deletion barretenberg/cpp/src/barretenberg/polynomials/polynomial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,19 @@ void Polynomial<Fr>::allocate_backing_memory(size_t size, size_t virtual_size, s
*/
template <typename Fr> Polynomial<Fr>::Polynomial(size_t size, size_t virtual_size, size_t start_index)
{
PROFILE_THIS_NAME("polynomial allocation with zeroing");

allocate_backing_memory(size, virtual_size, start_index);
memset(static_cast<void*>(coefficients_.backing_memory_.get()), 0, sizeof(Fr) * size);
size_t num_threads = calculate_num_threads(size);
size_t range_per_thread = size / num_threads;
size_t leftovers = size - (range_per_thread * num_threads);
parallel_for(num_threads, [&](size_t j) {
size_t offset = j * range_per_thread;
size_t range = (j == num_threads - 1) ? range_per_thread + leftovers : range_per_thread;
ASSERT(offset < size);
ASSERT((offset + range) <= size);
memset(static_cast<void*>(coefficients_.backing_memory_.get() + offset), 0, sizeof(Fr) * range);
});
}

/**
Expand All @@ -76,6 +87,7 @@ template <typename Fr> Polynomial<Fr>::Polynomial(size_t size, size_t virtual_si
template <typename Fr>
Polynomial<Fr>::Polynomial(size_t size, size_t virtual_size, size_t start_index, [[maybe_unused]] DontZeroMemory flag)
{
PROFILE_THIS_NAME("polynomial allocation without zeroing");
allocate_backing_memory(size, virtual_size, start_index);
}

Expand Down
4 changes: 1 addition & 3 deletions barretenberg/cpp/src/barretenberg/polynomials/polynomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ template <typename Fr> class Polynomial {
// Intended just for plonk, where size == virtual_size always
Polynomial(size_t size)
: Polynomial(size, size)
{
PROFILE_THIS();
}
{}
// Constructor that does not initialize values, use with caution to save time.
Polynomial(size_t size, size_t virtual_size, size_t start_index, DontZeroMemory flag);
Polynomial(size_t size, size_t virtual_size, DontZeroMemory flag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ template <IsUltraFlavor Flavor> class DeciderProvingKey_ {
}
{

PROFILE_THIS_NAME("constructing proving key");
PROFILE_THIS_NAME("allocating proving key");

proving_key = ProvingKey(dyadic_circuit_size, circuit.public_inputs.size(), commitment_key);
// If not using structured trace OR if using structured trace but overflow has occurred (overflow block in
Expand Down Expand Up @@ -188,27 +188,27 @@ template <IsUltraFlavor Flavor> class DeciderProvingKey_ {
// Allocate the table polynomials
if constexpr (IsUltraFlavor<Flavor>) {
for (auto& poly : proving_key.polynomials.get_tables()) {
poly = typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset);
poly = Polynomial(max_tables_size, dyadic_circuit_size, table_offset);
}
}
}
{
PROFILE_THIS_NAME("allocating sigmas and ids");

for (auto& sigma : proving_key.polynomials.get_sigmas()) {
sigma = typename Flavor::Polynomial(proving_key.circuit_size);
sigma = Polynomial(proving_key.circuit_size);
}
for (auto& id : proving_key.polynomials.get_ids()) {
id = typename Flavor::Polynomial(proving_key.circuit_size);
id = Polynomial(proving_key.circuit_size);
}
}
{
ZoneScopedN("allocating lookup read counts and tags");
// Allocate the read counts and tags polynomials
proving_key.polynomials.lookup_read_counts =
typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset);
Polynomial(max_tables_size, dyadic_circuit_size, table_offset);
proving_key.polynomials.lookup_read_tags =
typename Flavor::Polynomial(max_tables_size, dyadic_circuit_size, table_offset);
Polynomial(max_tables_size, dyadic_circuit_size, table_offset);
}
{
ZoneScopedN("allocating lookup and databus inverses");
Expand Down
Loading