Skip to content
Snippets Groups Projects
Unverified Commit 1813fcd4 authored by Thorsten Hater's avatar Thorsten Hater Committed by GitHub
Browse files

Use `-march` correctly (#2302)

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.
parent 1a9e3d5f
No related branches found
No related tags found
No related merge requests found
...@@ -146,7 +146,8 @@ place_pwlin::place_pwlin(const arb::morphology& m, const isometry& iso) { ...@@ -146,7 +146,8 @@ place_pwlin::place_pwlin(const arb::morphology& m, const isometry& iso) {
arb_assert(!segments.empty()); arb_assert(!segments.empty());
seg_pos.reserve(segments.size()+1); seg_pos.reserve(segments.size()+1);
seg_pos = {0}; seg_pos.clear();
seg_pos.push_back(0);
for (auto& seg: segments) { for (auto& seg: segments) {
seg_pos.push_back(seg_pos.back()+distance(seg.prox, seg.dist)); seg_pos.push_back(seg_pos.back()+distance(seg.prox, seg.dist));
} }
......
...@@ -110,18 +110,27 @@ function(set_arch_target optvar optvar_cuda_guarded arch) ...@@ -110,18 +110,27 @@ function(set_arch_target optvar optvar_cuda_guarded arch)
endforeach(line) endforeach(line)
string(REGEX REPLACE "-.*" "" target_model "${target}") 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) if (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang" AND CMAKE_CXX_COMPILER_VERSION LESS 15)
set(arch_opt "") set(arch_opt "")
else() elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if("${target}" MATCHES "aarch64-apple-darwin" OR "${target}" MATCHES "arm64-apple-darwin") if ("${target}" MATCHES "(arm64|aarch64)-.*")
set(arch_opt "-march=${arch} -mtune=${arch}") # on AArch64, this is correct, ...
elseif(target_model MATCHES "x86|i[3456]86" OR target_model MATCHES "amd64" OR target_model MATCHES "aarch64") set(arch_opt "-mcpu=${arch} -mtune=${arch}")
set(arch_opt "-march=${arch} -mtune=${arch}")
else() else()
set(arch_opt "-mcpu=${arch}") # ... however on x86 mcpu _is_ mtune _and_ deprecated (since 2003!), but ...
endif() 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()
endif() endif()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment