Skip to content

Commit

Permalink
Use -march correctly (#2302)
Browse files Browse the repository at this point in the history
Selecting tuning flags depends on compilers and architectures. 
Account for this complication which became more apparent w/
proliferation of Arm64 based chips.

Following from: https://maskray.me/blog/2022-08-28-march-mcpu-mtune

Also fix a new --- sensible --- warning.
  • Loading branch information
thorstenhater authored Aug 5, 2024
1 parent 1a9e3d5 commit 1813fcd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion arbor/morph/place_pwlin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ place_pwlin::place_pwlin(const arb::morphology& m, const isometry& iso) {
arb_assert(!segments.empty());

seg_pos.reserve(segments.size()+1);
seg_pos = {0};
seg_pos.clear();
seg_pos.push_back(0);
for (auto& seg: segments) {
seg_pos.push_back(seg_pos.back()+distance(seg.prox, seg.dist));
}
Expand Down
27 changes: 18 additions & 9 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,27 @@ function(set_arch_target optvar optvar_cuda_guarded arch)
endforeach(line)
string(REGEX REPLACE "-.*" "" target_model "${target}")

# Use -mcpu for all supported targets _except_ for x86 and Apple arm64, where it should be -march.

# Figure out which flags to pass to compiler to tune for concrete
# architecture.
# See clang / gcc manuals and:
# https://maskray.me/blog/2022-08-28-march-mcpu-mtune
if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" AND CMAKE_CXX_COMPILER_VERSION LESS 15)
set(arch_opt "")
else()
if("${target}" MATCHES "aarch64-apple-darwin" OR "${target}" MATCHES "arm64-apple-darwin")
set(arch_opt "-march=${arch} -mtune=${arch}")
elseif(target_model MATCHES "x86|i[3456]86" OR target_model MATCHES "amd64" OR target_model MATCHES "aarch64")
set(arch_opt "-march=${arch} -mtune=${arch}")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if ("${target}" MATCHES "(arm64|aarch64)-.*")
# on AArch64, this is correct, ...
set(arch_opt "-mcpu=${arch} -mtune=${arch}")
else()
set(arch_opt "-mcpu=${arch}")
endif()
# ... however on x86 mcpu _is_ mtune _and_ deprecated (since 2003!), but ...
set(arch_opt "-march=${arch}")
endif ()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# ... clang likes march (and possibly mtune)
# See https://discourse.llvm.org/t/when-to-use-mcpu-versus-march/47953/9
set(arch_opt "-march=${arch} -mtune=${arch}")
else ()
message(STATUS "Falling back to -march=${arch} for compiler ${CMAKE_CXX_COMPILER_ID}")
set(arch_opt "-march=${arch}")
endif()
endif()

Expand Down

0 comments on commit 1813fcd

Please sign in to comment.