Skip to content

Commit 20c9dd8

Browse files
committed
Attempt to fix AVX compilation issues on MacOS
The common wisdom is wrong, apparently: `-march=native` does not work for AVX on MacOS.
1 parent bb3a9f5 commit 20c9dd8

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

pybind_interface/avx2/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ project(qsim)
1717

1818
IF (WIN32)
1919
add_compile_options(/arch:AVX2)
20-
ELSEIF(APPLE AND NOT CMAKE_APPLE_SILICON_PROCESSOR)
21-
# On Intel MacOS, CMake detects AVX* but clang doesn't recognize -mavx2.
22-
# Using arch=native should turn on the features if they're available.
23-
add_compile_options(-march=native)
24-
ELSE()
20+
ELSEIF(NOT CMAKE_APPLE_SILICON_PROCESSOR)
2521
add_compile_options(-mavx2 -mfma)
2622
ENDIF()
2723

pybind_interface/avx512/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ project(qsim)
1717

1818
IF (WIN32)
1919
add_compile_options(/arch:AVX512)
20-
ELSEIF(APPLE AND NOT CMAKE_APPLE_SILICON_PROCESSOR
20+
ELSEIF(APPLE
21+
AND NOT CMAKE_APPLE_SILICON_PROCESSOR
2122
AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
22-
# On Intel Macs CMake detects AVX but clang doesn't recognize -mavx512.
23-
# Using arch=native should turn on the features if they're available.
24-
add_compile_options(-march=native)
23+
# Note: some sources recommend against using -mavx512f, and say to use
24+
# -march=native. The doesn't work on Mac Intel systems, at least in MacOS
25+
# 13 (and possibly higher); the compiler does not enable AVX512 features.
26+
add_compile_options(-mavx512f)
2527
ELSE()
2628
add_compile_options(-mavx512f -mbmi2)
2729
ENDIF()

0 commit comments

Comments
 (0)