Skip to content

Commit

Permalink
fix: parallelization of sumcheck partially_evaluate
Browse files Browse the repository at this point in the history
  • Loading branch information
ludamad0 committed Oct 19, 2023
1 parent b062c2e commit 6c0d8ae
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
17 changes: 7 additions & 10 deletions barretenberg/cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,17 @@
}
},
{
"name": "xray-1thread-verbose",
"name": "xray-verbose",
"displayName": "Build with single-threaded XRay Profiling",
"description": "Build with Clang and enable single-threaded LLVM XRay for profiling",
"generator": "Unix Makefiles",
"inherits": "clang16",
"environment": {
"CFLAGS": "-fxray-instrument -fxray-instruction-threshold=100 -mllvm -finline-max-stacksize=150",
"CXXFLAGS": "-fxray-instrument -fxray-instruction-threshold=100 -mllvm -finline-max-stacksize=150",
"LDFLAGS": "-fxray-instrument -fxray-instruction-threshold=100 -mllvm -finline-max-stacksize=150"
"CFLAGS": "-fxray-instrument -fxray-instruction-threshold=100 -finline-max-stacksize=150",
"CXXFLAGS": "-fxray-instrument -fxray-instruction-threshold=100 -finline-max-stacksize=150",
"LDFLAGS": "-fxray-instrument -fxray-instruction-threshold=100 -finline-max-stacksize=150"
},
"cacheVariables": {
"MULTITHREADING": "OFF"
},
"binaryDir": "build-xray-1thread-verbose"
"binaryDir": "build-xray-verbose"
},
{
"name": "xray-1thread",
Expand Down Expand Up @@ -320,8 +317,8 @@
"targets": ["barretenberg.wasm"]
},
{
"name": "xray-1thread-verbose",
"configurePreset": "xray-1thread-verbose",
"name": "xray-verbose",
"configurePreset": "xray-verbose",
"inherits": "default"
},
{
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/scripts/collect_profile_information.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ llvm-xray-16 stack xray-log.honk_bench_main_simple.* \
--instr_map=./bin/honk_bench_main_simple --stack-format=flame --aggregate-threads --aggregation-type=time --all-stacks \
| node ../scripts/llvm_xray_stack_flame_corrector.js \
| shorten_cpp_names \
| ../scripts/flamegraph.pl --width 2000 --fontsize 10 \
| ../scripts/flamegraph.pl --width 1200 --fontsize 10 \
> xray.svg
echo "Profiling complete, now you can do e.g. 'scp mainframe:`readlink -f xray.svg` .' on a local terminal and open the SVG in a browser."
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ template <typename Builder> void generate_sha256_test_circuit(Builder& builder,
BBERG_INSTRUMENT BBERG_NOINLINE void sumcheck_profiling(honk::UltraProver& ext_prover)
{
ext_prover.construct_proof();
for (size_t i = 0; i < 10000; i++) {
for (size_t i = 0; i < 200; i++) {
// Bench sumcheck
ext_prover.execute_relation_check_rounds();
}
Expand All @@ -60,7 +60,8 @@ void construct_proof_ultra() noexcept
barretenberg::srs::init_crs_factory("../srs_db/ignition");
// Constuct circuit and prover; don't include this part in measurement
honk::UltraComposer::CircuitBuilder builder;
generate_sha256_test_circuit(builder, 100);
generate_sha256_test_circuit(builder, 1);
std::cout << "gates: " << builder.get_total_circuit_size() << std::endl;

honk::UltraComposer composer;
std::shared_ptr<honk::UltraComposer::Instance> instance = composer.create_instance(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ThreadPool {
std::condition_variable complete_condition_;
bool stop = false;

void worker_loop(size_t thread_index);
[[clang::xray_never_instrument]] void worker_loop(size_t thread_index);

void do_iterations()
{
Expand Down
6 changes: 4 additions & 2 deletions barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ template <typename Flavor> class SumcheckProver {
void partially_evaluate(auto& polynomials, size_t round_size, FF round_challenge)
{
// after the first round, operate in place on partially_evaluated_polynomials
for (size_t j = 0; j < polynomials.size(); ++j) {
parallel_for(polynomials.size(), [&](size_t j) {
for (size_t i = 0; i < round_size; i += 2) {
auto x = polynomials[j][i];
std::cout << polynomials[j][i] << std::endl;
partially_evaluated_polynomials[j][i >> 1] =
polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]);
}
}
});
};
};

Expand Down

0 comments on commit 6c0d8ae

Please sign in to comment.