Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use libmkl_rt, or statically link against MKL #31159

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions aten/tools/valgrind.sup
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@
fun:handle_ld_preload
...
}
{
<Dynamically loaded MKL uninitialized jump>
Memcheck:Cond
fun:__intel_sse2_strrchr
fun:*_INTERNAL_45_______src_thirdparty_tbb_omp_dynamic_link_cpp*init_dl_data*
fun:__sti__$E
}
2 changes: 1 addition & 1 deletion caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ if(USE_OPENMP AND OPENMP_FOUND)
"OpenMP CXX_FLAGS: ${OpenMP_CXX_FLAGS}. \n"
"OpenMP libraries: ${OpenMP_CXX_LIBRARIES}.")
target_compile_options(torch_cpu INTERFACE ${OpenMP_CXX_FLAGS})
target_link_libraries(torch_cpu PRIVATE ${OpenMP_CXX_LIBRARIES})
target_link_libraries(torch_cpu INTERFACE ${OpenMP_CXX_LIBRARIES})
endif()


Expand Down
21 changes: 18 additions & 3 deletions cmake/Modules/FindMKL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ SET(mklseq)
# Paths
SET(saved_CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH})
SET(saved_CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH})
SET(saved_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
IF(WIN32)
# Set default MKLRoot for Windows
IF($ENV{MKLProductDir})
Expand Down Expand Up @@ -197,7 +198,18 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES OPENMP_TYPE OPENMP_LIBRARY _name _list _flag
# Separately handling compiled TBB
SET(_found_tbb TRUE)
ELSE()
SET(MKL_SAVED_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
IF(${_library} MATCHES "mkl*")
# Unfortunately combinations of shared MKL libraries other than only libmkl_rt
# assume and _require_ loading them into the global symbol namespace, which
# generally causes a lot of pollution with common symbols like pthreads, etc.
# To avoid this we only allow either linking to libmkl_rt.so, or require all
# libraries to get statically linked.
# Relevant link: https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/296094
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a)
ENDIF()
FIND_LIBRARY(${_prefix}_${_library}_LIBRARY NAMES ${_library})
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${MKL_SAVED_LIBRARY_SUFFIXES})
ENDIF()
MARK_AS_ADVANCED(${_prefix}_${_library}_LIBRARY)
IF(NOT (${_library} STREQUAL "tbb"))
Expand Down Expand Up @@ -250,10 +262,12 @@ ELSE(UNIX AND NOT APPLE)
SET(mkl_dl "")
ENDIF(UNIX AND NOT APPLE)

# Check for version 10/11
SET(MKL_VERSION 1011)

FIND_LIBRARY(MKL_LIBRARIES mkl_rt)
IF (NOT MKL_LIBRARIES)
SET(MKL_VERSION 1011)
ENDIF (NOT MKL_LIBRARIES)
UNSET(MKL_LIBRARIES CACHE)
ENDIF()

# First: search for parallelized ones with intel thread lib
IF (NOT "${MKL_THREADING}" STREQUAL "SEQ")
Expand Down Expand Up @@ -336,6 +350,7 @@ ENDIF (MKL_LIBRARIES)
# Final
SET(CMAKE_LIBRARY_PATH ${saved_CMAKE_LIBRARY_PATH})
SET(CMAKE_INCLUDE_PATH ${saved_CMAKE_INCLUDE_PATH})
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${saved_CMAKE_FIND_LIBRARY_SUFFIXES})
IF (MKL_LIBRARIES AND MKL_INCLUDE_DIR)
SET(MKL_FOUND TRUE)
ELSE (MKL_LIBRARIES AND MKL_INCLUDE_DIR)
Expand Down