Skip to content

Commit fd94507

Browse files
JepsonWongzhiqiu
andauthored
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 <[email protected]>
1 parent 2fe032a commit fd94507

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

cmake/external/mkldnn.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,28 @@ SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MKLDNN_INSTALL_DIR}/${LIBDIR
3636

3737
INCLUDE_DIRECTORIES(${MKLDNN_INC_DIR}) # For MKLDNN code to include internal headers.
3838

39+
IF(${CBLAS_PROVIDER} STREQUAL "MKLML")
40+
SET(MKLDNN_DEPENDS ${MKLML_PROJECT})
41+
MESSAGE(STATUS "Build MKLDNN with MKLML ${MKLML_ROOT}")
42+
ELSE()
43+
MESSAGE(STATUS "Build MKLDNN without MKLML")
44+
ENDIF()
45+
3946
IF(NOT WIN32)
4047
SET(MKLDNN_FLAG "-Wno-error=strict-overflow -Wno-error=unused-result -Wno-error=array-bounds")
4148
SET(MKLDNN_FLAG "${MKLDNN_FLAG} -Wno-unused-result -Wno-unused-value")
4249
SET(MKLDNN_CFLAG "${CMAKE_C_FLAGS} ${MKLDNN_FLAG}")
4350
SET(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} ${MKLDNN_FLAG}")
51+
52+
IF(${CBLAS_PROVIDER} STREQUAL "MKLML")
53+
# Force libmkldnn.so to link libiomp5.so (provided by intel mkl) instead of libgomp.so (provided by gcc),
54+
# since core_avx.so links libiomp5.so
55+
set(MKLDNN_SHARED_LINKER_FLAG "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed -L${MKLML_LIB_DIR} -liomp5")
56+
set(FORBID "-fopenmp")
57+
ELSE()
58+
set(MKLDNN_SHARED_LINKER_FLAG "${CMAKE_SHARED_LINKER_FLAGS}")
59+
set(FORBID "")
60+
ENDIF()
4461
ELSE()
4562
SET(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} /EHsc")
4663
ENDIF(NOT WIN32)
@@ -74,6 +91,8 @@ ExternalProject_Add(
7491
-DCMAKE_C_FLAGS=${MKLDNN_CFLAG}
7592
-DCMAKE_CXX_FLAGS=${MKLDNN_CXXFLAG}
7693
-DDNNL_BUILD_TESTS=OFF -DDNNL_BUILD_EXAMPLES=OFF
94+
-DCMAKE_SHARED_LINKER_FLAGS=${MKLDNN_SHARED_LINKER_FLAG}
95+
-DCMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS=${FORBID}
7796
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR}
7897
)
7998
if(WIN32)

0 commit comments

Comments
 (0)