Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix CUDNN detection for CMake build #17019

Merged
merged 2 commits into from
Dec 10, 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
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,15 @@ add_subdirectory(${GTEST_ROOT})
find_package(GTest REQUIRED)

# cudnn detection
if(USE_CUDNN AND USE_CUDA)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This AND USE_CUDA should not have been removed inside this PR. It assumes cmake_dependent_option(USE_CUDNN "Build with cudnn support" ON "USE_CUDA" OFF) from #17018 is used. Unfortunately our tests don't test USE_CUDA=0 on a machine with CUDNN available, so the passed.

@yajiedesign I suggest either to either merge #17018 quickly or I'll create another PR to add back the AND USE_CUDA

detect_cuDNN()
if(HAVE_CUDNN)
if(USE_CUDNN)
find_package(CUDNN)
if(CUDNN_FOUND)
add_definitions(-DUSE_CUDNN)
include_directories(SYSTEM ${CUDNN_INCLUDE})
list(APPEND mxnet_LINKER_LIBS ${CUDNN_LIBRARY})
add_definitions(-DMSHADOW_USE_CUDNN=1)
add_definitions(-DMSHADOW_USE_CUDNN=1)
else()
set(USE_CUDNN OFF)
endif()
endif()

Expand Down
12 changes: 0 additions & 12 deletions cmake/BuildTVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,6 @@ set(USE_RANDOM OFF)
# Whether use NNPack
set(USE_NNPACK OFF)

# Whether use CuDNN
if(USE_CUDNN AND USE_CUDA)
detect_cuDNN()
if(HAVE_CUDNN)
set(USE_CUDNN ON)
else()
set(USE_CUDNN OFF)
endif()
else()
set(USE_CUDNN OFF)
endif()

# Whether use cuBLAS
set(USE_CUBLAS OFF)

Expand Down
28 changes: 0 additions & 28 deletions cmake/FirstClassLangCuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,6 @@ if(USE_CXX14_IF_AVAILABLE)
check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
endif()

################################################################################################
# Short command for cuDNN detection. Believe it soon will be a part of CUDA toolkit distribution.
# That's why not FindcuDNN.cmake file, but just the macro
# Usage:
# detect_cuDNN()
function(detect_cuDNN)
set(CUDNN_ROOT "" CACHE PATH "CUDNN root folder")

find_path(CUDNN_INCLUDE cudnn.h
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT}
DOC "Path to cuDNN include directory." )


find_library(CUDNN_LIBRARY NAMES libcudnn.so cudnn.lib # libcudnn_static.a
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDNN_INCLUDE}
PATH_SUFFIXES lib lib/x64
DOC "Path to cuDNN library.")

if(CUDNN_INCLUDE AND CUDNN_LIBRARY)
set(HAVE_CUDNN TRUE PARENT_SCOPE)
set(CUDNN_FOUND TRUE PARENT_SCOPE)

mark_as_advanced(CUDNN_INCLUDE CUDNN_LIBRARY CUDNN_ROOT)
message(STATUS "Found cuDNN (include: ${CUDNN_INCLUDE}, library: ${CUDNN_LIBRARY})")
endif()
endfunction()



################################################################################################
# A function for automatic detection of GPUs installed (if autodetection is enabled)
Expand Down
33 changes: 33 additions & 0 deletions cmake/Modules/FindCUDNN.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
leezu marked this conversation as resolved.
Show resolved Hide resolved

include(FindPackageHandleStandardArgs)

set(CUDNN_ROOT "/usr/local/cuda/include" CACHE PATH "cuDNN root folder")

find_path(CUDNN_INCLUDE cudnn.h
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT}
DOC "Path to cuDNN include directory." )

find_library(CUDNN_LIBRARY NAMES libcudnn.so cudnn.lib # libcudnn_static.a
PATHS ${CUDNN_ROOT} $ENV{CUDNN_ROOT} ${CUDNN_INCLUDE}
PATH_SUFFIXES lib lib/x64 cuda/lib cuda/lib64 lib/x64
DOC "Path to cuDNN library.")

find_package_handle_standard_args(CUDNN DEFAULT_MSG CUDNN_LIBRARY CUDNN_INCLUDE)

mark_as_advanced(CUDNN_ROOT CUDNN_INCLUDE CUDNN_LIBRARY)