Skip to content

feat: add macOS (Apple Silicon) build support#1001

Open
philipportner wants to merge 1 commit intomainfrom
macos_native_build
Open

feat: add macOS (Apple Silicon) build support#1001
philipportner wants to merge 1 commit intomainfrom
macos_native_build

Conversation

@philipportner
Copy link
Collaborator

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAC OSX support

1 participant