Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions barretenberg/cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
"generator": "Ninja",
"toolchainFile": "cmake/toolchains/wasm32-wasi.cmake",
"environment": {
"WASI_SDK_PREFIX": "/opt/wasi-sdk",
"CC": "$env{WASI_SDK_PREFIX}/bin/clang",
"CXX": "$env{WASI_SDK_PREFIX}/bin/clang++",
"CXXFLAGS": "-DBB_VERBOSE -fvisibility=hidden",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
*/

#include "barretenberg/common/bb_bench.hpp"
#include "barretenberg/common/log.hpp"
#include "barretenberg/common/ref_span.hpp"
#include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/srs/factories/crs_factory.hpp"
#include "barretenberg/srs/global_crs.hpp"

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "barretenberg/common/assert.hpp"
#include "barretenberg/common/bb_bench.hpp"
#include "barretenberg/common/container.hpp"
#include "barretenberg/common/log.hpp"
#include "barretenberg/common/thread.hpp"
#include "barretenberg/common/throw_or_abort.hpp"
#include "barretenberg/constants.hpp"
Expand All @@ -19,6 +20,7 @@
#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp"
#include "barretenberg/transcript/transcript.hpp"
#include <cstddef>
#include <cstdlib>
#include <numeric>
#include <string>
#include <utility>
Expand Down
16 changes: 13 additions & 3 deletions barretenberg/cpp/src/barretenberg/common/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ namespace bb::detail {
* for it to reach num_workers_ before returning, guaranteeing no worker is
* still inside do_iterations() when the next generation is published.
*
* Idle wait is yield-spin then 100 us sleep_for fallback. Neither path
* lowers to i32.atomic.wait, so the V8 wasi-threads lost-wakeup race that
* affects condition_variable-based pools does not apply here.
* Idle wait is yield-spin then 100 us sleep_for fallback on native. Browser WASM
* keeps yielding because std::this_thread::sleep_for lowers to WASI poll_oneoff,
* which is intentionally stubbed out in this build. Neither path lowers to
* i32.atomic.wait, so the V8 wasi-threads lost-wakeup race that affects
* condition_variable-based pools does not apply here.
*
* This is the same design as the round-parallel MSM's local pool — the MSM
* dispatches parallel_for hundreds of times per proof, and per-call overhead
Expand Down Expand Up @@ -151,7 +153,11 @@ class ParallelForPool {
std::this_thread::yield();
}
while (!pred()) {
#ifdef __wasm__
std::this_thread::yield();
#else
std::this_thread::sleep_for(std::chrono::microseconds(100));
#endif
}
}
};
Expand Down Expand Up @@ -191,7 +197,11 @@ void ParallelForPool::worker_loop()
++idle_spins;
std::this_thread::yield();
} else {
#ifdef __wasm__
std::this_thread::yield();
#else
std::this_thread::sleep_for(std::chrono::microseconds(100));
#endif
}
}
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,21 @@ extern template class MSM<curve::BN254>;
// and bench targets can pin behaviour at the boundary.
inline constexpr size_t MIN_PTS_PER_THREAD_FOR_PIPPENGER = 24;

// Per-MSM arena sizer. Returns 0 for shapes that fall back to the Jacobian-fast path
// (no affine arena). Mirrors the inline budget calc inside `pippenger_round_parallel`;
// declared here so the test suite can exercise the same sizer.
template <typename Curve>
size_t compute_arena_bytes_for_msm(size_t n_input, bool external_glv_provided, bool dedup_active = false) noexcept;

namespace round_parallel_detail {

// Above this N, GLV's 2x point-count cost outweighs the windows-halved benefit.
#ifdef __wasm__
inline constexpr size_t GLV_SMALL_N_THRESHOLD = size_t{ 1 } << 16;
#else
inline constexpr size_t GLV_SMALL_N_THRESHOLD = size_t{ 1 } << 13;
#endif

/**
* @brief Single-MSM, no-affine-trick Pippenger over window_bits-wide windows.
*
Expand Down
Loading
Loading