From 1aba9998f11c9ecdab79925c3706cf92e9be3d7d Mon Sep 17 00:00:00 2001 From: Soumith Chintala Date: Tue, 18 Jul 2017 03:58:01 +0000 Subject: static MKL detection and linkage fixes --- lib/TH/CMakeLists.txt | 8 +++++++- lib/TH/cmake/FindMKL.cmake | 27 ++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/TH/CMakeLists.txt b/lib/TH/CMakeLists.txt index dd0b75d..c9be21a 100644 --- a/lib/TH/CMakeLists.txt +++ b/lib/TH/CMakeLists.txt @@ -303,7 +303,13 @@ ENDIF() FIND_PACKAGE(BLAS) IF(BLAS_FOUND) SET(USE_BLAS 1) - TARGET_LINK_LIBRARIES(TH ${BLAS_LIBRARIES}) + IF ($ENV{TH_BINARY_BUILD}) + MESSAGE(STATUS "TH_BINARY_BUILD detected. Enabling special linkage.") + TARGET_LINK_LIBRARIES(TH "${BLAS_LIBRARIES};${BLAS_LIBRARIES};${BLAS_LIBRARIES}") + ELSE ($ENV{TH_BINARY_BUILD}) + TARGET_LINK_LIBRARIES(TH ${BLAS_LIBRARIES}) + ENDIF ($ENV{TH_BINARY_BUILD}) + IF(BLAS_INFO STREQUAL "mkl") ADD_DEFINITIONS(-DTH_BLAS_MKL) ENDIF() diff --git a/lib/TH/cmake/FindMKL.cmake b/lib/TH/cmake/FindMKL.cmake index 7c9325a..88f0aa3 100644 --- a/lib/TH/cmake/FindMKL.cmake +++ b/lib/TH/cmake/FindMKL.cmake @@ -50,7 +50,7 @@ ENDIF ("${SIZE_OF_VOIDP}" EQUAL 8) IF(CMAKE_COMPILER_IS_GNUCC) SET(mklthreads "mkl_gnu_thread" "mkl_intel_thread") SET(mklifaces "gf" "intel") - SET(mklrtls "iomp5") + SET(mklrtls "gomp" "iomp5") ELSE(CMAKE_COMPILER_IS_GNUCC) SET(mklthreads "mkl_intel_thread") SET(mklifaces "intel") @@ -92,7 +92,7 @@ ENDIF (INTEL_MKL_DIR) # Try linking multiple libs MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags) # This macro checks for the existence of the combination of libraries given by _list. - # If the combination is found, this macro whether we can link against that library + # If the combination is found, this macro checks whether we can link against that library # combination using the name of a routine given by _name using the linker # flags given by _flags. If the combination of libraries is found and passes # the link test, LIBRARIES is set to the list of complete library paths that @@ -116,8 +116,15 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags) message(STATUS "Checking for [${__list}]") FOREACH(_library ${_list}) SET(_combined_name ${_combined_name}_${_library}) - IF(_libraries_work) - FIND_LIBRARY(${_prefix}_${_library}_LIBRARY NAMES ${_library}) + IF(_libraries_work) + IF(${_library} STREQUAL "gomp") + FIND_PACKAGE(OpenMP) + IF(OPENMP_FOUND) + SET(${_prefix}_${_library}_LIBRARY ${OpenMP_C_FLAGS}) + ENDIF(OPENMP_FOUND) + ELSE(${_library} STREQUAL "gomp") + FIND_LIBRARY(${_prefix}_${_library}_LIBRARY NAMES ${_library}) + ENDIF(${_library} STREQUAL "gomp") MARK_AS_ADVANCED(${_prefix}_${_library}_LIBRARY) SET(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) SET(_libraries_work ${${_prefix}_${_library}_LIBRARY}) @@ -131,6 +138,7 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags) # Test this combination of libraries. IF(_libraries_work) SET(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}}) + SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${CMAKE_REQUIRED_LIBRARIES}") CHECK_FUNCTION_EXISTS(${_name} ${_prefix}${_combined_name}_WORKS) SET(CMAKE_REQUIRED_LIBRARIES) MARK_AS_ADVANCED(${_prefix}${_combined_name}_WORKS) @@ -150,6 +158,11 @@ else(WIN32) set(mkl_m "m") endif(WIN32) +if(UNIX AND NOT APPLE) + set(mkl_dl "${CMAKE_DL_LIBS}") +else(UNIX AND NOT APPLE) + set(mkl_dl "") +endif(UNIX AND NOT APPLE) # Check for version 10/11 IF (NOT MKL_LIBRARIES) @@ -161,7 +174,7 @@ FOREACH(mklrtl ${mklrtls} "") FOREACH(mklthread ${mklthreads}) IF (NOT MKL_LIBRARIES AND NOT INTEL_MKL_SEQUENTIAL) CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm - "mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m}" "") + "mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m};${mkl_dl}" "") ENDIF (NOT MKL_LIBRARIES AND NOT INTEL_MKL_SEQUENTIAL) ENDFOREACH(mklthread) ENDFOREACH(mkl64) @@ -172,7 +185,7 @@ FOREACH(mklrtl ${mklrtls} "") FOREACH(mkl64 ${mkl64s} "") IF (NOT MKL_LIBRARIES) CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm - "mkl_${mkliface}${mkl64};mkl_sequential;mkl_core;${mkl_m}" "") + "mkl_${mkliface}${mkl64};mkl_sequential;mkl_core;${mkl_m};${mkl_dl}" "") IF (MKL_LIBRARIES) SET(mklseq "_sequential") ENDIF (MKL_LIBRARIES) @@ -186,7 +199,7 @@ FOREACH(mklrtl ${mklrtls} "") FOREACH(mklthread ${mklthreads}) IF (NOT MKL_LIBRARIES) CHECK_ALL_LIBRARIES(MKL_LIBRARIES cblas_sgemm - "mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m}" "") + "mkl_${mkliface}${mkl64};${mklthread};mkl_core;${mklrtl};pthread;${mkl_m};${mkl_dl}" "") ENDIF (NOT MKL_LIBRARIES) ENDFOREACH(mklthread) ENDFOREACH(mkl64) -- cgit v1.2.3