-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(avm): basic stat collection (#7283)
Colelcts and prints stats for `avm_prove` when BB is compiled with in `RelWithAssert` mode or `AVM_TRACK_STATS` is defined. Has no impact otherwise. ``` ------- STATS ------- compute_logderivative_inverse/incl_main_tag_err_ms: 0 compute_logderivative_inverse/incl_mem_tag_err_ms: 0 compute_logderivative_inverse/kernel_output_lookup_ms: 0 compute_logderivative_inverse/lookup_byte_lengths_ms: 0 compute_logderivative_inverse/lookup_byte_operations_ms: 0 compute_logderivative_inverse/lookup_div_u16_0_ms: 0 compute_logderivative_inverse/lookup_div_u16_1_ms: 0 compute_logderivative_inverse/lookup_div_u16_2_ms: 0 compute_logderivative_inverse/lookup_div_u16_3_ms: 0 compute_logderivative_inverse/lookup_div_u16_4_ms: 0 compute_logderivative_inverse/lookup_div_u16_5_ms: 0 compute_logderivative_inverse/lookup_div_u16_6_ms: 0 compute_logderivative_inverse/lookup_div_u16_7_ms: 0 compute_logderivative_inverse/lookup_into_kernel_ms: 0 compute_logderivative_inverse/lookup_mem_rng_chk_hi_ms: 0 compute_logderivative_inverse/lookup_mem_rng_chk_lo_ms: 0 compute_logderivative_inverse/lookup_mem_rng_chk_mid_ms: 0 compute_logderivative_inverse/lookup_opcode_gas_ms: 0 compute_logderivative_inverse/lookup_pow_2_0_ms: 0 compute_logderivative_inverse/lookup_pow_2_1_ms: 0 compute_logderivative_inverse/lookup_u16_0_ms: 0 compute_logderivative_inverse/lookup_u16_10_ms: 0 compute_logderivative_inverse/lookup_u16_11_ms: 0 compute_logderivative_inverse/lookup_u16_12_ms: 0 compute_logderivative_inverse/lookup_u16_13_ms: 0 compute_logderivative_inverse/lookup_u16_14_ms: 0 compute_logderivative_inverse/lookup_u16_1_ms: 0 compute_logderivative_inverse/lookup_u16_2_ms: 0 compute_logderivative_inverse/lookup_u16_3_ms: 0 compute_logderivative_inverse/lookup_u16_4_ms: 0 compute_logderivative_inverse/lookup_u16_5_ms: 0 compute_logderivative_inverse/lookup_u16_6_ms: 0 compute_logderivative_inverse/lookup_u16_7_ms: 0 compute_logderivative_inverse/lookup_u16_8_ms: 0 compute_logderivative_inverse/lookup_u16_9_ms: 0 compute_logderivative_inverse/lookup_u8_0_ms: 0 compute_logderivative_inverse/lookup_u8_1_ms: 0 compute_logderivative_inverse/perm_main_alu_ms: 1 compute_logderivative_inverse/perm_main_bin_ms: 0 compute_logderivative_inverse/perm_main_conv_ms: 0 compute_logderivative_inverse/perm_main_mem_a_ms: 0 compute_logderivative_inverse/perm_main_mem_b_ms: 0 compute_logderivative_inverse/perm_main_mem_c_ms: 0 compute_logderivative_inverse/perm_main_mem_d_ms: 0 compute_logderivative_inverse/perm_main_mem_ind_addr_a_ms: 0 compute_logderivative_inverse/perm_main_mem_ind_addr_b_ms: 0 compute_logderivative_inverse/perm_main_mem_ind_addr_c_ms: 0 compute_logderivative_inverse/perm_main_mem_ind_addr_d_ms: 0 compute_logderivative_inverse/perm_main_pedersen_ms: 0 compute_logderivative_inverse/perm_main_pos2_perm_ms: 0 compute_logderivative_inverse/range_check_da_gas_hi_ms: 0 compute_logderivative_inverse/range_check_da_gas_lo_ms: 0 compute_logderivative_inverse/range_check_l2_gas_hi_ms: 0 compute_logderivative_inverse/range_check_l2_gas_lo_ms: 0 proving/log_derivative_inverse_round_ms: 82 proving/pcs_rounds_ms: 158 proving/relation_check_rounds_ms: 66 proving/wire_commitments_round_ms: 193 ```
- Loading branch information
Showing
8 changed files
with
284 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "barretenberg/vm/avm_trace/stats.hpp" | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace bb::avm_trace { | ||
|
||
Stats& Stats::get() | ||
{ | ||
static Stats stats; | ||
return stats; | ||
} | ||
|
||
void Stats::reset() | ||
{ | ||
stats.clear(); | ||
} | ||
|
||
void Stats::increment(const std::string& key, uint64_t value) | ||
{ | ||
stats[key] += value; | ||
} | ||
|
||
void Stats::time(const std::string& key, std::function<void()> f) | ||
{ | ||
auto start = std::chrono::system_clock::now(); | ||
f(); | ||
auto elapsed = std::chrono::system_clock::now() - start; | ||
increment(key, static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count())); | ||
} | ||
|
||
std::string Stats::to_string() const | ||
{ | ||
std::vector<std::string> result; | ||
result.reserve(stats.size()); | ||
for (const auto& [key, value] : stats) { | ||
result.push_back(key + ": " + std::to_string(value)); | ||
} | ||
std::sort(result.begin(), result.end()); | ||
std::string joined; | ||
for (auto& s : result) { | ||
joined += std::move(s) + "\n"; | ||
} | ||
return joined; | ||
} | ||
|
||
std::string Stats::aggregate_to_string(const std::string& key_prefix) const | ||
{ | ||
uint64_t result = 0; | ||
for (const auto& [key, value] : stats) { | ||
if (key.starts_with(key_prefix)) { | ||
result += value; | ||
} | ||
} | ||
return key_prefix + ": " + std::to_string(result); | ||
} | ||
|
||
} // namespace bb::avm_trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
#include <string> | ||
#include <unordered_map> | ||
|
||
// To enable stats tracking, compile in RelWithAssert mode. | ||
// cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert | ||
#ifndef NDEBUG | ||
#define AVM_TRACK_STATS | ||
#endif | ||
|
||
#ifdef AVM_TRACK_STATS | ||
#define AVM_TRACK_TIME(key, body) ::bb::avm_trace::Stats::get().time(key, [&]() { body; }); | ||
#else | ||
#define AVM_TRACK_TIME(key, body) body | ||
#endif | ||
|
||
namespace bb::avm_trace { | ||
|
||
class Stats { | ||
public: | ||
static Stats& get(); | ||
void reset(); | ||
void increment(const std::string& key, uint64_t value); | ||
void time(const std::string& key, std::function<void()> f); | ||
std::string to_string() const; | ||
std::string aggregate_to_string(const std::string& key_prefix) const; | ||
|
||
private: | ||
Stats() = default; | ||
|
||
std::unordered_map<std::string, uint64_t> stats; | ||
}; | ||
|
||
} // namespace bb::avm_trace |
271 changes: 163 additions & 108 deletions
271
barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters