diff --git a/barretenberg/README.md b/barretenberg/README.md index 07a4bb6eaba..998c1cd29e3 100644 --- a/barretenberg/README.md +++ b/barretenberg/README.md @@ -133,6 +133,11 @@ When running MacOS Sonoma 14.2.1 the following steps are necessary: - update bash with `brew install bash` - update [cmake](https://cmake.org/download) +It is recommended to use homebrew llvm on macOS to enable std::execution parallel algorithms. To do so: + +- Install llvm with `brew install llvm` +- Add it to the path with `export PATH="/opt/homebrew/opt/llvm/bin:$PATH"` in your shell or profile file. +

Installing openMP (Linux)

diff --git a/barretenberg/cpp/CMakeLists.txt b/barretenberg/cpp/CMakeLists.txt index 59e4a2565d4..ebbe45edd4d 100644 --- a/barretenberg/cpp/CMakeLists.txt +++ b/barretenberg/cpp/CMakeLists.txt @@ -31,7 +31,7 @@ option(DISABLE_AZTEC_VM "Don't build Aztec VM (acceptable if iterating on core p option(MULTITHREADING "Enable multi-threading" ON) option(OMP_MULTITHREADING "Enable OMP multi-threading" OFF) option(FUZZING "Build ONLY fuzzing harnesses" OFF) -option(DISABLE_TBB "Intel Thread Building Blocks" ON) +option(ENABLE_PAR_ALGOS "Enable parallel algorithms" ON) option(COVERAGE "Enable collecting coverage from tests" OFF) option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF) option(ENABLE_HEAVY_TESTS "Enable heavy tests when collecting coverage" OFF) @@ -47,7 +47,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "a set(DISABLE_ADX ON) set(RUN_HAVE_STD_REGEX 0) set(RUN_HAVE_POSIX_REGEX 0) - set(DISABLE_TBB 0) endif() if(CHECK_CIRCUIT_STACKTRACES) @@ -95,7 +94,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32") set(WASM ON) set(DISABLE_ASM ON) set(OMP_MULTITHREADING OFF) - set(DISABLE_TBB 1) + set(ENABLE_PAR_ALGOS 0) add_compile_definitions(_WASI_EMULATED_PROCESS_CLOCKS=1) endif() @@ -110,6 +109,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14") message(WARNING "Clang <14 is not supported") endif() + # Disable std::execution parallel algorithms on AppleClang as it is not supported. + if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") + set(ENABLE_PAR_ALGOS 0) + endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10") message(WARNING "GCC <10 is not supported") diff --git a/barretenberg/cpp/cmake/threading.cmake b/barretenberg/cpp/cmake/threading.cmake index fffffb6f83c..05b3a9a4994 100644 --- a/barretenberg/cpp/cmake/threading.cmake +++ b/barretenberg/cpp/cmake/threading.cmake @@ -23,15 +23,15 @@ else() add_definitions(-DNO_OMP_MULTITHREADING) endif() -if(DISABLE_TBB) - message(STATUS "Intel Thread Building Blocks is disabled.") - add_definitions(-DNO_TBB) -else() +if(ENABLE_PAR_ALGOS) find_package(TBB QUIET OPTIONAL_COMPONENTS tbb) if(${TBB_FOUND}) - message(STATUS "Intel Thread Building Blocks is enabled.") + message(STATUS "std::execution parallel algorithms are enabled.") else() - message(STATUS "Could not locate TBB.") - add_definitions(-DNO_TBB) + message(STATUS "Could not locate Intel TBB, disabling std::execution parallel algorithms.") + add_definitions(-DNO_PAR_ALGOS) endif() +else() + message(STATUS "std::execution parallel algorithms are disabled.") + add_definitions(-DNO_PAR_ALGOS) endif() diff --git a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/sorted_msm.cpp b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/sorted_msm.cpp index b295604904e..02b6ff7f353 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/sorted_msm.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/sorted_msm.cpp @@ -54,7 +54,7 @@ MsmSorter::AdditionSequences MsmSorter::construct_addition_sequenc // Create the array containing the indices of the scalars and points sorted by scalar value const size_t num_points = points.size(); std::iota(index.begin(), index.end(), 0); -#ifdef NO_TBB +#ifdef NO_PAR_ALGOS std::sort(index.begin(), index.end(), [&](size_t idx_1, size_t idx_2) { return scalars[idx_1] < scalars[idx_2]; }); #else std::sort(std::execution::par_unseq, index.begin(), index.end(), [&](size_t idx_1, size_t idx_2) { diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp index 023d1e81b3f..5cc245ee985 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -177,7 +177,7 @@ void compute_translator_range_constraint_ordered_polynomials(typename Flavor::Pr std::copy(sorted_elements.cbegin(), sorted_elements.cend(), sorted_element_insertion_offset); // Sort it -#ifdef NO_TBB +#ifdef NO_PAR_ALGOS std::sort(extra_denominator_uint.begin(), extra_denominator_uint.end()); #else std::sort(std::execution::par_unseq, extra_denominator_uint.begin(), extra_denominator.end()); diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp index 88c518cb4b3..90fb89c785d 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp @@ -105,7 +105,7 @@ std::array construct_sorted_list_polynomials(typ } } -#ifdef NO_TBB +#ifdef NO_PAR_ALGOS std::sort(lookup_gates.begin(), lookup_gates.end()); #else std::sort(std::execution::par_unseq, lookup_gates.begin(), lookup_gates.end()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp index 9409d1c119c..0e00ba6adc2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp @@ -1032,7 +1032,7 @@ template void UltraCircuitBuilder_:: sorted_list.emplace_back(shrinked_value); } -#ifdef NO_TBB +#ifdef NO_PAR_ALGOS std::sort(sorted_list.begin(), sorted_list.end()); #else std::sort(std::execution::par_unseq, sorted_list.begin(), sorted_list.end()); @@ -2560,7 +2560,7 @@ template void UltraCircuitBuilder_:: } } -#ifdef NO_TBB +#ifdef NO_PAR_ALGOS std::sort(rom_array.records.begin(), rom_array.records.end()); #else std::sort(std::execution::par_unseq, rom_array.records.begin(), rom_array.records.end()); @@ -2652,7 +2652,7 @@ template void UltraCircuitBuilder_:: } } -#ifdef NO_TBB +#ifdef NO_PAR_ALGOS std::sort(ram_array.records.begin(), ram_array.records.end()); #else std::sort(std::execution::par_unseq, ram_array.records.begin(), ram_array.records.end());