Merge pull request #14660 from YashasSamaga:dnn-cuda-build
add cuDNN dependency and setup build for cuda4dnn (#14660) * update cmake for cuda4dnn - Adds FindCUDNN - Adds new options: * WITH_CUDA * OPENCV_DNN_CUDA - Adds CUDA4DNN preprocessor symbol for the DNN module * FIX: append EXCLUDE_CUDA instead of overwrite * remove cuDNN dependency for user apps * fix unused variable warningpull/14696/head
parent
3ccb1d67c2
commit
ae279966c2
13 changed files with 228 additions and 11 deletions
@ -0,0 +1,105 @@ |
|||||||
|
# template taken from https://cmake.org/cmake/help/v3.14/manual/cmake-developer.7.html |
||||||
|
|
||||||
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
||||||
|
# file Copyright.txt or https://cmake.org/licensing for details. |
||||||
|
|
||||||
|
#[=======================================================================[.rst: |
||||||
|
FindCUDNN |
||||||
|
--------- |
||||||
|
|
||||||
|
Finds the cuDNN library. |
||||||
|
|
||||||
|
Requires: |
||||||
|
^^^^^^^^^ |
||||||
|
|
||||||
|
find_cuda_helper_libs from FindCUDA.cmake |
||||||
|
i.e. CUDA module should be found using FindCUDA.cmake before attempting to find cuDNN |
||||||
|
|
||||||
|
Result Variables |
||||||
|
^^^^^^^^^^^^^^^^ |
||||||
|
|
||||||
|
This will define the following variables: |
||||||
|
|
||||||
|
``CUDNN_FOUND`` |
||||||
|
``CUDNN_INCLUDE_DIRS`` location of cudnn.h |
||||||
|
``CUDNN_LIBRARIES`` location of cudnn library |
||||||
|
|
||||||
|
Cache Variables |
||||||
|
^^^^^^^^^^^^^^^ |
||||||
|
|
||||||
|
The following cache variables will be set if cuDNN was found. They may also be set on failure. |
||||||
|
|
||||||
|
``CUDNN_LIBRARY`` |
||||||
|
``CUDNN_INCLUDE_DIR`` |
||||||
|
``CUDNN_VERSION`` |
||||||
|
|
||||||
|
``CUDNN_VERSION_MAJOR`` INTERNAL |
||||||
|
``CUDNN_VERSION_MINOR`` INTERNAL |
||||||
|
``CUDNN_VERSION_PATCH`` INTERNAL |
||||||
|
|
||||||
|
#]=======================================================================] |
||||||
|
|
||||||
|
# find the library |
||||||
|
if(CUDA_FOUND) |
||||||
|
find_cuda_helper_libs(cudnn) |
||||||
|
set(CUDNN_LIBRARY ${CUDA_cudnn_LIBRARY} CACHE FILEPATH "location of the cuDNN library") |
||||||
|
unset(CUDA_cudnn_LIBRARY CACHE) |
||||||
|
endif() |
||||||
|
|
||||||
|
# find the include |
||||||
|
if(CUDNN_LIBRARY) |
||||||
|
find_path(CUDNN_INCLUDE_DIR |
||||||
|
cudnn.h |
||||||
|
PATHS ${CUDA_TOOLKIT_INCLUDE} |
||||||
|
DOC "location of cudnn.h" |
||||||
|
NO_DEFAULT_PATH |
||||||
|
) |
||||||
|
|
||||||
|
if(NOT CUDNN_INCLUDE_DIR) |
||||||
|
find_path(CUDNN_INCLUDE_DIR |
||||||
|
cudnn.h |
||||||
|
DOC "location of cudnn.h" |
||||||
|
) |
||||||
|
endif() |
||||||
|
endif() |
||||||
|
|
||||||
|
# extract version from the include |
||||||
|
if(CUDNN_INCLUDE_DIR) |
||||||
|
file(READ "${CUDNN_INCLUDE_DIR}/cudnn.h" CUDNN_H_CONTENTS) |
||||||
|
|
||||||
|
string(REGEX MATCH "define CUDNN_MAJOR ([0-9]+)" _ "${CUDNN_H_CONTENTS}") |
||||||
|
set(CUDNN_MAJOR_VERSION ${CMAKE_MATCH_1} CACHE INTERNAL "") |
||||||
|
string(REGEX MATCH "define CUDNN_MINOR ([0-9]+)" _ "${CUDNN_H_CONTENTS}") |
||||||
|
set(CUDNN_MINOR_VERSION ${CMAKE_MATCH_1} CACHE INTERNAL "") |
||||||
|
string(REGEX MATCH "define CUDNN_PATCHLEVEL ([0-9]+)" _ "${CUDNN_H_CONTENTS}") |
||||||
|
set(CUDNN_PATCH_VERSION ${CMAKE_MATCH_1} CACHE INTERNAL "") |
||||||
|
|
||||||
|
set(CUDNN_VERSION |
||||||
|
"${CUDNN_MAJOR_VERSION}.${CUDNN_MINOR_VERSION}.${CUDNN_PATCH_VERSION}" |
||||||
|
CACHE |
||||||
|
STRING |
||||||
|
"cuDNN version" |
||||||
|
) |
||||||
|
|
||||||
|
unset(CUDNN_H_CONTENTS) |
||||||
|
endif() |
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs) |
||||||
|
find_package_handle_standard_args(CUDNN |
||||||
|
FOUND_VAR CUDNN_FOUND |
||||||
|
REQUIRED_VARS |
||||||
|
CUDNN_LIBRARY |
||||||
|
CUDNN_INCLUDE_DIR |
||||||
|
VERSION_VAR CUDNN_VERSION |
||||||
|
) |
||||||
|
|
||||||
|
if(CUDNN_FOUND) |
||||||
|
set(CUDNN_LIBRARIES ${CUDNN_LIBRARY}) |
||||||
|
set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR}) |
||||||
|
endif() |
||||||
|
|
||||||
|
mark_as_advanced( |
||||||
|
CUDNN_LIBRARY |
||||||
|
CUDNN_INCLUDE_DIR |
||||||
|
CUDNN_VERSION |
||||||
|
) |
@ -1,3 +1,11 @@ |
|||||||
message(STATUS "opencv_dnn: filter out ocl4dnn source code") |
if(NOT (OPENCV_DNN_OPENCL AND HAVE_OPENCL)) |
||||||
ocv_list_filterout(OPENCV_MODULE_${the_module}_SOURCES "/ocl4dnn/") |
message(STATUS "opencv_dnn: filter out ocl4dnn source code") |
||||||
ocv_list_filterout(OPENCV_MODULE_${the_module}_HEADERS "/ocl4dnn/") |
ocv_list_filterout(OPENCV_MODULE_${the_module}_SOURCES "/ocl4dnn/") |
||||||
|
ocv_list_filterout(OPENCV_MODULE_${the_module}_HEADERS "/ocl4dnn/") |
||||||
|
endif() |
||||||
|
|
||||||
|
if(NOT (OPENCV_DNN_CUDA AND HAVE_CUDA AND HAVE_CUBLAS AND HAVE_CUDNN)) |
||||||
|
message(STATUS "opencv_dnn: filter out cuda4dnn source code") |
||||||
|
ocv_list_filterout(OPENCV_MODULE_${the_module}_SOURCES "/cuda4dnn/") |
||||||
|
ocv_list_filterout(OPENCV_MODULE_${the_module}_HEADERS "/cuda4dnn/") |
||||||
|
endif() |
||||||
|
@ -0,0 +1,18 @@ |
|||||||
|
// This file is part of OpenCV project. |
||||||
|
// It is subject to the license terms in the LICENSE file found in the top-level directory |
||||||
|
// of this distribution and at http://opencv.org/license.html. |
||||||
|
|
||||||
|
// this file is a stub and will be removed once actual code is added |
||||||
|
|
||||||
|
#include "../precomp.hpp" |
||||||
|
|
||||||
|
#include <cuda_runtime.h> |
||||||
|
|
||||||
|
#ifndef HAVE_CUDA |
||||||
|
# error "CUDA files should not be compiled if CUDA was not enabled" |
||||||
|
#endif |
||||||
|
|
||||||
|
__global__ void cuda4dnn_build_test_kernel(float* addr) { |
||||||
|
int idx = threadIdx.x; |
||||||
|
addr[idx] = 0.0; |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
// This file is part of OpenCV project.
|
||||||
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||||
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
|
|
||||||
|
// this file is a stub and will be removed once actual code is added
|
||||||
|
|
||||||
|
#include "../precomp.hpp" |
||||||
|
|
||||||
|
#ifndef HAVE_CUDA |
||||||
|
# error "CUDA4DNN should be enabled iff CUDA and cuDNN were found" |
||||||
|
#endif |
||||||
|
|
||||||
|
#include <cudnn.h> |
||||||
|
|
||||||
|
void cuda4dnn_build_test_func() { |
||||||
|
auto ver = cudnnGetVersion(); |
||||||
|
CV_UNUSED(ver); |
||||||
|
} |
Loading…
Reference in new issue