Skip to content

Commit

Permalink
feat: reduce max memory in translator by freeing accumulator and eccvm (
Browse files Browse the repository at this point in the history
#8253)

We free the accumulator as soon as the decider_prover is done, the
eccvm_builder as soon as the eccvm_prover is constructed, the
translator_builder as soon as the translator_prover is constructed, and
the eccvm_prover, as soon as we pass all the necessary information to
the translator_builder. The peak memory drops by 18MB, but what's
significant is that the translator is no longer the bottleneck of the
benchmark, mostly due to freeing the accumulator.

The peak memory during the eccvm/translator drops from 666MiB to 328MiB,
a drop of 338MiB, which is approximately the size of one instance and
the commitment key, which is as expected.
Before:
<img width="1180" alt="Screenshot 2024-09-20 at 1 55 13 PM"
src="https://github.com/user-attachments/assets/469fe1e0-01ac-4e4e-a794-0266d15b4a5f">

After:
<img width="1193" alt="Screenshot 2024-09-19 at 6 28 39 PM"
src="https://github.com/user-attachments/assets/2f5c8873-5aa4-4631-a6f1-9a01aeef633c">
  • Loading branch information
lucasxia01 authored Sep 20, 2024
1 parent 020d4fd commit 7247ddb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
1 change: 1 addition & 0 deletions barretenberg/cpp/scripts/benchmark_tracy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ssh $BOX "
./tracy-capture -a 127.0.0.1 -f -o trace-$BENCHMARK & ;
sleep 0.1 ;
cd ~/aztec-packages/barretenberg/cpp/build-$PRESET ;
ninja $BENCHMARK ;
$COMMAND ;
" &
wait # TODO(AD) hack - not sure why needed
Expand Down
5 changes: 4 additions & 1 deletion barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ ClientIVC::Proof ClientIVC::prove()
ASSERT(merge_verification_queue.size() == 1); // ensure only a single merge proof remains in the queue
FoldProof& fold_proof = verification_queue[0].proof;
MergeProof& merge_proof = merge_verification_queue[0];
return { fold_proof, decider_prove(), goblin.prove(merge_proof) };
HonkProof decider_proof = decider_prove();
// Free the accumulator to save memory
fold_output.accumulator = nullptr;
return { fold_proof, std::move(decider_proof), goblin.prove(merge_proof) };
};

bool ClientIVC::verify(const Proof& proof,
Expand Down
47 changes: 34 additions & 13 deletions barretenberg/cpp/src/barretenberg/goblin/goblin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ class GoblinProver {
// on the first call to accumulate there is no merge proof to verify
bool merge_proof_exists{ false };

std::shared_ptr<ECCVMProvingKey> get_eccvm_proving_key() const { return eccvm_prover->key; }
std::shared_ptr<ECCVMProvingKey> get_eccvm_proving_key() const { return eccvm_key; }
std::shared_ptr<TranslatorProvingKey> get_translator_proving_key() const { return translator_prover->key; }

private:
// TODO(https://github.com/AztecProtocol/barretenberg/issues/798) unique_ptr use is a hack
std::unique_ptr<ECCVMBuilder> eccvm_builder;
std::unique_ptr<TranslatorBuilder> translator_builder;
std::unique_ptr<TranslatorProver> translator_prover;
std::unique_ptr<ECCVMProver> eccvm_prover;
std::shared_ptr<ECCVMProvingKey> eccvm_key;

GoblinAccumulationOutput accumulator; // Used only for ACIR methods for now

Expand Down Expand Up @@ -171,23 +170,45 @@ class GoblinProver {
*/
void prove_eccvm()
{
eccvm_builder = std::make_unique<ECCVMBuilder>(op_queue);
eccvm_prover = std::make_unique<ECCVMProver>(*eccvm_builder);
goblin_proof.eccvm_proof = eccvm_prover->construct_proof();
goblin_proof.translation_evaluations = eccvm_prover->translation_evaluations;
};
{
ZoneScopedN("Create ECCVMBuilder and ECCVMProver");
auto eccvm_builder = std::make_unique<ECCVMBuilder>(op_queue);
eccvm_prover = std::make_unique<ECCVMProver>(*eccvm_builder);
}
{
ZoneScopedN("Construct ECCVM Proof");
goblin_proof.eccvm_proof = eccvm_prover->construct_proof();
}

{
ZoneScopedN("Assign Translation Evaluations");
goblin_proof.translation_evaluations = eccvm_prover->translation_evaluations;
}
}

/**
* @brief Construct a translator proof
*
*/
void prove_translator()
{
translator_builder = std::make_unique<TranslatorBuilder>(
eccvm_prover->translation_batching_challenge_v, eccvm_prover->evaluation_challenge_x, op_queue);
translator_prover = std::make_unique<TranslatorProver>(*translator_builder, eccvm_prover->transcript);
goblin_proof.translator_proof = translator_prover->construct_proof();
};
fq translation_batching_challenge_v = eccvm_prover->translation_batching_challenge_v;
fq evaluation_challenge_x = eccvm_prover->evaluation_challenge_x;
std::shared_ptr<Transcript> transcript = eccvm_prover->transcript;
eccvm_key = eccvm_prover->key;
eccvm_prover = nullptr;
{
ZoneScopedN("Create TranslatorBuilder and TranslatorProver");
auto translator_builder =
std::make_unique<TranslatorBuilder>(translation_batching_challenge_v, evaluation_challenge_x, op_queue);
translator_prover = std::make_unique<TranslatorProver>(*translator_builder, transcript);
}

{
ZoneScopedN("Construct Translator Proof");
goblin_proof.translator_proof = translator_prover->construct_proof();
}
}

/**
* @brief Constuct a full Goblin proof (ECCVM, Translator, merge)
Expand Down

0 comments on commit 7247ddb

Please sign in to comment.