From d1139b700db0ed640e216f76564278f14fd83dca Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Wed, 3 May 2023 13:15:31 +0200 Subject: [PATCH] Add LTO and M1 arch to CMake (#2106) Tweak CMake to set up Link Time Optimizations (helps pybind11) and set arch/tune for Arm Macs (M1 for now). --- CMakeLists.txt | 9 +++++++++ arbor/backends/multicore/threshold_watcher.hpp | 1 + cmake/CompilerOptions.cmake | 9 ++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4aa73c9b0..d2a7d20acc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.19) include(CMakeDependentOption) +include(CheckIPOSupported) # Make CUDA support throw errors if architectures remain unclear cmake_policy(SET CMP0104 NEW) @@ -16,6 +17,14 @@ include(GNUInstallDirs) # Effectively adds '-fpic' flag to CXX_FLAGS. Needed for dynamic catalogues. set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# Have LTO where possible, ie add -flto +check_ipo_supported(RESULT HAVE_LTO OUTPUT ERR_LTO) +if(HAVE_LTO AND NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION) + message (STATUS "LTO support found, enabling") + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) +else() + message(STATUS "No LTO: ${ERR_LTO}") +endif() # Turn on this option to force the compilers to produce color output when output is # redirected from the terminal (e.g. when using ninja or a pager). diff --git a/arbor/backends/multicore/threshold_watcher.hpp b/arbor/backends/multicore/threshold_watcher.hpp index b3419cdbb8..ed075ba8b6 100644 --- a/arbor/backends/multicore/threshold_watcher.hpp +++ b/arbor/backends/multicore/threshold_watcher.hpp @@ -58,6 +58,7 @@ class threshold_watcher { /// Crossing events are recorded for each threshold that /// is crossed since the last call to test void test(array& time_since_spike, const arb_value_type& t_before, const arb_value_type& t_after) { + if (cv_index_.empty() || n_detectors_ == 0) return; arb_assert(values_!=nullptr); // Reset all spike times to -1.0 indicating no spike has been recorded on the detector diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake index 5a8b2bcab0..824bb4e45e 100644 --- a/cmake/CompilerOptions.cmake +++ b/cmake/CompilerOptions.cmake @@ -110,12 +110,11 @@ function(set_arch_target optvar arch) endforeach(line) string(REGEX REPLACE "-.*" "" target_model "${target}") - # Use -mcpu for all supported targets _except_ for x86, where it should be -march. - - if("${target}" MATCHES "aarch64-apple-darwin") - set(arch_opt "-mcpu=${arch}") + # Use -mcpu for all supported targets _except_ for x86 and Apple arm64, where it should be -march. + 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}") + set(arch_opt "-march=${arch} -mtune=${arch}") else() set(arch_opt "-mcpu=${arch}") endif()