Skip to content

Commit 9c1423a

Browse files
wraitiiMaddiaa0
authored andcommitted
Rename DISABLE_TBB flag and disable on MacOS by default (#9747)
Per #9746 , mac os compilation on ARM fails by default because of `std::execution::par_unseq`. This PR fixes that by explicitly disabling it on MacOS since apple clang doesn't support it. There's probably a better plug somewhere but I'm not ultra-familiar with how you setup the build system, should this be a preset, should this be based on apple-clang specifically, etc. Can adapt the PR as needed. I also rename DISABLE_TBB here because it seems to me that this should be part of the native C++20 support on other platforms, but I have to admit I'm really unfamiliar with the details here and I'm not sure if intel TBB is needed, or indeed what it does exactly. Can cut this from the PR. Likewise, this turns parallel algorithms ON by default on the same C++20 assumption, but that could well not work.
1 parent aabf175 commit 9c1423a

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

barretenberg/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ When running MacOS Sonoma 14.2.1 the following steps are necessary:
133133
- update bash with `brew install bash`
134134
- update [cmake](https://cmake.org/download)
135135

136+
It is recommended to use homebrew llvm on macOS to enable std::execution parallel algorithms. To do so:
137+
138+
- Install llvm with `brew install llvm`
139+
- Add it to the path with `export PATH="/opt/homebrew/opt/llvm/bin:$PATH"` in your shell or profile file.
140+
136141
<details>
137142
<summary><h3>Installing openMP (Linux)</h3></summary>
138143

barretenberg/cpp/CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ option(DISABLE_AZTEC_VM "Don't build Aztec VM (acceptable if iterating on core p
3131
option(MULTITHREADING "Enable multi-threading" ON)
3232
option(OMP_MULTITHREADING "Enable OMP multi-threading" OFF)
3333
option(FUZZING "Build ONLY fuzzing harnesses" OFF)
34-
option(DISABLE_TBB "Intel Thread Building Blocks" ON)
34+
option(ENABLE_PAR_ALGOS "Enable parallel algorithms" ON)
3535
option(COVERAGE "Enable collecting coverage from tests" OFF)
3636
option(ENABLE_ASAN "Address sanitizer for debugging tricky memory corruption" OFF)
3737
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
4747
set(DISABLE_ADX ON)
4848
set(RUN_HAVE_STD_REGEX 0)
4949
set(RUN_HAVE_POSIX_REGEX 0)
50-
set(DISABLE_TBB 0)
5150
endif()
5251

5352
if(CHECK_CIRCUIT_STACKTRACES)
@@ -95,7 +94,7 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "wasm32")
9594
set(WASM ON)
9695
set(DISABLE_ASM ON)
9796
set(OMP_MULTITHREADING OFF)
98-
set(DISABLE_TBB 1)
97+
set(ENABLE_PAR_ALGOS 0)
9998
add_compile_definitions(_WASI_EMULATED_PROCESS_CLOCKS=1)
10099
endif()
101100

@@ -110,6 +109,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
110109
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14")
111110
message(WARNING "Clang <14 is not supported")
112111
endif()
112+
# Disable std::execution parallel algorithms on AppleClang as it is not supported.
113+
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
114+
set(ENABLE_PAR_ALGOS 0)
115+
endif()
113116
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
114117
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10")
115118
message(WARNING "GCC <10 is not supported")

barretenberg/cpp/cmake/threading.cmake

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ else()
2323
add_definitions(-DNO_OMP_MULTITHREADING)
2424
endif()
2525

26-
if(DISABLE_TBB)
27-
message(STATUS "Intel Thread Building Blocks is disabled.")
28-
add_definitions(-DNO_TBB)
29-
else()
26+
if(ENABLE_PAR_ALGOS)
3027
find_package(TBB QUIET OPTIONAL_COMPONENTS tbb)
3128
if(${TBB_FOUND})
32-
message(STATUS "Intel Thread Building Blocks is enabled.")
29+
message(STATUS "std::execution parallel algorithms are enabled.")
3330
else()
34-
message(STATUS "Could not locate TBB.")
35-
add_definitions(-DNO_TBB)
31+
message(STATUS "Could not locate Intel TBB, disabling std::execution parallel algorithms.")
32+
add_definitions(-DNO_PAR_ALGOS)
3633
endif()
34+
else()
35+
message(STATUS "std::execution parallel algorithms are disabled.")
36+
add_definitions(-DNO_PAR_ALGOS)
3737
endif()

barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/sorted_msm.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ MsmSorter<Curve>::AdditionSequences MsmSorter<Curve>::construct_addition_sequenc
5454
// Create the array containing the indices of the scalars and points sorted by scalar value
5555
const size_t num_points = points.size();
5656
std::iota(index.begin(), index.end(), 0);
57-
#ifdef NO_TBB
57+
#ifdef NO_PAR_ALGOS
5858
std::sort(index.begin(), index.end(), [&](size_t idx_1, size_t idx_2) { return scalars[idx_1] < scalars[idx_2]; });
5959
#else
6060
std::sort(std::execution::par_unseq, index.begin(), index.end(), [&](size_t idx_1, size_t idx_2) {

barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void compute_translator_range_constraint_ordered_polynomials(typename Flavor::Pr
177177
std::copy(sorted_elements.cbegin(), sorted_elements.cend(), sorted_element_insertion_offset);
178178

179179
// Sort it
180-
#ifdef NO_TBB
180+
#ifdef NO_PAR_ALGOS
181181
std::sort(extra_denominator_uint.begin(), extra_denominator_uint.end());
182182
#else
183183
std::sort(std::execution::par_unseq, extra_denominator_uint.begin(), extra_denominator.end());

barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ std::array<typename Flavor::Polynomial, 4> construct_sorted_list_polynomials(typ
105105
}
106106
}
107107

108-
#ifdef NO_TBB
108+
#ifdef NO_PAR_ALGOS
109109
std::sort(lookup_gates.begin(), lookup_gates.end());
110110
#else
111111
std::sort(std::execution::par_unseq, lookup_gates.begin(), lookup_gates.end());

barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ template <typename Arithmetization> void UltraCircuitBuilder_<Arithmetization>::
10321032
sorted_list.emplace_back(shrinked_value);
10331033
}
10341034

1035-
#ifdef NO_TBB
1035+
#ifdef NO_PAR_ALGOS
10361036
std::sort(sorted_list.begin(), sorted_list.end());
10371037
#else
10381038
std::sort(std::execution::par_unseq, sorted_list.begin(), sorted_list.end());
@@ -2560,7 +2560,7 @@ template <typename Arithmetization> void UltraCircuitBuilder_<Arithmetization>::
25602560
}
25612561
}
25622562

2563-
#ifdef NO_TBB
2563+
#ifdef NO_PAR_ALGOS
25642564
std::sort(rom_array.records.begin(), rom_array.records.end());
25652565
#else
25662566
std::sort(std::execution::par_unseq, rom_array.records.begin(), rom_array.records.end());
@@ -2652,7 +2652,7 @@ template <typename Arithmetization> void UltraCircuitBuilder_<Arithmetization>::
26522652
}
26532653
}
26542654

2655-
#ifdef NO_TBB
2655+
#ifdef NO_PAR_ALGOS
26562656
std::sort(ram_array.records.begin(), ram_array.records.end());
26572657
#else
26582658
std::sort(std::execution::par_unseq, ram_array.records.begin(), ram_array.records.end());

0 commit comments

Comments
 (0)