Merge branch 'native_arch_on_windows' into 'master'

Native arch on windows

See merge request jschoeberl/netgen!310
This commit is contained in:
Joachim Schöberl 2020-01-17 18:00:07 +00:00
commit 538ca486fd
6 changed files with 67 additions and 34 deletions

View File

@ -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")
@ -222,13 +215,9 @@ endmacro()
set(CMAKE_CXX_STANDARD 17)
if(WIN32)
get_WIN32_WINNT(ver)
add_definitions(-D_WIN32_WINNT=${ver} -DWNT -DWNT_WINDOW -DNOMINMAX)
set(CMAKE_MFC_FLAG 0)
add_definitions(-DMSVC_EXPRESS -D_CRT_SECURE_NO_WARNINGS -DHAVE_STRUCT_TIMESPEC)
# build convenience (aka object) libraries in windows)
set(NG_LIB_TYPE OBJECT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else(WIN32)
# build shared libraries
set(NG_LIB_TYPE SHARED)
@ -411,6 +400,59 @@ if (USE_PYTHON)
endif (USE_PYTHON)
add_subdirectory(tests)
#######################################################################
if(USE_NATIVE_ARCH)
if(WIN32)
include(CheckCXXSourceRuns)
check_cxx_source_runs("
#include <immintrin.h>
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 <immintrin.h>
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 <immintrin.h>
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)
if(APPLE)
# work-around for bug in Xcode 11.3: https://forums.developer.apple.com/thread/121887
target_compile_options(ngcore PUBLIC "-fno-stack-check")
endif(APPLE)
endif(USE_NATIVE_ARCH)
#######################################################################
# Debian packager

View File

@ -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@")

View File

@ -20,18 +20,6 @@ if(WIN32)
set (OCC_DOWNLOAD_URL_WIN "${DEPS_DOWNLOAD_URL}/occ_win64.zip" CACHE STRING INTERNAL)
set (TCLTK_DOWNLOAD_URL_WIN "${DEPS_DOWNLOAD_URL}/tcltk_win64.zip" CACHE STRING INTERNAL)
set (ZLIB_DOWNLOAD_URL_WIN "${DEPS_DOWNLOAD_URL}/zlib_win64.zip" CACHE STRING INTERNAL)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_CXX_FLAGS_NEW ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_NEW} CACHE STRING "compile flags" FORCE)
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_CXX_FLAGS_NEW ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_NEW} CACHE STRING "compile flags" FORCE)
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_SHARED_LINKER_FLAGS_NEW ${CMAKE_SHARED_LINKER_FLAGS})
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_NEW} /IGNORE:4217,4049" CACHE STRING "compile flags" FORCE)
string(REGEX REPLACE "/W[0-4]" "/W0" CMAKE_EXE_LINKER_FLAGS_NEW ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS"${CMAKE_EXE_LINKER_FLAGS_NEW}/IGNORE:4217,4049" CACHE STRING "compile flags" FORCE)
endif(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
endif(WIN32)
if(UNIX)

View File

@ -23,21 +23,21 @@ if(USE_PYTHON)
target_compile_definitions(ngcore PUBLIC NETGEN_PYTHON NG_PYTHON)
endif(USE_PYTHON)
target_compile_definitions(ngcore PRIVATE NGCORE_EXPORTS)
if(NOT WIN32)
target_compile_options(ngcore PRIVATE -fvisibility=hidden)
endif(NOT WIN32)
if(WIN32)
target_compile_options(ngcore PUBLIC /bigobj)
target_compile_options(ngcore PUBLIC /bigobj /MP /W1 /wd4068)
get_WIN32_WINNT(ver)
target_compile_definitions(ngcore PUBLIC _WIN32_WINNT=${ver} WNT WNT_WINDOW NOMINMAX MSVC_EXPRESS _CRT_SECURE_NO_WARNINGS HAVE_STRUCT_TIMESPEC)
target_link_options(ngcore PUBLIC /ignore:4273 /ignore:4217 /ignore:4049)
else(WIN32)
target_compile_options(ngcore PRIVATE -fvisibility=hidden)
endif(WIN32)
target_compile_definitions(ngcore PUBLIC $<$<CONFIG:DEBUG>:NETGEN_ENABLE_CHECK_RANGE>)
target_compile_definitions(ngcore PRIVATE NGCORE_EXPORTS)
target_include_directories(ngcore INTERFACE $<INSTALL_INTERFACE:${NG_INSTALL_DIR_INCLUDE}> $<INSTALL_INTERFACE:${NG_INSTALL_DIR_INCLUDE}/include>)
if(CHECK_RANGE)
if(CHECK_RANGE OR CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG")
target_compile_definitions(ngcore PUBLIC NETGEN_ENABLE_CHECK_RANGE)
endif(CHECK_RANGE)
endif(CHECK_RANGE OR CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG")
if(USE_SPDLOG)
include_directories(${SPDLOG_INCLUDE_DIR})

View File

@ -11,8 +11,9 @@ endif(NOT WIN32)
if(USE_GUI)
add_library(geom2dvis ${NG_LIB_TYPE} vsgeom2d.cpp)
target_link_libraries(geom2dvis PUBLIC ngcore)
if(NOT WIN32)
target_link_libraries(geom2dvis geom2d)
target_link_libraries(geom2dvis PUBLIC geom2d)
install( TARGETS geom2dvis ${NG_INSTALL_DIR})
endif(NOT WIN32)
endif(USE_GUI)

View File

@ -6,6 +6,7 @@ add_library(occ ${NG_LIB_TYPE}
)
if(USE_GUI)
add_library(occvis ${NG_LIB_TYPE} vsocc.cpp)
target_link_libraries(occvis PUBLIC ngcore)
endif(USE_GUI)
target_link_libraries(occ PUBLIC ngcore PRIVATE netgen_python)