From b4c5b75f3758bed9335c1a63e1e0de3cad618986 Mon Sep 17 00:00:00 2001
From: Ben Cumming <bcumming@cscs.ch>
Date: Sat, 9 Jul 2016 19:04:05 +0200
Subject: [PATCH] use KNL-specific compiler flags for KNL target

added flags for GNU and Intel compilers to the cmake build rules
that generate KNL-specific instructions when the TARGET_KNL cmake
flag is set.
---
 CMakeLists.txt              |  6 ++++++
 cmake/CompilerOptions.cmake | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 37f1cfe8..44e40b63 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,6 +62,12 @@ if(SYSTEM_CRAY)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -dynamic")
 endif()
 
+# Cray systems
+set(TARGET_KNL OFF CACHE BOOL "target Intel KNL architecture")
+if(TARGET_KNL)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXOPT_KNL}")
+endif()
+
 # targets for extermal dependencies
 include(ExternalProject)
 externalproject_add(modparser
diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake
index 167ae048..6dc09b96 100644
--- a/cmake/CompilerOptions.cmake
+++ b/cmake/CompilerOptions.cmake
@@ -13,10 +13,21 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
     set(CXXOPT_WALL "${CXXOPT_WALL} -Wno-missing-braces")
 endif()
 
+if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
+
+    # compiler flags for generating KNL-specific AVX512 instructions
+    # supported in gcc 4.9.x and later
+    #set(CXXOPT_KNL "-mavx512f")
+    set(CXXOPT_KNL "-march=knl")
+endif()
+
 if(${CMAKE_CXX_COMPILER_ID} MATCHES "Intel")
     # Disable warning for unused template parameter
     # this is raised by a templated function in the json library
 
     set(CXXOPT_WALL "${CXXOPT_WALL} -wd488")
+
+    # compiler flags for generating KNL-specific AVX512 instructions
+    set(CXXOPT_KNL "-xMIC-AVX512")
 endif()
 
-- 
GitLab