Commit 327de62c authored by Davis King's avatar Davis King

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.
parent 5b7b8bcd
...@@ -573,14 +573,27 @@ if (NOT TARGET dlib) ...@@ -573,14 +573,27 @@ if (NOT TARGET dlib)
# bother to look for it. # bother to look for it.
get_filename_component(cuda_blas_path "${CUDA_CUBLAS_LIBRARIES}" DIRECTORY) get_filename_component(cuda_blas_path "${CUDA_CUBLAS_LIBRARIES}" DIRECTORY)
find_library(cusolver cusolver HINTS ${cuda_blas_path}) find_library(cusolver cusolver HINTS ${cuda_blas_path})
# Also find OpenMP since cuSOLVER needs it. mark_as_advanced(cusolver)
find_package(OpenMP) # Also find OpenMP since cuSOLVER needs it. Importantly, we only
if (NOT OPENMP_FOUND) # look for one to link to if our use of BLAS, specifically the
message(STATUS "*** Didn't find OpenMP, which is required to use CUDA. ***") # 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()
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} set(source_files ${source_files}
dnn/cuda_dlib.cu dnn/cuda_dlib.cu
dnn/cudnn_dlibapi.cpp dnn/cudnn_dlibapi.cpp
...@@ -595,6 +608,7 @@ if (NOT TARGET dlib) ...@@ -595,6 +608,7 @@ if (NOT TARGET dlib)
${cudnn} ${cudnn}
${CUDA_curand_LIBRARY} ${CUDA_curand_LIBRARY}
${cusolver} ${cusolver}
${openmp_libarires}
) )
include_directories(${cudnn_include}) include_directories(${cudnn_include})
else() else()
...@@ -659,13 +673,6 @@ if (NOT TARGET dlib) ...@@ -659,13 +673,6 @@ if (NOT TARGET dlib)
PUBLIC ${dlib_needed_includes} PUBLIC ${dlib_needed_includes}
) )
target_link_libraries(dlib PRIVATE ${dlib_needed_libraries}) 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 (UNIX AND NOT DLIB_IN_PROJECT_BUILD)
if (DLIB_USE_CUDA) if (DLIB_USE_CUDA)
cuda_add_library(dlib_shared SHARED ${source_files} ) cuda_add_library(dlib_shared SHARED ${source_files} )
...@@ -680,13 +687,6 @@ if (NOT TARGET dlib) ...@@ -680,13 +687,6 @@ if (NOT TARGET dlib)
PUBLIC ${dlib_needed_includes} PUBLIC ${dlib_needed_includes}
) )
target_link_libraries(dlib_shared PRIVATE ${dlib_needed_libraries}) 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()
endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ########################################################## endif () ##### end of if NOT DLIB_ISO_CPP_ONLY ##########################################################
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
# lapack_libraries - link against these to use LAPACK library # lapack_libraries - link against these to use LAPACK library
# mkl_libraries - link against these to use the MKL library # mkl_libraries - link against these to use the MKL library
# mkl_include_dir - add to the include path 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 # setting this makes CMake allow normal looking if else statements
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
...@@ -91,11 +93,13 @@ if (UNIX OR MINGW) ...@@ -91,11 +93,13 @@ if (UNIX OR MINGW)
/opt/intel/include /opt/intel/include
) )
find_path(mkl_include_dir mkl_version.h ${mkl_include_search_path}) 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 # 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. # file first since this way avoids linking bugs in some cases.
find_library(mkl_rt mkl_rt ${mkl_search_path}) 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 we found the MKL
if ( mkl_rt) if ( mkl_rt)
set(mkl_libraries ${mkl_rt} ) set(mkl_libraries ${mkl_rt} )
......
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