Commit 165d1e35 authored by Facundo Galán's avatar Facundo Galán Committed by Davis E. King

Add MKL with TBB support to CMake (#1561)

* Add DLIB_USE_MKL_WITH_TBB opcion to CMake for Windows.

* Add to CMake MKL with TBB support for Linux

* Remove unnecessary tbb includes from CMake.

* Add back white spaces.
parent 3e9d361f
......@@ -167,6 +167,8 @@ if (NOT TARGET dlib)
"Disable this if you don't want to use NVIDIA CUDA" )
set (DLIB_USE_MKL_SEQUENTIAL_STR
"Enable this if you have MKL installed and want to use the sequential version instead of the multi-core version." )
set (DLIB_USE_MKL_WITH_TBB_STR
"Enable this if you have MKL installed and want to use the tbb version instead of the openmp version." )
set (DLIB_PNG_SUPPORT_STR
"Disable this if you don't want to link against libpng" )
set (DLIB_GIF_SUPPORT_STR
......@@ -190,6 +192,7 @@ if (NOT TARGET dlib)
option(DLIB_ENABLE_STACK_TRACE ${DLIB_ENABLE_STACK_TRACE_STR} OFF)
toggle_preprocessor_switch(DLIB_ENABLE_STACK_TRACE)
option(DLIB_USE_MKL_SEQUENTIAL ${DLIB_USE_MKL_SEQUENTIAL_STR} OFF)
option(DLIB_USE_MKL_WITH_TBB ${DLIB_USE_MKL_WITH_TBB_STR} OFF)
if(DLIB_ENABLE_ASSERTS)
# Set these variables so they are set in the config.h.in file when dlib
......@@ -566,6 +569,13 @@ if (NOT TARGET dlib)
if (DLIB_USE_BLAS OR DLIB_USE_LAPACK OR DLIB_USE_MKL_FFT)
if (DLIB_USE_MKL_WITH_TBB AND DLIB_USE_MKL_SEQUENTIAL)
set(DLIB_USE_MKL_SEQUENTIAL OFF CACHE STRING ${DLIB_USE_MKL_SEQUENTIAL_STR} FORCE )
toggle_preprocessor_switch(DLIB_USE_MKL_SEQUENTIAL)
message(STATUS "Disabling DLIB_USE_MKL_SEQUENTIAL. It cannot be used simultaneously with DLIB_USE_MKL_WITH_TBB.")
endif()
# Try to find BLAS, LAPACK and MKL
include(cmake_utils/find_blas.cmake)
......@@ -943,4 +953,4 @@ if (COMMAND pybind11_add_module)
set_target_properties(dlib PROPERTIES CUDA_VISIBILITY_PRESET "hidden")
endif()
add_library(dlib::dlib ALIAS dlib)
add_library(dlib::dlib ALIAS dlib)
\ No newline at end of file
......@@ -85,6 +85,9 @@ if (UNIX OR MINGW)
/opt/intel/mkl/lib/intel64
/opt/intel/lib/intel64
/opt/intel/mkl/lib
/opt/intel/tbb/*/lib/em64t/gcc4.7
/opt/intel/tbb/lib/intel64/gcc4.7
/opt/intel/tbb/lib/gcc4.7
)
find_library(mkl_intel mkl_intel_lp64 ${mkl_search_path})
......@@ -94,6 +97,8 @@ if (UNIX OR MINGW)
/opt/intel/mkl/*/lib/32
/opt/intel/mkl/lib/ia32
/opt/intel/lib/ia32
/opt/intel/tbb/*/lib/32/gcc4.7
/opt/intel/tbb/lib/ia32/gcc4.7
)
find_library(mkl_intel mkl_intel ${mkl_search_path})
......@@ -110,7 +115,7 @@ if (UNIX OR MINGW)
find_path(mkl_include_dir mkl_version.h ${mkl_include_search_path})
mark_as_advanced(mkl_include_dir)
if(NOT DLIB_USE_MKL_SEQUENTIAL)
if(NOT DLIB_USE_MKL_SEQUENTIAL AND NOT DLIB_USE_MKL_WITH_TBB)
# Search for the needed libraries from the MKL. We will try to link against the mkl_rt
# file first since this way avoids linking bugs in some cases.
find_library(mkl_rt mkl_rt ${mkl_search_path})
......@@ -135,7 +140,13 @@ if (UNIX OR MINGW)
find_library(mkl_core mkl_core ${mkl_search_path})
set(mkl_libs ${mkl_intel} ${mkl_core})
mark_as_advanced(mkl_libs mkl_intel mkl_core)
if (DLIB_USE_MKL_SEQUENTIAL)
if (DLIB_USE_MKL_WITH_TBB)
find_library(mkl_tbb_thread mkl_tbb_thread ${mkl_search_path})
find_library(mkl_tbb tbb ${mkl_search_path})
mark_as_advanced(mkl_tbb_thread mkl_tbb)
list(APPEND mkl_libs ${mkl_tbb_thread} ${mkl_tbb})
elseif (DLIB_USE_MKL_SEQUENTIAL)
find_library(mkl_sequential mkl_sequential ${mkl_search_path})
mark_as_advanced(mkl_sequential)
list(APPEND mkl_libs ${mkl_sequential})
......@@ -148,7 +159,7 @@ if (UNIX OR MINGW)
endif()
# If we found the MKL
if (mkl_intel AND mkl_core AND ((mkl_thread AND mkl_iomp AND mkl_pthread) OR mkl_sequential))
if (mkl_intel AND mkl_core AND ((mkl_tbb_thread AND mkl_tbb) OR (mkl_thread AND mkl_iomp AND mkl_pthread) OR mkl_sequential))
set(mkl_libraries ${mkl_libs})
set(blas_libraries ${mkl_libs})
set(lapack_libraries ${mkl_libs})
......@@ -287,24 +298,32 @@ elseif(WIN32 AND NOT MINGW)
if (SIZE_OF_VOID_PTR EQUAL 8)
set( mkl_search_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/mkl/lib/intel64"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/tbb/lib/intel64/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/compiler/lib/intel64"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/lib/intel64"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/lib/intel64"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/tbb/lib/intel64/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/lib/intel64"
"C:/Program Files (x86)/Intel/Composer XE/mkl/lib/intel64"
"C:/Program Files (x86)/Intel/Composer XE/tbb/lib/intel64/vc14"
"C:/Program Files (x86)/Intel/Composer XE/compiler/lib/intel64"
"C:/Program Files/Intel/Composer XE/mkl/lib/intel64"
"C:/Program Files/Intel/Composer XE/tbb/lib/intel64/vc14"
"C:/Program Files/Intel/Composer XE/compiler/lib/intel64"
)
find_library(mkl_intel mkl_intel_lp64 ${mkl_search_path})
else()
set( mkl_search_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/mkl/lib/ia32"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/tbb/lib/ia32/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/compiler/lib/ia32"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/lib/ia32"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/tbb/lib/ia32/vc14"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/lib/ia32"
"C:/Program Files (x86)/Intel/Composer XE/mkl/lib/ia32"
"C:/Program Files (x86)/Intel/Composer XE/tbb/lib/ia32/vc14"
"C:/Program Files (x86)/Intel/Composer XE/compiler/lib/ia32"
"C:/Program Files/Intel/Composer XE/mkl/lib/ia32"
"C:/Program Files/Intel/Composer XE/tbb/lib/ia32/vc14"
"C:/Program Files/Intel/Composer XE/compiler/lib/ia32"
)
find_library(mkl_intel mkl_intel_c ${mkl_search_path})
......@@ -316,8 +335,8 @@ elseif(WIN32 AND NOT MINGW)
set(mkl_include_search_path
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/mkl/include"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_*/windows/compiler/include"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/include"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/mkl/include"
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries/windows/compiler/include"
"C:/Program Files (x86)/Intel/Composer XE/mkl/include"
"C:/Program Files (x86)/Intel/Composer XE/compiler/include"
"C:/Program Files/Intel/Composer XE/mkl/include"
......@@ -330,10 +349,15 @@ elseif(WIN32 AND NOT MINGW)
find_library(mkl_core mkl_core ${mkl_search_path})
set(mkl_libs ${mkl_intel} ${mkl_core})
mark_as_advanced(mkl_libs mkl_intel mkl_core)
if (DLIB_USE_MKL_SEQUENTIAL)
find_library(mkl_sequential mkl_sequential ${mkl_search_path})
mark_as_advanced(mkl_sequential)
list(APPEND mkl_libs ${mkl_sequential})
if (DLIB_USE_MKL_WITH_TBB)
find_library(mkl_tbb_thread mkl_tbb_thread ${mkl_search_path})
find_library(mkl_tbb tbb ${mkl_search_path})
mark_as_advanced(mkl_tbb_thread mkl_tbb)
list(APPEND mkl_libs ${mkl_tbb_thread} ${mkl_tbb})
elseif (DLIB_USE_MKL_SEQUENTIAL)
find_library(mkl_sequential mkl_sequential ${mkl_search_path})
mark_as_advanced(mkl_sequential)
list(APPEND mkl_libs ${mkl_sequential})
else()
find_library(mkl_thread mkl_intel_thread ${mkl_search_path})
find_library(mkl_iomp libiomp5md ${mkl_search_path})
......@@ -342,7 +366,7 @@ elseif(WIN32 AND NOT MINGW)
endif()
# If we found the MKL
if (mkl_intel AND mkl_core AND ((mkl_thread AND mkl_iomp) OR mkl_sequential))
if (mkl_intel AND mkl_core AND ((mkl_tbb_thread AND mkl_tbb) OR mkl_sequential OR (mkl_thread AND mkl_iomp)))
set(blas_libraries ${mkl_libs})
set(lapack_libraries ${mkl_libs})
set(blas_found 1)
......@@ -420,4 +444,3 @@ if (UNIX OR MINGW)
message(" *****************************************************************************")
endif()
endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment