Skip to content

Commit d154453

Browse files
authored
feat: merge-train/barretenberg (#16980)
BEGIN_COMMIT_OVERRIDE fix: bb bench bug chore: remove stdlib::address and an unused (and unsafe) pedersen method (#16974) END_COMMIT_OVERRIDE
2 parents 6ed0b44 + 540d2ba commit d154453

File tree

7 files changed

+19
-187
lines changed

7 files changed

+19
-187
lines changed

barretenberg/cpp/src/barretenberg/common/bb_bench.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ AggregateData GlobalBenchStatsContainer::aggregate() const
206206

207207
// Each count has a unique [thread, key] combo.
208208
// We therefore treat each count as a thread's contribution to that key.
209-
for (const TimeStatsEntry* entry : entries) {
209+
for (const std::shared_ptr<TimeStatsEntry>& entry : entries) {
210210
// A map from parent key => AggregateEntry
211211
auto& entry_map = result[entry->key];
212212
// combine all entries with same parent key
@@ -238,7 +238,7 @@ GlobalBenchStatsContainer::~GlobalBenchStatsContainer()
238238
}
239239
}
240240

241-
void GlobalBenchStatsContainer::add_entry(const char* key, TimeStatsEntry* entry)
241+
void GlobalBenchStatsContainer::add_entry(const char* key, const std::shared_ptr<TimeStatsEntry>& entry)
242242
{
243243
std::unique_lock<std::mutex> lock(mutex);
244244
entry->key = key;
@@ -248,7 +248,7 @@ void GlobalBenchStatsContainer::add_entry(const char* key, TimeStatsEntry* entry
248248
void GlobalBenchStatsContainer::print() const
249249
{
250250
std::cout << "GlobalBenchStatsContainer::print() START" << "\n";
251-
for (const TimeStatsEntry* entry : entries) {
251+
for (const std::shared_ptr<TimeStatsEntry>& entry : entries) {
252252
print_stats_recursive(entry->key, &entry->count, "");
253253
}
254254
std::cout << "GlobalBenchStatsContainer::print() END" << "\n";
@@ -560,7 +560,7 @@ void GlobalBenchStatsContainer::print_aggregate_counts_hierarchical(std::ostream
560560
void GlobalBenchStatsContainer::clear()
561561
{
562562
std::unique_lock<std::mutex> lock(mutex);
563-
for (TimeStatsEntry* entry : entries) {
563+
for (std::shared_ptr<TimeStatsEntry>& entry : entries) {
564564
entry->count = TimeStats();
565565
}
566566
}

barretenberg/cpp/src/barretenberg/common/bb_bench.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ostream>
99
#include <string_view>
1010
#include <tracy/Tracy.hpp>
11+
#include <unordered_map>
1112
#include <vector>
1213

1314
/**
@@ -65,19 +66,19 @@ struct AggregateEntry {
6566
// AggregateData: Result of normalizing benchmark data
6667
// entries: Key -> ParentKey -> Entry
6768
// Empty string is used as key if the entry has no parent.
68-
using AggregateData = std::map<OperationKey, std::map<OperationKey, AggregateEntry>>;
69+
using AggregateData = std::unordered_map<OperationKey, std::map<OperationKey, AggregateEntry>>;
6970

7071
// Contains all statically known op counts
7172
struct GlobalBenchStatsContainer {
7273
public:
7374
static inline thread_local TimeStatsEntry* parent = nullptr;
7475
~GlobalBenchStatsContainer();
7576
std::mutex mutex;
76-
std::vector<TimeStatsEntry*> entries;
77+
std::vector<std::shared_ptr<TimeStatsEntry>> entries;
7778
void print() const;
7879
// NOTE: Should be called when other threads aren't active
7980
void clear();
80-
void add_entry(const char* key, TimeStatsEntry* entry);
81+
void add_entry(const char* key, const std::shared_ptr<TimeStatsEntry>& entry);
8182
void print_stats_recursive(const OperationKey& key, const TimeStats* stats, const std::string& indent) const;
8283
void print_aggregate_counts(std::ostream&, size_t) const;
8384
void print_aggregate_counts_hierarchical(std::ostream&) const;
@@ -151,16 +152,17 @@ struct TimeStatsEntry {
151152
template <OperationLabel Op> struct ThreadBenchStats {
152153
public:
153154
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
154-
static inline thread_local TimeStatsEntry stats;
155+
static inline thread_local std::shared_ptr<TimeStatsEntry> stats;
155156

156157
static void init_entry(TimeStatsEntry& entry);
157158
// returns null if use_bb_bench not enabled
158-
static TimeStatsEntry* ensure_stats()
159+
static std::shared_ptr<TimeStatsEntry> ensure_stats()
159160
{
160-
if (bb::detail::use_bb_bench && BB_UNLIKELY(stats.key.empty())) {
161-
GLOBAL_BENCH_STATS.add_entry(Op.value, &stats);
161+
if (bb::detail::use_bb_bench && BB_UNLIKELY(stats == nullptr)) {
162+
stats = std::make_shared<TimeStatsEntry>();
163+
GLOBAL_BENCH_STATS.add_entry(Op.value, stats);
162164
}
163-
return bb::detail::use_bb_bench ? &stats : nullptr;
165+
return stats;
164166
}
165167
};
166168

@@ -198,7 +200,7 @@ struct BenchReporter {
198200
#define BB_BENCH_TRACY() BB_BENCH_ONLY_NAME(__func__)
199201
#define BB_BENCH_TRACY_NAME(name) BB_BENCH_ONLY_NAME(name)
200202
#define BB_BENCH_ONLY_NAME(name) \
201-
bb::detail::BenchReporter _bb_bench_reporter((bb::detail::ThreadBenchStats<name>::ensure_stats()))
203+
bb::detail::BenchReporter _bb_bench_reporter((bb::detail::ThreadBenchStats<name>::ensure_stats().get()))
202204
#define BB_BENCH_ENABLE_NESTING() \
203205
if (_bb_bench_reporter.stats) \
204206
bb::detail::GlobalBenchStatsContainer::parent = _bb_bench_reporter.stats

barretenberg/cpp/src/barretenberg/common/parallel_for_mutex_pool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ThreadPool {
2828

2929
void start_tasks(size_t num_iterations, const std::function<void(size_t)>& func)
3030
{
31-
parent = bb::detail::GlobalBenchStatsContainer::parent;
31+
parent.store(bb::detail::GlobalBenchStatsContainer::parent);
3232
{
3333
std::unique_lock<std::mutex> lock(tasks_mutex);
3434
task_ = func;
@@ -48,7 +48,7 @@ class ThreadPool {
4848
}
4949

5050
private:
51-
bb::detail::TimeStatsEntry* parent = nullptr;
51+
std::atomic<bb::detail::TimeStatsEntry*> parent = nullptr;
5252
std::vector<std::thread> workers;
5353
std::mutex tasks_mutex;
5454
std::function<void(size_t)> task_;
@@ -119,7 +119,7 @@ void ThreadPool::worker_loop(size_t /*unused*/)
119119
}
120120
// Make sure nested stats accounting works under multithreading
121121
// Note: parent is a thread-local variable.
122-
bb::detail::GlobalBenchStatsContainer::parent = parent;
122+
bb::detail::GlobalBenchStatsContainer::parent = parent.load();
123123
do_iterations();
124124
}
125125
// info("worker exit ", worker_num);

barretenberg/cpp/src/barretenberg/polynomials/gate_separator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ template <typename FF> struct GateSeparatorPolynomial {
143143
BB_PROFILE static std::vector<FF> compute_beta_products(const std::vector<FF>& betas,
144144
const size_t log_num_monomials)
145145
{
146-
146+
BB_BENCH_NAME("GateSeparatorPolynomial::compute_beta_products");
147147
size_t pow_size = 1 << log_num_monomials;
148148
std::vector<FF> beta_products(pow_size);
149149

barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,6 @@ field_t<C> pedersen_hash<C>::hash(const std::vector<field_ct>& inputs, const Gen
3333
return result.x;
3434
}
3535

36-
template <typename C>
37-
field_t<C> pedersen_hash<C>::hash_skip_field_validation(const std::vector<field_ct>& inputs,
38-
const GeneratorContext context)
39-
{
40-
using cycle_scalar = typename cycle_group::cycle_scalar;
41-
using Curve = EmbeddedCurve;
42-
43-
const auto base_points = context.generators->get(inputs.size(), context.offset, context.domain_separator);
44-
45-
std::vector<cycle_scalar> scalars;
46-
std::vector<cycle_group> points;
47-
scalars.emplace_back(cycle_scalar::create_from_bn254_scalar(field_ct(inputs.size())));
48-
points.emplace_back(crypto::pedersen_hash_base<Curve>::length_generator);
49-
for (size_t i = 0; i < inputs.size(); ++i) {
50-
// `true` param = skip primality test when performing a scalar mul
51-
scalars.emplace_back(cycle_scalar::create_from_bn254_scalar(inputs[i], true));
52-
// constructs constant cycle_group objects (non-witness)
53-
points.emplace_back(base_points[i]);
54-
}
55-
56-
auto result = cycle_group::batch_mul(points, scalars);
57-
return result.x;
58-
}
59-
6036
/**
6137
* @brief Hash a byte_array.
6238
*

barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ template <typename Builder> class pedersen_hash {
3131

3232
public:
3333
static field_ct hash(const std::vector<field_ct>& in, GeneratorContext context = {});
34-
// TODO health warnings!
35-
static field_ct hash_skip_field_validation(const std::vector<field_ct>& in, GeneratorContext context = {});
3634
static field_ct hash_buffer(const stdlib::byte_array<Builder>& input, GeneratorContext context = {});
3735
};
3836

barretenberg/cpp/src/barretenberg/stdlib/primitives/address/address.hpp

Lines changed: 0 additions & 144 deletions
This file was deleted.

0 commit comments

Comments
 (0)