Fix MSVC openmp flag (#18973)
* Fix MSVC openmp flag
diff --git a/tensorflow/contrib/cmake/CMakeLists.txt b/tensorflow/contrib/cmake/CMakeLists.txt
index d81f6a0..0708d6b 100644
--- a/tensorflow/contrib/cmake/CMakeLists.txt
+++ b/tensorflow/contrib/cmake/CMakeLists.txt
@@ -172,19 +172,20 @@
endif()
endif()
+include(CheckCXXCompilerFlag)
+
+# OpenMP Support
+CHECK_CXX_COMPILER_FLAG("-fopenmp" GCC_OPENMP_SUPPORT)
+if (GCC_OPENMP_SUPPORT)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
+endif()
+CHECK_CXX_COMPILER_FLAG("/openmp" MSVC_OPENMP_SUPPORT)
+if (MSVC_OPENMP_SUPPORT)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
+endif()
+
# MSVC SIMD instructions
if (tensorflow_WIN_CPU_SIMD_OPTIONS)
- include(CheckCXXCompilerFlag)
- if (tensorflow_ENABLE_MKL_SUPPORT)
- add_definitions(-DINTEL_MKL -DEIGEN_USE_VML)
- if (NOT tensorflow_ENABLE_MKLDNN_SUPPORT)
- add_definitions(-DINTEL_MKL_ML)
- endif()
- endif()
- CHECK_CXX_COMPILER_FLAG("-fopenmp" COMPILER_OPT_OPENMP_SUPPORT)
- if (COMPILER_OPT_OPENMP_SUPPORT)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
- endif()
if (WIN32)
CHECK_CXX_COMPILER_FLAG(${tensorflow_WIN_CPU_SIMD_OPTIONS} COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED)
if(COMPILER_OPT_WIN_CPU_SIMD_SUPPORTED)
@@ -323,7 +324,9 @@
list(APPEND tensorflow_EXTERNAL_LIBRARIES network)
endif()
+# MKL Support
if (tensorflow_ENABLE_MKL_SUPPORT)
+ add_definitions(-DINTEL_MKL -DEIGEN_USE_VML)
if (WIN32)
find_path(MKL_HOME_PLATFORM mkl
PATHS ${MKL_HOME} ${MKL_HOME}/../ ${MKL_HOME}/../../
@@ -359,6 +362,8 @@
list(APPEND tensorflow_EXTERNAL_LIBRARIES ${mkldnn_STATIC_LIBRARIES})
list(APPEND tensorflow_EXTERNAL_DEPENDENCIES mkldnn)
include_directories(${mkldnn_INCLUDE_DIRS})
+ else (tensorflow_ENABLE_MKLDNN_SUPPORT)
+ add_definitions(-DINTEL_MKL_ML)
endif()
endif (tensorflow_ENABLE_MKL_SUPPORT)