FindCUDNN.cmake 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # template taken from https://cmake.org/cmake/help/v3.14/manual/cmake-developer.7.html
  2. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  3. # file Copyright.txt or https://cmake.org/licensing for details.
  4. #[=======================================================================[.rst:
  5. FindCUDNN
  6. ---------
  7. Finds the cuDNN library.
  8. Requires:
  9. ^^^^^^^^^
  10. find_cuda_helper_libs from FindCUDA.cmake
  11. i.e. CUDA module should be found using FindCUDA.cmake before attempting to find cuDNN
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This will define the following variables:
  15. ``CUDNN_FOUND``
  16. ``CUDNN_INCLUDE_DIRS`` location of cudnn.h
  17. ``CUDNN_LIBRARIES`` location of cudnn library
  18. Cache Variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables will be set if cuDNN was found. They may also be set on failure.
  21. ``CUDNN_LIBRARY``
  22. ``CUDNN_INCLUDE_DIR``
  23. ``CUDNN_VERSION``
  24. ``CUDNN_VERSION_MAJOR`` INTERNAL
  25. ``CUDNN_VERSION_MINOR`` INTERNAL
  26. ``CUDNN_VERSION_PATCH`` INTERNAL
  27. #]=======================================================================]
  28. # find the library
  29. if(CUDA_FOUND)
  30. find_cuda_helper_libs(cudnn)
  31. set(CUDNN_LIBRARY ${CUDA_cudnn_LIBRARY} CACHE FILEPATH "location of the cuDNN library")
  32. unset(CUDA_cudnn_LIBRARY CACHE)
  33. endif()
  34. # find the include
  35. if(CUDNN_LIBRARY)
  36. find_path(CUDNN_INCLUDE_DIR
  37. cudnn.h
  38. PATHS ${CUDA_TOOLKIT_INCLUDE}
  39. DOC "location of cudnn.h"
  40. NO_DEFAULT_PATH
  41. )
  42. if(NOT CUDNN_INCLUDE_DIR)
  43. find_path(CUDNN_INCLUDE_DIR
  44. cudnn.h
  45. DOC "location of cudnn.h"
  46. )
  47. endif()
  48. endif()
  49. # extract version from the include
  50. if(CUDNN_INCLUDE_DIR)
  51. if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version.h")
  52. file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version.h" CUDNN_H_CONTENTS)
  53. else()
  54. file(READ "${CUDNN_INCLUDE_DIR}/cudnn.h" CUDNN_H_CONTENTS)
  55. endif()
  56. string(REGEX MATCH "define CUDNN_MAJOR ([0-9]+)" _ "${CUDNN_H_CONTENTS}")
  57. set(CUDNN_VERSION_MAJOR ${CMAKE_MATCH_1} CACHE INTERNAL "")
  58. string(REGEX MATCH "define CUDNN_MINOR ([0-9]+)" _ "${CUDNN_H_CONTENTS}")
  59. set(CUDNN_VERSION_MINOR ${CMAKE_MATCH_1} CACHE INTERNAL "")
  60. string(REGEX MATCH "define CUDNN_PATCHLEVEL ([0-9]+)" _ "${CUDNN_H_CONTENTS}")
  61. set(CUDNN_VERSION_PATCH ${CMAKE_MATCH_1} CACHE INTERNAL "")
  62. set(CUDNN_VERSION "${CUDNN_VERSION_MAJOR}.${CUDNN_VERSION_MINOR}.${CUDNN_VERSION_PATCH}")
  63. unset(CUDNN_H_CONTENTS)
  64. endif()
  65. include(FindPackageHandleStandardArgs)
  66. find_package_handle_standard_args(CUDNN
  67. FOUND_VAR CUDNN_FOUND
  68. REQUIRED_VARS
  69. CUDNN_LIBRARY
  70. CUDNN_INCLUDE_DIR
  71. VERSION_VAR CUDNN_VERSION
  72. )
  73. if(CUDNN_FOUND)
  74. set(CUDNN_LIBRARIES ${CUDNN_LIBRARY})
  75. set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR})
  76. endif()
  77. mark_as_advanced(
  78. CUDNN_LIBRARY
  79. CUDNN_INCLUDE_DIR
  80. CUDNN_VERSION
  81. )