Skip to content

Commit

Permalink
Add LTO and M1 arch to CMake (#2106)
Browse files Browse the repository at this point in the history
Tweak CMake to set up Link Time Optimizations (helps pybind11) and set
arch/tune for Arm Macs (M1 for now).
  • Loading branch information
thorstenhater authored May 3, 2023
1 parent fcccfcb commit d1139b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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).
Expand Down
1 change: 1 addition & 0 deletions arbor/backends/multicore/threshold_watcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions cmake/CompilerOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d1139b7

Please sign in to comment.