Skip to content

Commit

Permalink
Rename DISABLE_TBB flag and disable on MacOS by default (#9747)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wraitii authored Nov 5, 2024
1 parent d7ee6e5 commit 047a964
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
5 changes: 5 additions & 0 deletions barretenberg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<details>
<summary><h3>Installing openMP (Linux)</h3></summary>

Expand Down
9 changes: 6 additions & 3 deletions barretenberg/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()

Expand All @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions barretenberg/cpp/cmake/threading.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ MsmSorter<Curve>::AdditionSequences MsmSorter<Curve>::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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ std::array<typename Flavor::Polynomial, 4> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ template <typename Arithmetization> void UltraCircuitBuilder_<Arithmetization>::
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());
Expand Down Expand Up @@ -2560,7 +2560,7 @@ template <typename Arithmetization> void UltraCircuitBuilder_<Arithmetization>::
}
}

#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());
Expand Down Expand Up @@ -2652,7 +2652,7 @@ template <typename Arithmetization> void UltraCircuitBuilder_<Arithmetization>::
}
}

#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());
Expand Down

0 comments on commit 047a964

Please sign in to comment.