mirror of https://github.com/davisking/dlib.git
Fixed bad results when using CUDA and the Intel MKL at the same time. This
was because of a bug introduced yesterday in the CMake scripts which would accidentally pull in two versions of the OpenMP libraries, the GNU one and the Intel one, but you can't mix them together at the same time.
This commit is contained in:
parent
5b7b8bcda1
commit
327de62cc2
|
@ -573,14 +573,27 @@ if (NOT TARGET dlib)
|
|||
# bother to look for it.
|
||||
get_filename_component(cuda_blas_path "${CUDA_CUBLAS_LIBRARIES}" DIRECTORY)
|
||||
find_library(cusolver cusolver HINTS ${cuda_blas_path})
|
||||
# Also find OpenMP since cuSOLVER needs it.
|
||||
find_package(OpenMP)
|
||||
if (NOT OPENMP_FOUND)
|
||||
message(STATUS "*** Didn't find OpenMP, which is required to use CUDA. ***")
|
||||
mark_as_advanced(cusolver)
|
||||
# Also find OpenMP since cuSOLVER needs it. Importantly, we only
|
||||
# look for one to link to if our use of BLAS, specifically the
|
||||
# Intel MKL, hasn't already decided what to use. This is because
|
||||
# it makes the MKL bug out if you link to another openmp lib other
|
||||
# than Intel's when you use the MKL.
|
||||
if (NOT openmp_libarires)
|
||||
if (MSVC)
|
||||
set(openmp_libarires "")
|
||||
else()
|
||||
find_package(OpenMP)
|
||||
if (OPENMP_FOUND)
|
||||
set(openmp_libarires ${OpenMP_CXX_FLAGS})
|
||||
else()
|
||||
message(STATUS "*** Didn't find OpenMP, which is required to use CUDA. ***")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (CUDA_FOUND AND cudnn AND cudnn_include AND COMPILER_CAN_DO_CPP_11 AND cuda_test_compile_worked AND cudnn_test_compile_worked AND OPENMP_FOUND)
|
||||
if (CUDA_FOUND AND cudnn AND cudnn_include AND COMPILER_CAN_DO_CPP_11 AND cuda_test_compile_worked AND cudnn_test_compile_worked AND openmp_libarires)
|
||||
set(source_files ${source_files}
|
||||
dnn/cuda_dlib.cu
|
||||
dnn/cudnn_dlibapi.cpp
|
||||
|
@ -595,6 +608,7 @@ if (NOT TARGET dlib)
|
|||
${cudnn}
|
||||
${CUDA_curand_LIBRARY}
|
||||
${cusolver}
|
||||
${openmp_libarires}
|
||||
)
|
||||
include_directories(${cudnn_include})
|
||||
else()
|
||||
|
@ -659,13 +673,6 @@ if (NOT TARGET dlib)
|
|||
PUBLIC ${dlib_needed_includes}
|
||||
)
|
||||
target_link_libraries(dlib PRIVATE ${dlib_needed_libraries})
|
||||
if (OPENMP_FOUND)
|
||||
# Enable OpenMP
|
||||
target_compile_options(dlib PUBLIC ${OpenMP_CXX_FLAGS})
|
||||
if (NOT MSVC)
|
||||
target_link_libraries(dlib PUBLIC ${OpenMP_CXX_FLAGS})
|
||||
endif()
|
||||
endif()
|
||||
if (UNIX AND NOT DLIB_IN_PROJECT_BUILD)
|
||||
if (DLIB_USE_CUDA)
|
||||
cuda_add_library(dlib_shared SHARED ${source_files} )
|
||||
|
@ -680,13 +687,6 @@ if (NOT TARGET dlib)
|
|||
PUBLIC ${dlib_needed_includes}
|
||||
)
|
||||
target_link_libraries(dlib_shared PRIVATE ${dlib_needed_libraries})
|
||||
if (OPENMP_FOUND)
|
||||
# Enable OpenMP
|
||||
target_compile_options(dlib_shared PUBLIC ${OpenMP_CXX_FLAGS})
|
||||
if (NOT MSVC)
|
||||
target_link_libraries(dlib_shared PUBLIC ${OpenMP_CXX_FLAGS})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
# lapack_libraries - link against these to use LAPACK library
|
||||
# mkl_libraries - link against these to use the MKL library
|
||||
# mkl_include_dir - add to the include path to use the MKL library
|
||||
# openmp_libarires - Set to Intel's OpenMP library if and only if we
|
||||
# find the MKL.
|
||||
|
||||
# setting this makes CMake allow normal looking if else statements
|
||||
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
||||
|
@ -91,11 +93,13 @@ if (UNIX OR MINGW)
|
|||
/opt/intel/include
|
||||
)
|
||||
find_path(mkl_include_dir mkl_version.h ${mkl_include_search_path})
|
||||
mark_as_advanced(mkl_include_dir)
|
||||
|
||||
# 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})
|
||||
mark_as_advanced( mkl_rt )
|
||||
find_library(openmp_libarires iomp5 ${mkl_search_path})
|
||||
mark_as_advanced( mkl_rt openmp_libarires )
|
||||
# if we found the MKL
|
||||
if ( mkl_rt)
|
||||
set(mkl_libraries ${mkl_rt} )
|
||||
|
|
Loading…
Reference in New Issue