Skip to content
Snippets Groups Projects
Commit a0425710 authored by Marcel Loose's avatar Marcel Loose :sunglasses: Committed by Jakob Maljaars
Browse files

Initial version of target CPU selection

This commit contains an initial working version of target CPU selection.
The name of the target CPU (if any) will be part of the Debian package
name. The package will also contain a the list conflicting packages,
based on the fact that different target CPUs will excluded one another.
parent 1bc4481c
Branches
Tags
1 merge request!101Select target cpu
......@@ -45,6 +45,21 @@ set(GIT_VERSION_HEADER "idg-version.h")
include(cmake/version.cmake)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
option(PORTABLE "Build portable binaries" OFF)
if(PORTABLE)
if(DEFINED TARGET_CPU)
message(WARNING "You have selected to build PORTABLE binaries. "
"TARGET_CPU settings will be ignored.")
unset(TARGET_CPU CACHE)
endif()
else()
if(DEFINED TARGET_CPU)
add_compile_options(-march=${TARGET_CPU})
else()
add_compile_options(-march=native)
endif()
endif()
# MPI
if (BUILD_WITH_MPI)
find_package(MPI REQUIRED)
......
......@@ -73,7 +73,15 @@ if(NOT VERSION_STRING)
"using ${VERSION_STRING} instead.")
endif()
set(CPACK_PACKAGE_NAME "IDG")
include(${CMAKE_CURRENT_SOURCE_DIR}/DetermineTargetCPU.cmake)
# Set package name: encode target CPU, if defined, in package name.
if(DEFINED IDENTIFIED_TARGET_CPU)
set(CPACK_PACKAGE_NAME "idg-${IDENTIFIED_TARGET_CPU}")
else()
set(CPACK_PACKAGE_NAME "idg")
endif()
set(CPACK_PACKAGE_VENDOR "ASTRON")
set(CPACK_PACKAGE_VERSION "${VERSION_STRING}")
......@@ -94,6 +102,28 @@ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "deb-packages@astron.nl")
set(CPACK_DEBIAN_PACKAGE_SECTION "science")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
# Determine list of conflicting package names
# Iterate over all components, each component has its own package
foreach(_component ${CPACK_COMPONENTS_ALL})
string(TOUPPER ${_component} _COMPONENT)
if(DEFINED IDENTIFIED_TARGET_CPU)
set(_conflicts idg-${_component})
else()
set(_conflicts)
endif()
# Packages not built for current target CPU always conflict
foreach(_cpu ${KNOWN_TARGET_CPUS})
if(NOT "${_cpu}" STREQUAL "${IDENTIFIED_TARGET_CPU}")
if("${_conflicts}" STREQUAL "")
set(_conflicts "idg-${_cpu}-${_component}")
else()
set(_conflicts "${_conflicts}, idg-${_cpu}-${_component}")
endif()
endif()
endforeach()
set(CPACK_DEBIAN_${_COMPONENT}_PACKAGE_CONFLICTS "${_conflicts}")
endforeach()
include(CPack)
message(STATUS "Package name: ${CPACK_PACKAGE_NAME}")
......
#[=======================================================================[.rst:
DetermineTargetCPU
---------------------------
Determine the target CPU used for the current build.
By default, the build system will generate code that is optimized for the
current architecture, by using the compile option `-march=native`. This will
let the compiler determine the target CPU. The user may also manually select
a specific target CPU by setting the variable ``TARGET_CPU``. In order to
force the compiler to generate portable code, the user can set the option
``PORTABLE`` to ``TRUE``. Note that ``PORTABLE`` takes precedence over
``TARGET_CPU``.
This module determines which target CPU the compiler has selected, if any,
and stores the result in the internal variable ``IDENTIFIED_TARGET_CPU``.
#]=======================================================================]
# List of target CPUs known by both GCC and Clang
# This list was produced as follows (note: requires llc to be installed):
# comm -12 \
# <(g++ -march=foo -E - < /dev/null |& grep '^cc1: note' | \
# sed -nE 's,^.*: *([^;]*).*$,\1,p' | tr ' ' '\n' | sort -u) \
# <(llc -mattr=help |& grep processor. | awk '{print $1}' | sort -u)
set(KNOWN_TARGET_CPUS
amdfam10 athlon64 athlon64-sse3 athlon-fx atom barcelona bdver1 bdver2
bdver3 bdver4 bonnell broadwell btver1 btver2 core2 core-avx2 core-avx-i
corei7 corei7-avx haswell ivybridge k8 k8-sse3 knl nehalem nocona opteron
opteron-sse3 sandybridge silvermont skylake skylake-avx512 slm westmere
x86-64 znver1 CACHE INTERNAL "Known target CPUs")
if(NOT PORTABLE)
get_directory_property(_compile_options COMPILE_OPTIONS)
string(REPLACE ";" " " _compile_options "${_compile_options}")
execute_process(COMMAND bash -c
# Executed command is printed on stderr; we can discard stdout
"echo | ${CMAKE_CXX_COMPILER} ${_compile_options} -E -v - >/dev/null"
ERROR_VARIABLE _command
RESULT_VARIABLE _result)
if(NOT _result EQUAL 0)
message(WARNING "${CMAKE_CXX_COMPILER_ID} compiler failed to identify "
"target CPU '${TARGET_CPU}'")
else()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
execute_process(COMMAND bash -c
"echo '${_command}' | sed -nE '/cc1/s/^.*-march=([^ ]+).*$/\\1/p'"
OUTPUT_VARIABLE _target_cpu
OUTPUT_STRIP_TRAILING_WHITESPACE)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
execute_process(COMMAND bash -c
"echo '${_command}' | sed -nE '/cc1/s/^.*-target-cpu ([^ ]+).*$/\\1/p'"
OUTPUT_VARIABLE _target_cpu
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
message(WARNING "Don't know how to let ${CMAKE_CXX_COMPILER_ID} "
"compiler identify target CPU")
endif()
endif()
endif()
if(DEFINED _target_cpu)
set(IDENTIFIED_TARGET_CPU ${_target_cpu} CACHE INTERNAL "")
else()
unset(IDENTIFIED_TARGET_CPU CACHE)
endif()
if(DEFINED IDENTIFIED_TARGET_CPU AND
NOT IDENTIFIED_TARGET_CPU IN_LIST KNOWN_TARGET_CPUS)
message(AUTHOR_WARNING
"'${IDENTIFIED_TARGET_CPU}' is not in the list KNOWN_TARGET_CPUS. "
"Please check if this list is still up-to-date")
endif()
......@@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(wmodes, *utf::depends_on("gridder/reference")) {
for (WMode wmode : kWModes) {
std::vector<double> image_wmode =
GridImage(idg::api::Type::CPU_REFERENCE, wmode);
CompareImages(image_ref, image_wmode, 1.2);
CompareImages(image_ref, image_wmode, 1.3);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment