From fd945075e2075a467675ca808e954a4872b78b0f Mon Sep 17 00:00:00 2001 From: zhongpu <2013000149@qq.com> Date: Thu, 27 Feb 2020 16:27:18 +0800 Subject: [PATCH] fix compile issue, test=develop (#22001) (#22775) * fix compile issue, test=develop * force link libiomp5 when mklml is enabled, test=develop Co-authored-by: Leo Chen --- cmake/external/mkldnn.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmake/external/mkldnn.cmake b/cmake/external/mkldnn.cmake index 761b8d87b22..aa0f61e75c0 100644 --- a/cmake/external/mkldnn.cmake +++ b/cmake/external/mkldnn.cmake @@ -36,11 +36,28 @@ SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLDNN_INSTALL_DIR}/${LIBDIR INCLUDE_DIRECTORIES(${MKLDNN_INC_DIR}) # For MKLDNN code to include internal headers. +IF(${CBLAS_PROVIDER} STREQUAL "MKLML") + SET(MKLDNN_DEPENDS ${MKLML_PROJECT}) + MESSAGE(STATUS "Build MKLDNN with MKLML ${MKLML_ROOT}") +ELSE() + MESSAGE(STATUS "Build MKLDNN without MKLML") +ENDIF() + IF(NOT WIN32) SET(MKLDNN_FLAG "-Wno-error=strict-overflow -Wno-error=unused-result -Wno-error=array-bounds") SET(MKLDNN_FLAG "${MKLDNN_FLAG} -Wno-unused-result -Wno-unused-value") SET(MKLDNN_CFLAG "${CMAKE_C_FLAGS} ${MKLDNN_FLAG}") SET(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} ${MKLDNN_FLAG}") + + IF(${CBLAS_PROVIDER} STREQUAL "MKLML") + # Force libmkldnn.so to link libiomp5.so (provided by intel mkl) instead of libgomp.so (provided by gcc), + # since core_avx.so links libiomp5.so + set(MKLDNN_SHARED_LINKER_FLAG "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed -L${MKLML_LIB_DIR} -liomp5") + set(FORBID "-fopenmp") + ELSE() + set(MKLDNN_SHARED_LINKER_FLAG "${CMAKE_SHARED_LINKER_FLAGS}") + set(FORBID "") + ENDIF() ELSE() SET(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} /EHsc") ENDIF(NOT WIN32) @@ -74,6 +91,8 @@ ExternalProject_Add( -DCMAKE_C_FLAGS=${MKLDNN_CFLAG} -DCMAKE_CXX_FLAGS=${MKLDNN_CXXFLAG} -DDNNL_BUILD_TESTS=OFF -DDNNL_BUILD_EXAMPLES=OFF + -DCMAKE_SHARED_LINKER_FLAGS=${MKLDNN_SHARED_LINKER_FLAG} + -DCMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS=${FORBID} CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR} ) if(WIN32) -- GitLab