feat: add macOS (Apple Silicon) build support#1001
Open
philipportner wants to merge 1 commit intomainfrom
Open
feat: add macOS (Apple Silicon) build support#1001philipportner wants to merge 1 commit intomainfrom
philipportner wants to merge 1 commit intomainfrom
Conversation
DAPHNE was previously Linux-only. This adds support for building and running on macOS with Apple Silicon (ARM64) using GCC-15 from Homebrew. --- Build system (build.sh) --- Add platform detection and portable shell helpers: `get_nproc` (macOS lacks `nproc`) and `sed_inplace` (BSD sed uses `sed -i ''`). Recognize `arm64` alongside `aarch64` for architecture detection. Default PAPI to OFF on macOS (unsupported). Gate OpenMPI build behind `--mpi` flag to avoid unnecessary builds. Use GCC-15 for all builds including LLVM/MLIR to ensure ABI compatibility (libstdc++ throughout; mixing Clang's libc++ and GCC's libstdc++ causes link failures due to different symbol namespaces like std::__1:: vs std::__cxx11::). Disable LLD for LLVM/MLIR build on macOS (LLD is Clang/LLVM-specific). Patch third-party dependencies for GCC compatibility on macOS: - boringssl: replace `__builtin_available()` with unconditional check, remove `-stdlib=libc++` flags - Arrow 13: add missing `#include <algorithm>` (GCC-15 is stricter) - OpenBLAS: disable DYNAMIC_ARCH on macOS, suppress -Wincompatible-pointer-types errors - antlr4: remove deprecated CMP00xx OLD policies for CMake 4.x - spdlog: pass CMAKE_PREFIX_PATH so it finds our thirdparty fmt --- CMake --- Disable `-fuse-ld=lld` on macOS. Fix all `find_library` calls to use bare names (e.g. `hwloc` not `libhwloc.so`) so CMake finds `.dylib` on macOS. Set up Homebrew's libomp for OpenMP support on macOS. Fix Homebrew header pollution: LLVM's Findzstd.cmake sets the zstd target's INTERFACE_INCLUDE_DIRECTORIES to `/opt/homebrew/include`, which pulls in ALL Homebrew headers. This caused a symbol mismatch where Homebrew's fmt 11.2 headers were used during compilation but our thirdparty fmt 11.0 library was linked (the `vformat_to` function changed from template to non-template between versions). Fix by narrowing zstd's include path to `/opt/homebrew/opt/zstd/include`. Add `fmt::fmt` to MLIRDaphneTransforms link libraries (spdlog uses fmt with SPDLOG_FMT_EXTERNAL, but the link wasn't propagated). Use `.dylib` instead of `.so` in genKernelInst.py on Darwin. --- C++ source: Linux-only APIs --- Guard `sched_setaffinity`/`cpu_set_t`/`CPU_ZERO`/`CPU_SET` with `#ifdef __linux__` in the vectorized worker code (5 files). CPU pinning is not supported the same way on macOS. Replace `/proc/self/exe` with `_NSGetExecutablePath()` from `<mach-o/dyld.h>` in DaphneUserConfig.h for resolving the executable path on macOS. --- C++ source: ARM64 type differences --- On macOS ARM64 (LP64), `long` and `int64_t` are distinct types (`long` vs `long long`), and similarly `unsigned long` vs `uint64_t`. On Linux x86_64, these are the same type. This causes ambiguous overload resolution and missing template instantiation errors throughout. Fix ambiguous `ConstantOp` constructor calls by using explicit `static_cast<uint64_t>()` or `static_cast<int64_t>()` instead of passing `size_t`, `std::stoul()`, or `std::stol()` directly (in RewriteToCallKernelOpPass, DaphneDSLVisitor, DaphneVectorizableOpInterface). Fix `std::min(ssize_t, int64_t)` type mismatch in CTable.h. Fix const-member assignment in Tasks.h `withDifferentRange()` by using aggregate initialization instead of copy-then-modify (GCC-15 is stricter about this than Clang). Add `#if defined(__APPLE__) && defined(__aarch64__)` guarded template instantiations for `long`/`unsigned long` (and `long long`/ `unsigned long long`) in DenseMatrix, CSRMatrix, ContiguousTensor, ChunkedTensor, ValueTypeUtils, and CompilerUtils. --- C++ source: GCC linker fixes --- Change `static constexpr` to `inline constexpr` for variable template primary definitions and their explicit specializations in BinaryOpCode.h and UnaryOpCode.h. With GCC, `static` variable templates in headers create separate copies per translation unit, causing 324 duplicate symbol errors at link time. The `inline` keyword gives them proper external linkage with a single definition. Closes #759.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DAPHNE was previously Linux-only. This adds support for building and running on macOS with Apple Silicon (ARM64) using GCC-15 from Homebrew.
--- Build system (build.sh) ---
Add platform detection and portable shell helpers:
get_nproc(macOS lacksnproc) andsed_inplace(BSD sed usessed -i ''). Recognizearm64alongsideaarch64for architecture detection. Default PAPI to OFF on macOS (unsupported). Gate OpenMPI build behind--mpiflag to avoid unnecessary builds. Use GCC-15 for all builds including LLVM/MLIR to ensure ABI compatibility (libstdc++ throughout; mixing Clang's libc++ and GCC's libstdc++ causes link failures due to different symbol namespaces like std::__1:: vs std::__cxx11::). Disable LLD for LLVM/MLIR build on macOS (LLD is Clang/LLVM-specific).Patch third-party dependencies for GCC compatibility on macOS:
__builtin_available()with unconditional check, remove-stdlib=libc++flags#include <algorithm>(GCC-15 is stricter)--- CMake ---
Disable
-fuse-ld=lldon macOS. Fix allfind_librarycalls to use bare names (e.g.hwlocnotlibhwloc.so) so CMake finds.dylibon macOS. Set up Homebrew's libomp for OpenMP support on macOS.Fix Homebrew header pollution: LLVM's Findzstd.cmake sets the zstd target's INTERFACE_INCLUDE_DIRECTORIES to
/opt/homebrew/include, which pulls in ALL Homebrew headers. This caused a symbol mismatch where Homebrew's fmt 11.2 headers were used during compilation but our thirdparty fmt 11.0 library was linked (thevformat_tofunction changed from template to non-template between versions). Fix by narrowing zstd's include path to/opt/homebrew/opt/zstd/include.Add
fmt::fmtto MLIRDaphneTransforms link libraries (spdlog uses fmt with SPDLOG_FMT_EXTERNAL, but the link wasn't propagated).Use
.dylibinstead of.soin genKernelInst.py on Darwin.--- C++ source: Linux-only APIs ---
Guard
sched_setaffinity/cpu_set_t/CPU_ZERO/CPU_SETwith#ifdef __linux__in the vectorized worker code (5 files). CPU pinning is not supported the same way on macOS.Replace
/proc/self/exewith_NSGetExecutablePath()from<mach-o/dyld.h>in DaphneUserConfig.h for resolving the executable path on macOS.--- C++ source: ARM64 type differences ---
On macOS ARM64 (LP64),
longandint64_tare distinct types (longvslong long), and similarlyunsigned longvsuint64_t. On Linux x86_64, these are the same type. This causes ambiguous overload resolution and missing template instantiation errors throughout.Fix ambiguous
ConstantOpconstructor calls by using explicitstatic_cast<uint64_t>()orstatic_cast<int64_t>()instead of passingsize_t,std::stoul(), orstd::stol()directly (in RewriteToCallKernelOpPass, DaphneDSLVisitor, DaphneVectorizableOpInterface).Fix
std::min(ssize_t, int64_t)type mismatch in CTable.h.Fix const-member assignment in Tasks.h
withDifferentRange()by using aggregate initialization instead of copy-then-modify (GCC-15 is stricter about this than Clang).Add
#if defined(__APPLE__) && defined(__aarch64__)guarded template instantiations forlong/unsigned long(andlong long/unsigned long long) in DenseMatrix, CSRMatrix, ContiguousTensor, ChunkedTensor, ValueTypeUtils, and CompilerUtils.--- C++ source: GCC linker fixes ---
Change
static constexprtoinline constexprfor variable template primary definitions and their explicit specializations in BinaryOpCode.h and UnaryOpCode.h. With GCC,staticvariable templates in headers create separate copies per translation unit, causing 324 duplicate symbol errors at link time. Theinlinekeyword gives them proper external linkage with a single definition.Closes #759.