diff --git a/CMakeLists.txt b/CMakeLists.txt index ee1b532a..2e3ccc70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,7 @@ else(WIN32) cmake_minimum_required(VERSION 3.8) endif(WIN32) -if(NOT WIN32) - option( USE_NATIVE_ARCH "build which -march=native" ON) -endif(NOT WIN32) +option( USE_NATIVE_ARCH "build for native cpu architecture" ON) option( USE_GUI "don't build netgen with GUI" ON ) option( USE_PYTHON "build with python interface" ON ) @@ -94,11 +92,6 @@ if(USE_CCACHE) endif(CCACHE_FOUND) endif(USE_CCACHE) -####################################################################### -if(USE_NATIVE_ARCH) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") -endif(USE_NATIVE_ARCH) - ####################################################################### if(INTEL_MIC) set(MKL_ARCH "mic") @@ -411,6 +404,55 @@ if (USE_PYTHON) endif (USE_PYTHON) add_subdirectory(tests) +####################################################################### +if(USE_NATIVE_ARCH) + if(WIN32) + include(CheckCXXSourceRuns) + check_cxx_source_runs(" + #include + int main() + { + __m256d a{1.,2.,3.,4.}; + __m256d b{2.,0.,3.,5.}; + __m256d c = _mm256_mul_pd(a,b); + return 0; + } " NG_HAVE_AVX) + check_cxx_source_runs(" + #include + int main() + { + __m256i a{1,2,3,4}; + __m256i b{2,0,3,5}; + __m256i c = _mm256_cmpgt_epi64 (a,b); + return 0; + } " NG_HAVE_AVX2) + check_cxx_source_runs(" + #include + int main() + { + __m512d a{1.,2.,3.,4.}; + __m512d b{5.,6.,7.,8.}; + __m512d c = _mm512_mul_pd(a,b); + return 0; + } " NG_HAVE_AVX512) + + if(NG_HAVE_AVX512) + target_compile_options(ngcore PUBLIC "/arch:AVX512") + message(STATUS "Build for AVX512 CPU") + elseif(NG_HAVE_AVX2) + target_compile_options(ngcore PUBLIC "/arch:AVX2") + message(STATUS "Build for AVX2 CPU") + elseif(NG_HAVE_AVX) + target_compile_options(ngcore PUBLIC "/arch:AVX") + message(STATUS "Build for AVX CPU") + else() + message(STATUS "Build for generic CPU") + endif() + else() + target_compile_options(ngcore PUBLIC "-march=native") + endif(WIN32) +endif(USE_NATIVE_ARCH) + ####################################################################### # Debian packager diff --git a/cmake/NetgenConfig.cmake.in b/cmake/NetgenConfig.cmake.in index 0606332b..e8262666 100644 --- a/cmake/NetgenConfig.cmake.in +++ b/cmake/NetgenConfig.cmake.in @@ -54,6 +54,7 @@ set(NETGEN_USE_MPEG @USE_MPEG@) set(NETGEN_INTEL_MIC @INTEL_MIC@) set(NETGEN_INSTALL_PROFILES @INSTALL_PROFILES@) set(NETGEN_USE_CCACHE @USE_CCACHE@) +set(NETGEN_USE_NATIVE_ARCH @USE_NATIVE_ARCH@) set(NETGEN_PYTHON_RPATH "@NETGEN_PYTHON_RPATH@") set(NETGEN_RPATH_TOKEN "@NG_RPATH_TOKEN@")