From 3cad81afdb7b2fe7e7f26deda4a8848dbef9c6e6 Mon Sep 17 00:00:00 2001 From: Simon Shillaker <554768+Shillaker@users.noreply.github.com> Date: Mon, 14 Mar 2022 14:59:08 +0100 Subject: [PATCH] Add flag for optimising for specific CPU (#240) --- CMakeLists.txt | 9 ++++++++- cmake/OptimiseCPU.cmake | 41 ----------------------------------------- tasks/dev.py | 9 ++++++++- 3 files changed, 16 insertions(+), 43 deletions(-) delete mode 100644 cmake/OptimiseCPU.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index a13f7cd25..13d549c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ option(FAABRIC_WASM_BUILD "Build Faabric wasm library" OFF) option(FAABRIC_BUILD_TESTS "Build Faabric tests" ON) option(FAABRIC_SELF_TRACING "Turn on system tracing using the logger" OFF) +option(FAABRIC_TARGET_CPU "CPU to optimise for, e.g. skylake, icelake or native" OFF) + # Enable colorized compiler output if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") add_compile_options(-fdiagnostics-color=always) @@ -13,7 +15,12 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") endif() # Optimise for CPU -include(cmake/OptimiseCPU.cmake) +if(FAABRIC_TARGET_CPU) + message(STATUS "Optimising Faabric for CPU ${FAABRIC_TARGET_CPU}") + add_compile_options(-march=${FAABRIC_TARGET_CPU} -mtune=${FAABRIC_TARGET_CPU}) +else() + message(STATUS "Faabric not optimised for specific CPU") +endif() # Top-level CMake config set(CMAKE_CXX_FLAGS "-Wall") diff --git a/cmake/OptimiseCPU.cmake b/cmake/OptimiseCPU.cmake deleted file mode 100644 index 14bcd96e1..000000000 --- a/cmake/OptimiseCPU.cmake +++ /dev/null @@ -1,41 +0,0 @@ -set(CPU_VENDOR) -set(CPU_FAMILY) -set(CPU_MODEL) -set(CPU_PROPS) - -file(READ "/proc/cpuinfo" _cpuinfo) -string(REGEX REPLACE ".*vendor_id[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" - CPU_VENDOR "${_cpuinfo}") -string(REGEX REPLACE ".*cpu family[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" - CPU_FAMILY "${_cpuinfo}") -string(REGEX REPLACE ".*model[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" - CPU_MODEL "${_cpuinfo}") -string(REGEX REPLACE ".*flags[ \t]*:[ \t]+([^\n]+).*" "\\1" - CPU_PROPS "${_cpuinfo}") - -message("Found CPU: Vendor = ${CPU_VENDOR} Family = ${CPU_FAMILY} Model = ${CPU_MODEL} Props = ${CPU_PROPS}") - -# See this file for an example of extending this list: -# https://github.com/VcDevel/Vc/blob/1.4/cmake/OptimizeForArchitecture.cmake -# See the LLVM source for list of supported arch, e.g. this test: -# https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/x86-march.c - -set(CPU_COMPILE_FLAGS) -if(CPU_VENDOR STREQUAL "GenuineIntel") - if(CPU_FAMILY EQUAL 6) - if(CPU_MODEL EQUAL 78 OR CPU_MODEL EQUAL 94) - # Skylake - set(CPU_COMPILE_FLAGS -march=skylake -mtune=skylake) - elseif(CPU_MODEL EQUAL 58 OR CPU_MODEL EQUAL 62) - # Ivy bridge - set(CPU_COMPILE_FLAGS -march=ivybridge -mtune=ivybridge) - endif() - endif() -endif() - -if(CPU_COMPILE_FLAGS) - message("Setting following CPU-specific compile flags: ${CPU_COMPILE_FLAGS}") - add_compile_options(${CPU_COMPILE_FLAGS}) -else() - message("Could not provide any CPU-specific compile flags") -endif() diff --git a/tasks/dev.py b/tasks/dev.py index 3559e1f1b..023c773ac 100644 --- a/tasks/dev.py +++ b/tasks/dev.py @@ -15,7 +15,13 @@ @task def cmake( - ctx, clean=False, shared=False, build="Debug", sanitiser="None", prof=False + ctx, + clean=False, + shared=False, + build="Debug", + sanitiser="None", + prof=False, + cpu=None, ): """ Configures the build @@ -44,6 +50,7 @@ def cmake( "-DCMAKE_C_COMPILER=/usr/bin/clang-13", "-DFAABRIC_USE_SANITISER={}".format(sanitiser), "-DFAABRIC_SELF_TRACING=ON" if prof else "", + "-DFAABRIC_TARGET_CPU={}".format(cpu) if cpu else "", PROJ_ROOT, ]