FindCUDAToolkit.cmake 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindCUDAToolkit
  5. ---------------
  6. .. versionadded:: 3.17
  7. This script locates the NVIDIA CUDA toolkit and the associated libraries, but
  8. does not require the ``CUDA`` language be enabled for a given project. This
  9. module does not search for the NVIDIA CUDA Samples.
  10. .. versionadded:: 3.19
  11. QNX support.
  12. Search Behavior
  13. ^^^^^^^^^^^^^^^
  14. The CUDA Toolkit search behavior uses the following order:
  15. 1. If the ``CUDA`` language has been enabled we will use the directory
  16. containing the compiler as the first search location for ``nvcc``.
  17. 2. If the ``CUDAToolkit_ROOT`` cmake configuration variable (e.g.,
  18. ``-DCUDAToolkit_ROOT=/some/path``) *or* environment variable is defined, it
  19. will be searched. If both an environment variable **and** a
  20. configuration variable are specified, the *configuration* variable takes
  21. precedence.
  22. The directory specified here must be such that the executable ``nvcc`` or
  23. the appropriate ``version.txt`` file can be found underneath the specified
  24. directory.
  25. 3. If the CUDA_PATH environment variable is defined, it will be searched
  26. for ``nvcc``.
  27. 4. The user's path is searched for ``nvcc`` using :command:`find_program`. If
  28. this is found, no subsequent search attempts are performed. Users are
  29. responsible for ensuring that the first ``nvcc`` to show up in the path is
  30. the desired path in the event that multiple CUDA Toolkits are installed.
  31. 5. On Unix systems, if the symbolic link ``/usr/local/cuda`` exists, this is
  32. used. No subsequent search attempts are performed. No default symbolic link
  33. location exists for the Windows platform.
  34. 6. The platform specific default install locations are searched. If exactly one
  35. candidate is found, this is used. The default CUDA Toolkit install locations
  36. searched are:
  37. +-------------+-------------------------------------------------------------+
  38. | Platform | Search Pattern |
  39. +=============+=============================================================+
  40. | macOS | ``/Developer/NVIDIA/CUDA-X.Y`` |
  41. +-------------+-------------------------------------------------------------+
  42. | Other Unix | ``/usr/local/cuda-X.Y`` |
  43. +-------------+-------------------------------------------------------------+
  44. | Windows | ``C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y`` |
  45. +-------------+-------------------------------------------------------------+
  46. Where ``X.Y`` would be a specific version of the CUDA Toolkit, such as
  47. ``/usr/local/cuda-9.0`` or
  48. ``C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0``
  49. .. note::
  50. When multiple CUDA Toolkits are installed in the default location of a
  51. system (e.g., both ``/usr/local/cuda-9.0`` and ``/usr/local/cuda-10.0``
  52. exist but the ``/usr/local/cuda`` symbolic link does **not** exist), this
  53. package is marked as **not** found.
  54. There are too many factors involved in making an automatic decision in
  55. the presence of multiple CUDA Toolkits being installed. In this
  56. situation, users are encouraged to either (1) set ``CUDAToolkit_ROOT`` or
  57. (2) ensure that the correct ``nvcc`` executable shows up in ``$PATH`` for
  58. :command:`find_program` to find.
  59. Arguments
  60. ^^^^^^^^^
  61. ``[<version>]``
  62. The ``[<version>]`` argument requests a version with which the package found
  63. should be compatible. See :ref:`find_package version format <FIND_PACKAGE_VERSION_FORMAT>`
  64. for more details.
  65. Options
  66. ^^^^^^^
  67. ``REQUIRED``
  68. If specified, configuration will error if a suitable CUDA Toolkit is not
  69. found.
  70. ``QUIET``
  71. If specified, the search for a suitable CUDA Toolkit will not produce any
  72. messages.
  73. ``EXACT``
  74. If specified, the CUDA Toolkit is considered found only if the exact
  75. ``VERSION`` specified is recovered.
  76. Imported targets
  77. ^^^^^^^^^^^^^^^^
  78. An :ref:`imported target <Imported targets>` named ``CUDA::toolkit`` is provided.
  79. This module defines :prop_tgt:`IMPORTED` targets for each
  80. of the following libraries that are part of the CUDAToolkit:
  81. - :ref:`CUDA Runtime Library<cuda_toolkit_rt_lib>`
  82. - :ref:`CUDA Driver Library<cuda_toolkit_driver_lib>`
  83. - :ref:`cuBLAS<cuda_toolkit_cuBLAS>`
  84. - :ref:`cuFFT<cuda_toolkit_cuFFT>`
  85. - :ref:`cuRAND<cuda_toolkit_cuRAND>`
  86. - :ref:`cuSOLVER<cuda_toolkit_cuSOLVER>`
  87. - :ref:`cuSPARSE<cuda_toolkit_cuSPARSE>`
  88. - :ref:`cuPTI<cuda_toolkit_cupti>`
  89. - :ref:`NPP<cuda_toolkit_NPP>`
  90. - :ref:`nvBLAS<cuda_toolkit_nvBLAS>`
  91. - :ref:`nvGRAPH<cuda_toolkit_nvGRAPH>`
  92. - :ref:`nvJPEG<cuda_toolkit_nvJPEG>`
  93. - :ref:`nvidia-ML<cuda_toolkit_nvML>`
  94. - :ref:`nvRTC<cuda_toolkit_nvRTC>`
  95. - :ref:`nvToolsExt<cuda_toolkit_nvToolsExt>`
  96. - :ref:`OpenCL<cuda_toolkit_opencl>`
  97. - :ref:`cuLIBOS<cuda_toolkit_cuLIBOS>`
  98. .. _`cuda_toolkit_rt_lib`:
  99. CUDA Runtime Library
  100. """"""""""""""""""""
  101. The CUDA Runtime library (cudart) are what most applications will typically
  102. need to link against to make any calls such as `cudaMalloc`, and `cudaFree`.
  103. Targets Created:
  104. - ``CUDA::cudart``
  105. - ``CUDA::cudart_static``
  106. .. _`cuda_toolkit_driver_lib`:
  107. CUDA Driver Library
  108. """"""""""""""""""""
  109. The CUDA Driver library (cuda) are used by applications that use calls
  110. such as `cuMemAlloc`, and `cuMemFree`.
  111. Targets Created:
  112. - ``CUDA::cuda_driver``
  113. .. _`cuda_toolkit_cuBLAS`:
  114. cuBLAS
  115. """"""
  116. The `cuBLAS <https://docs.nvidia.com/cuda/cublas/index.html>`_ library.
  117. Targets Created:
  118. - ``CUDA::cublas``
  119. - ``CUDA::cublas_static``
  120. - ``CUDA::cublasLt`` starting in CUDA 10.1
  121. - ``CUDA::cublasLt_static`` starting in CUDA 10.1
  122. .. _`cuda_toolkit_cuFFT`:
  123. cuFFT
  124. """""
  125. The `cuFFT <https://docs.nvidia.com/cuda/cufft/index.html>`_ library.
  126. Targets Created:
  127. - ``CUDA::cufft``
  128. - ``CUDA::cufftw``
  129. - ``CUDA::cufft_static``
  130. - ``CUDA::cufft_static_nocallback`` starting in CUDA 9.2, requires CMake 3.23+
  131. - ``CUDA::cufftw_static``
  132. cuRAND
  133. """"""
  134. The `cuRAND <https://docs.nvidia.com/cuda/curand/index.html>`_ library.
  135. Targets Created:
  136. - ``CUDA::curand``
  137. - ``CUDA::curand_static``
  138. .. _`cuda_toolkit_cuSOLVER`:
  139. cuSOLVER
  140. """"""""
  141. The `cuSOLVER <https://docs.nvidia.com/cuda/cusolver/index.html>`_ library.
  142. Targets Created:
  143. - ``CUDA::cusolver``
  144. - ``CUDA::cusolver_static``
  145. .. _`cuda_toolkit_cuSPARSE`:
  146. cuSPARSE
  147. """"""""
  148. The `cuSPARSE <https://docs.nvidia.com/cuda/cusparse/index.html>`_ library.
  149. Targets Created:
  150. - ``CUDA::cusparse``
  151. - ``CUDA::cusparse_static``
  152. .. _`cuda_toolkit_cupti`:
  153. cupti
  154. """""
  155. The `NVIDIA CUDA Profiling Tools Interface <https://developer.nvidia.com/CUPTI>`_.
  156. Targets Created:
  157. - ``CUDA::cupti``
  158. - ``CUDA::cupti_static``
  159. .. _`cuda_toolkit_NPP`:
  160. NPP
  161. """
  162. The `NPP <https://docs.nvidia.com/cuda/npp/index.html>`_ libraries.
  163. Targets Created:
  164. - `nppc`:
  165. - ``CUDA::nppc``
  166. - ``CUDA::nppc_static``
  167. - `nppial`: Arithmetic and logical operation functions in `nppi_arithmetic_and_logical_operations.h`
  168. - ``CUDA::nppial``
  169. - ``CUDA::nppial_static``
  170. - `nppicc`: Color conversion and sampling functions in `nppi_color_conversion.h`
  171. - ``CUDA::nppicc``
  172. - ``CUDA::nppicc_static``
  173. - `nppicom`: JPEG compression and decompression functions in `nppi_compression_functions.h`
  174. Removed starting in CUDA 11.0, use :ref:`nvJPEG<cuda_toolkit_nvJPEG>` instead.
  175. - ``CUDA::nppicom``
  176. - ``CUDA::nppicom_static``
  177. - `nppidei`: Data exchange and initialization functions in `nppi_data_exchange_and_initialization.h`
  178. - ``CUDA::nppidei``
  179. - ``CUDA::nppidei_static``
  180. - `nppif`: Filtering and computer vision functions in `nppi_filter_functions.h`
  181. - ``CUDA::nppif``
  182. - ``CUDA::nppif_static``
  183. - `nppig`: Geometry transformation functions found in `nppi_geometry_transforms.h`
  184. - ``CUDA::nppig``
  185. - ``CUDA::nppig_static``
  186. - `nppim`: Morphological operation functions found in `nppi_morphological_operations.h`
  187. - ``CUDA::nppim``
  188. - ``CUDA::nppim_static``
  189. - `nppist`: Statistics and linear transform in `nppi_statistics_functions.h` and `nppi_linear_transforms.h`
  190. - ``CUDA::nppist``
  191. - ``CUDA::nppist_static``
  192. - `nppisu`: Memory support functions in `nppi_support_functions.h`
  193. - ``CUDA::nppisu``
  194. - ``CUDA::nppisu_static``
  195. - `nppitc`: Threshold and compare operation functions in `nppi_threshold_and_compare_operations.h`
  196. - ``CUDA::nppitc``
  197. - ``CUDA::nppitc_static``
  198. - `npps`:
  199. - ``CUDA::npps``
  200. - ``CUDA::npps_static``
  201. .. _`cuda_toolkit_nvBLAS`:
  202. nvBLAS
  203. """"""
  204. The `nvBLAS <https://docs.nvidia.com/cuda/nvblas/index.html>`_ libraries.
  205. This is a shared library only.
  206. Targets Created:
  207. - ``CUDA::nvblas``
  208. .. _`cuda_toolkit_nvGRAPH`:
  209. nvGRAPH
  210. """""""
  211. The `nvGRAPH <https://docs.nvidia.com/cuda/nvgraph/index.html>`_ library.
  212. Removed starting in CUDA 11.0
  213. Targets Created:
  214. - ``CUDA::nvgraph``
  215. - ``CUDA::nvgraph_static``
  216. .. _`cuda_toolkit_nvJPEG`:
  217. nvJPEG
  218. """"""
  219. The `nvJPEG <https://docs.nvidia.com/cuda/nvjpeg/index.html>`_ library.
  220. Introduced in CUDA 10.
  221. Targets Created:
  222. - ``CUDA::nvjpeg``
  223. - ``CUDA::nvjpeg_static``
  224. .. _`cuda_toolkit_nvRTC`:
  225. nvRTC
  226. """""
  227. The `nvRTC <https://docs.nvidia.com/cuda/nvrtc/index.html>`_ (Runtime Compilation) library.
  228. This is a shared library only.
  229. Targets Created:
  230. - ``CUDA::nvrtc``
  231. .. _`cuda_toolkit_nvml`:
  232. nvidia-ML
  233. """""""""
  234. The `NVIDIA Management Library <https://developer.nvidia.com/nvidia-management-library-nvml>`_.
  235. This is a shared library only.
  236. Targets Created:
  237. - ``CUDA::nvml``
  238. .. _`cuda_toolkit_nvToolsExt`:
  239. nvToolsExt
  240. """"""""""
  241. The `NVIDIA Tools Extension <https://docs.nvidia.com/gameworks/content/gameworkslibrary/nvtx/nvidia_tools_extension_library_nvtx.htm>`_.
  242. This is a shared library only.
  243. Targets Created:
  244. - ``CUDA::nvToolsExt``
  245. .. _`cuda_toolkit_opencl`:
  246. OpenCL
  247. """"""
  248. The `NVIDIA OpenCL Library <https://developer.nvidia.com/opencl>`_.
  249. This is a shared library only.
  250. Targets Created:
  251. - ``CUDA::OpenCL``
  252. .. _`cuda_toolkit_cuLIBOS`:
  253. cuLIBOS
  254. """""""
  255. The cuLIBOS library is a backend thread abstraction layer library which is
  256. static only. The ``CUDA::cublas_static``, ``CUDA::cusparse_static``,
  257. ``CUDA::cufft_static``, ``CUDA::curand_static``, and (when implemented) NPP
  258. libraries all automatically have this dependency linked.
  259. Target Created:
  260. - ``CUDA::culibos``
  261. **Note**: direct usage of this target by consumers should not be necessary.
  262. .. _`cuda_toolkit_cuRAND`:
  263. Result variables
  264. ^^^^^^^^^^^^^^^^
  265. ``CUDAToolkit_FOUND``
  266. A boolean specifying whether or not the CUDA Toolkit was found.
  267. ``CUDAToolkit_VERSION``
  268. The exact version of the CUDA Toolkit found (as reported by
  269. ``nvcc --version`` or ``version.txt``).
  270. ``CUDAToolkit_VERSION_MAJOR``
  271. The major version of the CUDA Toolkit.
  272. ``CUDAToolkit_VERSION_MINOR``
  273. The minor version of the CUDA Toolkit.
  274. ``CUDAToolkit_VERSION_PATCH``
  275. The patch version of the CUDA Toolkit.
  276. ``CUDAToolkit_BIN_DIR``
  277. The path to the CUDA Toolkit library directory that contains the CUDA
  278. executable ``nvcc``.
  279. ``CUDAToolkit_INCLUDE_DIRS``
  280. The path to the CUDA Toolkit ``include`` folder containing the header files
  281. required to compile a project linking against CUDA.
  282. ``CUDAToolkit_LIBRARY_DIR``
  283. The path to the CUDA Toolkit library directory that contains the CUDA
  284. Runtime library ``cudart``.
  285. ``CUDAToolkit_LIBRARY_ROOT``
  286. .. versionadded:: 3.18
  287. The path to the CUDA Toolkit directory containing the nvvm directory and
  288. version.txt.
  289. ``CUDAToolkit_TARGET_DIR``
  290. The path to the CUDA Toolkit directory including the target architecture
  291. when cross-compiling. When not cross-compiling this will be equivalent to
  292. the parent directory of ``CUDAToolkit_BIN_DIR``.
  293. ``CUDAToolkit_NVCC_EXECUTABLE``
  294. The path to the NVIDIA CUDA compiler ``nvcc``. Note that this path may
  295. **not** be the same as
  296. :variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>`. ``nvcc`` must be
  297. found to determine the CUDA Toolkit version as well as determining other
  298. features of the Toolkit. This variable is set for the convenience of
  299. modules that depend on this one.
  300. #]=======================================================================]
  301. # NOTE: much of this was simply extracted from FindCUDA.cmake.
  302. # James Bigler, NVIDIA Corp (nvidia.com - jbigler)
  303. # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
  304. #
  305. # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
  306. #
  307. # Copyright (c) 2007-2009
  308. # Scientific Computing and Imaging Institute, University of Utah
  309. #
  310. # This code is licensed under the MIT License. See the FindCUDA.cmake script
  311. # for the text of the license.
  312. # The MIT License
  313. #
  314. # License for the specific language governing rights and limitations under
  315. # Permission is hereby granted, free of charge, to any person obtaining a
  316. # copy of this software and associated documentation files (the "Software"),
  317. # to deal in the Software without restriction, including without limitation
  318. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  319. # and/or sell copies of the Software, and to permit persons to whom the
  320. # Software is furnished to do so, subject to the following conditions:
  321. #
  322. # The above copyright notice and this permission notice shall be included
  323. # in all copies or substantial portions of the Software.
  324. #
  325. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  326. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  327. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  328. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  329. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  330. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  331. # DEALINGS IN THE SOFTWARE.
  332. #
  333. ###############################################################################
  334. # The toolkit is located during compiler detection for CUDA and stored in CMakeCUDACompiler.cmake as
  335. # CMAKE_CUDA_COMPILER_TOOLKIT_ROOT and CMAKE_CUDA_COMPILER_LIBRARY_ROOT.
  336. # We compute the rest based on those here to avoid re-searching and to avoid finding a possibly
  337. # different installation.
  338. if(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT)
  339. set(CUDAToolkit_ROOT_DIR "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}")
  340. set(CUDAToolkit_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_LIBRARY_ROOT}")
  341. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_ROOT_DIR}/bin")
  342. set(CUDAToolkit_NVCC_EXECUTABLE "${CUDAToolkit_BIN_DIR}/nvcc${CMAKE_EXECUTABLE_SUFFIX}")
  343. else()
  344. function(_CUDAToolkit_find_root_dir )
  345. cmake_parse_arguments(arg "" "" "SEARCH_PATHS;FIND_FLAGS" ${ARGN})
  346. if(NOT CUDAToolkit_BIN_DIR)
  347. if(NOT CUDAToolkit_SENTINEL_FILE)
  348. find_program(CUDAToolkit_NVCC_EXECUTABLE
  349. NAMES nvcc nvcc.exe
  350. PATHS ${arg_SEARCH_PATHS}
  351. ${arg_FIND_FLAGS}
  352. )
  353. endif()
  354. if(NOT CUDAToolkit_NVCC_EXECUTABLE)
  355. find_file(CUDAToolkit_SENTINEL_FILE
  356. NAMES version.txt
  357. PATHS ${arg_SEARCH_PATHS}
  358. NO_DEFAULT_PATH
  359. )
  360. endif()
  361. if(EXISTS "${CUDAToolkit_NVCC_EXECUTABLE}")
  362. # If NVCC exists then invoke it to find the toolkit location.
  363. # This allows us to support wrapper scripts (e.g. ccache or colornvcc), CUDA Toolkit,
  364. # NVIDIA HPC SDK, and distro's splayed layouts
  365. execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda"
  366. OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT)
  367. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ TOP=([^\r\n]*)")
  368. get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}/bin" ABSOLUTE)
  369. else()
  370. get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY)
  371. endif()
  372. unset(_CUDA_NVCC_OUT)
  373. mark_as_advanced(CUDAToolkit_BIN_DIR)
  374. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
  375. endif()
  376. if(CUDAToolkit_SENTINEL_FILE)
  377. get_filename_component(CUDAToolkit_BIN_DIR ${CUDAToolkit_SENTINEL_FILE} DIRECTORY ABSOLUTE)
  378. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}/bin")
  379. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
  380. mark_as_advanced(CUDAToolkit_BIN_DIR)
  381. endif()
  382. endif()
  383. if(CUDAToolkit_BIN_DIR)
  384. get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE)
  385. set(CUDAToolkit_ROOT_DIR "${CUDAToolkit_ROOT_DIR}" PARENT_SCOPE)
  386. endif()
  387. endfunction()
  388. function(_CUDAToolkit_find_version_file result_variable)
  389. # We first check for a non-scattered installation to prefer it over a scattered installation.
  390. if(CUDAToolkit_ROOT AND EXISTS "${CUDAToolkit_ROOT}/version.txt")
  391. set(${result_variable} "${CUDAToolkit_ROOT}/version.txt" PARENT_SCOPE)
  392. elseif(CUDAToolkit_ROOT_DIR AND EXISTS "${CUDAToolkit_ROOT_DIR}/version.txt")
  393. set(${result_variable} "${CUDAToolkit_ROOT_DIR}/version.txt" PARENT_SCOPE)
  394. elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/version.txt")
  395. set(${result_variable} "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/version.txt" PARENT_SCOPE)
  396. elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/version.txt")
  397. set(${result_variable} "${CMAKE_SYSROOT}/usr/lib/cuda/version.txt" PARENT_SCOPE)
  398. endif()
  399. endfunction()
  400. # For NVCC we can easily deduce the SDK binary directory from the compiler path.
  401. if(CMAKE_CUDA_COMPILER_LOADED AND NOT CUDAToolkit_BIN_DIR AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
  402. get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_CUDA_COMPILER}" DIRECTORY)
  403. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "")
  404. # Try language provided path first.
  405. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_BIN_DIR}" FIND_FLAGS NO_DEFAULT_PATH)
  406. mark_as_advanced(CUDAToolkit_BIN_DIR)
  407. endif()
  408. # Try user provided path
  409. if(NOT CUDAToolkit_ROOT_DIR AND CUDAToolkit_ROOT)
  410. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_ROOT}" FIND_FLAGS PATH_SUFFIXES bin NO_DEFAULT_PATH)
  411. endif()
  412. if(NOT CUDAToolkit_ROOT_DIR)
  413. _CUDAToolkit_find_root_dir(FIND_FLAGS PATHS ENV CUDA_PATH PATH_SUFFIXES bin)
  414. endif()
  415. # If the user specified CUDAToolkit_ROOT but the toolkit could not be found, this is an error.
  416. if(NOT CUDAToolkit_ROOT_DIR AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT}))
  417. # Declare error messages now, print later depending on find_package args.
  418. set(fail_base "Could not find nvcc executable in path specified by")
  419. set(cuda_root_fail "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
  420. set(env_cuda_root_fail "${fail_base} environment variable CUDAToolkit_ROOT=$ENV{CUDAToolkit_ROOT}")
  421. if(CUDAToolkit_FIND_REQUIRED)
  422. if(DEFINED CUDAToolkit_ROOT)
  423. message(FATAL_ERROR ${cuda_root_fail})
  424. elseif(DEFINED ENV{CUDAToolkit_ROOT})
  425. message(FATAL_ERROR ${env_cuda_root_fail})
  426. endif()
  427. else()
  428. if(NOT CUDAToolkit_FIND_QUIETLY)
  429. if(DEFINED CUDAToolkit_ROOT)
  430. message(STATUS ${cuda_root_fail})
  431. elseif(DEFINED ENV{CUDAToolkit_ROOT})
  432. message(STATUS ${env_cuda_root_fail})
  433. endif()
  434. endif()
  435. set(CUDAToolkit_FOUND FALSE)
  436. unset(fail_base)
  437. unset(cuda_root_fail)
  438. unset(env_cuda_root_fail)
  439. return()
  440. endif()
  441. endif()
  442. # CUDAToolkit_ROOT cmake / env variable not specified, try platform defaults.
  443. #
  444. # - Linux: /usr/local/cuda-X.Y
  445. # - macOS: /Developer/NVIDIA/CUDA-X.Y
  446. # - Windows: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y
  447. #
  448. # We will also search the default symlink location /usr/local/cuda first since
  449. # if CUDAToolkit_ROOT is not specified, it is assumed that the symlinked
  450. # directory is the desired location.
  451. if(NOT CUDAToolkit_ROOT_DIR)
  452. if(UNIX)
  453. if(NOT APPLE)
  454. set(platform_base "/usr/local/cuda-")
  455. else()
  456. set(platform_base "/Developer/NVIDIA/CUDA-")
  457. endif()
  458. else()
  459. set(platform_base "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v")
  460. endif()
  461. # Build out a descending list of possible cuda installations, e.g.
  462. file(GLOB possible_paths "${platform_base}*")
  463. # Iterate the glob results and create a descending list.
  464. set(versions)
  465. foreach(p ${possible_paths})
  466. # Extract version number from end of string
  467. string(REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${p})
  468. if(IS_DIRECTORY ${p} AND p_version)
  469. list(APPEND versions ${p_version})
  470. endif()
  471. endforeach()
  472. # Sort numerically in descending order, so we try the newest versions first.
  473. list(SORT versions COMPARE NATURAL ORDER DESCENDING)
  474. # With a descending list of versions, populate possible paths to search.
  475. set(search_paths)
  476. foreach(v ${versions})
  477. list(APPEND search_paths "${platform_base}${v}")
  478. endforeach()
  479. # Force the global default /usr/local/cuda to the front on Unix.
  480. if(UNIX)
  481. list(INSERT search_paths 0 "/usr/local/cuda")
  482. endif()
  483. # Now search for the toolkit again using the platform default search paths.
  484. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${search_paths}" FIND_FLAGS PATH_SUFFIXES bin)
  485. # We are done with these variables now, cleanup for caller.
  486. unset(platform_base)
  487. unset(possible_paths)
  488. unset(versions)
  489. unset(search_paths)
  490. if(NOT CUDAToolkit_ROOT_DIR)
  491. if(CUDAToolkit_FIND_REQUIRED)
  492. message(FATAL_ERROR "Could not find nvcc, please set CUDAToolkit_ROOT.")
  493. elseif(NOT CUDAToolkit_FIND_QUIETLY)
  494. message(STATUS "Could not find nvcc, please set CUDAToolkit_ROOT.")
  495. endif()
  496. set(CUDAToolkit_FOUND FALSE)
  497. return()
  498. endif()
  499. endif()
  500. _CUDAToolkit_find_version_file( _CUDAToolkit_version_file )
  501. if(_CUDAToolkit_version_file)
  502. # CUDAToolkit_LIBRARY_ROOT contains the device library and version file.
  503. get_filename_component(CUDAToolkit_LIBRARY_ROOT "${_CUDAToolkit_version_file}" DIRECTORY ABSOLUTE)
  504. endif()
  505. unset(_CUDAToolkit_version_file)
  506. endif()
  507. # Find target directory when crosscompiling.
  508. if(CMAKE_CROSSCOMPILING)
  509. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a")
  510. # Support for NVPACK
  511. set(CUDAToolkit_TARGET_NAME "armv7-linux-androideabi")
  512. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
  513. set(CUDAToolkit_TARGET_NAME "armv7-linux-gnueabihf")
  514. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
  515. if(ANDROID_ARCH_NAME STREQUAL "arm64")
  516. set(CUDAToolkit_TARGET_NAME "aarch64-linux-androideabi")
  517. elseif (CMAKE_SYSTEM_NAME STREQUAL "QNX")
  518. set(CUDAToolkit_TARGET_NAME "aarch64-qnx")
  519. else()
  520. set(CUDAToolkit_TARGET_NAME "aarch64-linux")
  521. endif(ANDROID_ARCH_NAME STREQUAL "arm64")
  522. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  523. set(CUDAToolkit_TARGET_NAME "x86_64-linux")
  524. endif()
  525. if(EXISTS "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
  526. set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
  527. # add known CUDA target root path to the set of directories we search for programs, libraries and headers
  528. list(PREPEND CMAKE_FIND_ROOT_PATH "${CUDAToolkit_TARGET_DIR}")
  529. # Mark that we need to pop the root search path changes after we have
  530. # found all cuda libraries so that searches for our cross-compilation
  531. # libraries work when another cuda sdk is in CMAKE_PREFIX_PATH or
  532. # PATh
  533. set(_CUDAToolkit_Pop_ROOT_PATH True)
  534. endif()
  535. endif()
  536. # If not already set we can simply use the toolkit root or it's a scattered installation.
  537. if(NOT CUDAToolkit_TARGET_DIR)
  538. # Not cross compiling
  539. set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}")
  540. # Now that we have the real ROOT_DIR, find components inside it.
  541. list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR})
  542. # Mark that we need to pop the prefix path changes after we have
  543. # found the cudart library.
  544. set(_CUDAToolkit_Pop_Prefix True)
  545. endif()
  546. # CUDAToolkit_TARGET_DIR always points to the directory containing the include directory.
  547. # On a scattered installation /usr, on a non-scattered something like /usr/local/cuda or /usr/local/cuda-10.2/targets/aarch64-linux.
  548. if(EXISTS "${CUDAToolkit_TARGET_DIR}/include/cuda_runtime.h")
  549. set(CUDAToolkit_INCLUDE_DIR "${CUDAToolkit_TARGET_DIR}/include")
  550. elseif(NOT CUDAToolkit_FIND_QUIETLY)
  551. message(STATUS "Unable to find cuda_runtime.h in \"${CUDAToolkit_TARGET_DIR}/include\" for CUDAToolkit_INCLUDE_DIR.")
  552. endif()
  553. # The NVHPC layout moves math library headers and libraries to a sibling directory.
  554. # Create a separate variable so this directory can be selectively added to math targets.
  555. if(NOT EXISTS "${CUDAToolkit_INCLUDE_DIR}/cublas_v2.h")
  556. set(CUDAToolkit_MATH_INCLUDE_DIR "${CUDAToolkit_TARGET_DIR}/../../math_libs/include")
  557. cmake_path(NORMAL_PATH CUDAToolkit_MATH_INCLUDE_DIR)
  558. if(NOT EXISTS "${CUDAToolkit_MATH_INCLUDE_DIR}/cublas_v2.h")
  559. if(NOT CUDAToolkit_FIND_QUIETLY)
  560. message(STATUS "Unable to find cublas_v2.h in either \"${CUDAToolkit_INCLUDE_DIR}\" or \"${CUDAToolkit_MATH_INCLUDE_DIR}\"")
  561. endif()
  562. unset(CUDAToolkit_MATH_INCLUDE_DIR)
  563. endif()
  564. endif()
  565. if(CUDAToolkit_NVCC_EXECUTABLE AND
  566. CMAKE_CUDA_COMPILER_VERSION AND
  567. CUDAToolkit_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER)
  568. # Need to set these based off the already computed CMAKE_CUDA_COMPILER_VERSION value
  569. # This if statement will always match, but is used to provide variables for MATCH 1,2,3...
  570. if(CMAKE_CUDA_COMPILER_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  571. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  572. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  573. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  574. set(CUDAToolkit_VERSION "${CMAKE_CUDA_COMPILER_VERSION}")
  575. endif()
  576. elseif(CUDAToolkit_NVCC_EXECUTABLE)
  577. # Compute the version by invoking nvcc
  578. execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
  579. if(NVCC_OUT MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  580. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  581. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  582. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  583. set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  584. endif()
  585. unset(NVCC_OUT)
  586. else()
  587. _CUDAToolkit_find_version_file(version_file)
  588. if(version_file)
  589. file(READ "${version_file}" VERSION_INFO)
  590. if(VERSION_INFO MATCHES [=[CUDA Version ([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  591. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  592. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  593. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  594. set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  595. endif()
  596. endif()
  597. endif()
  598. # Find the CUDA Runtime Library libcudart
  599. find_library(CUDA_CUDART
  600. NAMES cudart
  601. PATH_SUFFIXES lib64 lib/x64
  602. )
  603. find_library(CUDA_CUDART
  604. NAMES cudart
  605. PATH_SUFFIXES lib64/stubs lib/x64/stubs
  606. )
  607. if(NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY)
  608. message(STATUS "Unable to find cudart library.")
  609. endif()
  610. if(_CUDAToolkit_Pop_Prefix)
  611. list(REMOVE_AT CMAKE_PREFIX_PATH -1)
  612. unset(_CUDAToolkit_Pop_Prefix)
  613. endif()
  614. #-----------------------------------------------------------------------------
  615. # Perform version comparison and validate all required variables are set.
  616. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  617. find_package_handle_standard_args(CUDAToolkit
  618. REQUIRED_VARS
  619. CUDAToolkit_INCLUDE_DIR
  620. CUDA_CUDART
  621. CUDAToolkit_BIN_DIR
  622. VERSION_VAR
  623. CUDAToolkit_VERSION
  624. )
  625. unset(CUDAToolkit_ROOT_DIR)
  626. mark_as_advanced(CUDA_CUDART
  627. CUDAToolkit_INCLUDE_DIR
  628. CUDAToolkit_NVCC_EXECUTABLE
  629. CUDAToolkit_SENTINEL_FILE
  630. )
  631. #-----------------------------------------------------------------------------
  632. # Construct result variables
  633. if(CUDAToolkit_FOUND)
  634. set(CUDAToolkit_INCLUDE_DIRS ${CUDAToolkit_INCLUDE_DIR})
  635. get_filename_component(CUDAToolkit_LIBRARY_DIR ${CUDA_CUDART} DIRECTORY ABSOLUTE)
  636. endif()
  637. #-----------------------------------------------------------------------------
  638. # Construct import targets
  639. if(CUDAToolkit_FOUND)
  640. function(_CUDAToolkit_find_and_add_import_lib lib_name)
  641. cmake_parse_arguments(arg "" "" "ALT;DEPS;EXTRA_PATH_SUFFIXES" ${ARGN})
  642. set(search_names ${lib_name} ${arg_ALT})
  643. find_library(CUDA_${lib_name}_LIBRARY
  644. NAMES ${search_names}
  645. HINTS ${CUDAToolkit_LIBRARY_DIR}
  646. ENV CUDA_PATH
  647. PATH_SUFFIXES nvidia/current lib64 lib/x64 lib
  648. ${arg_EXTRA_PATH_SUFFIXES}
  649. )
  650. # Don't try any stub directories until we have exhausted all other
  651. # search locations.
  652. find_library(CUDA_${lib_name}_LIBRARY
  653. NAMES ${search_names}
  654. HINTS ${CUDAToolkit_LIBRARY_DIR}
  655. ENV CUDA_PATH
  656. PATH_SUFFIXES lib64/stubs lib/x64/stubs lib/stubs stubs
  657. # Support NVHPC splayed math library layout
  658. ../../math_libs/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/lib64
  659. ../../math_libs/lib64
  660. )
  661. mark_as_advanced(CUDA_${lib_name}_LIBRARY)
  662. if (NOT TARGET CUDA::${lib_name} AND CUDA_${lib_name}_LIBRARY)
  663. add_library(CUDA::${lib_name} UNKNOWN IMPORTED)
  664. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  665. if(DEFINED CUDAToolkit_MATH_INCLUDE_DIR)
  666. string(FIND ${CUDA_${lib_name}_LIBRARY} "math_libs" math_libs)
  667. if(NOT ${math_libs} EQUAL -1)
  668. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_MATH_INCLUDE_DIR}")
  669. endif()
  670. endif()
  671. set_property(TARGET CUDA::${lib_name} PROPERTY IMPORTED_LOCATION "${CUDA_${lib_name}_LIBRARY}")
  672. foreach(dep ${arg_DEPS})
  673. if(TARGET CUDA::${dep})
  674. target_link_libraries(CUDA::${lib_name} INTERFACE CUDA::${dep})
  675. endif()
  676. endforeach()
  677. endif()
  678. endfunction()
  679. if(NOT TARGET CUDA::toolkit)
  680. add_library(CUDA::toolkit IMPORTED INTERFACE)
  681. target_include_directories(CUDA::toolkit SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  682. target_link_directories(CUDA::toolkit INTERFACE "${CUDAToolkit_LIBRARY_DIR}")
  683. endif()
  684. _CUDAToolkit_find_and_add_import_lib(cuda_driver ALT cuda)
  685. _CUDAToolkit_find_and_add_import_lib(cudart)
  686. _CUDAToolkit_find_and_add_import_lib(cudart_static)
  687. # setup dependencies that are required for cudart_static when building
  688. # on linux. These are generally only required when using the CUDA toolkit
  689. # when CUDA language is disabled
  690. if(NOT TARGET CUDA::cudart_static_deps
  691. AND TARGET CUDA::cudart_static)
  692. add_library(CUDA::cudart_static_deps IMPORTED INTERFACE)
  693. target_link_libraries(CUDA::cudart_static INTERFACE CUDA::cudart_static_deps)
  694. if(UNIX AND (CMAKE_C_COMPILER OR CMAKE_CXX_COMPILER))
  695. find_package(Threads REQUIRED)
  696. target_link_libraries(CUDA::cudart_static_deps INTERFACE Threads::Threads ${CMAKE_DL_LIBS})
  697. endif()
  698. if(UNIX AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX"))
  699. # On Linux, you must link against librt when using the static cuda runtime.
  700. find_library(CUDAToolkit_rt_LIBRARY rt)
  701. mark_as_advanced(CUDAToolkit_rt_LIBRARY)
  702. if(NOT CUDAToolkit_rt_LIBRARY)
  703. message(WARNING "Could not find librt library, needed by CUDA::cudart_static")
  704. else()
  705. target_link_libraries(CUDA::cudart_static_deps INTERFACE ${CUDAToolkit_rt_LIBRARY})
  706. endif()
  707. endif()
  708. endif()
  709. _CUDAToolkit_find_and_add_import_lib(culibos) # it's a static library
  710. foreach (cuda_lib cublasLt cublas cufft curand cusparse nppc nvjpeg)
  711. _CUDAToolkit_find_and_add_import_lib(${cuda_lib})
  712. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS culibos)
  713. endforeach()
  714. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.0.0)
  715. # cublas depends on cublasLt
  716. # https://docs.nvidia.com/cuda/archive/11.0/cublas/index.html#static-library
  717. _CUDAToolkit_find_and_add_import_lib(cublas DEPS cublasLt)
  718. _CUDAToolkit_find_and_add_import_lib(cublas_static DEPS cublasLt_static)
  719. endif()
  720. # cuFFTW depends on cuFFT
  721. _CUDAToolkit_find_and_add_import_lib(cufftw DEPS cufft)
  722. _CUDAToolkit_find_and_add_import_lib(cufftw DEPS cufft_static)
  723. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 9.2)
  724. _CUDAToolkit_find_and_add_import_lib(cufft_static_nocallback DEPS culibos)
  725. endif()
  726. # cuSOLVER depends on cuBLAS, and cuSPARSE
  727. _CUDAToolkit_find_and_add_import_lib(cusolver DEPS cublas cusparse)
  728. _CUDAToolkit_find_and_add_import_lib(cusolver_static DEPS cublas_static cusparse_static culibos)
  729. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.1.2)
  730. # cusolver depends on liblapack_static.a starting with CUDA 10.1 update 2,
  731. # https://docs.nvidia.com/cuda/archive/11.5.0/cusolver/index.html#static-link-lapack
  732. _CUDAToolkit_find_and_add_import_lib(cusolver_lapack_static ALT lapack_static) # implementation detail static lib
  733. _CUDAToolkit_find_and_add_import_lib(cusolver_static DEPS cusolver_lapack_static)
  734. endif()
  735. if(CUDAToolkit_VERSION VERSION_GREATER 11.2.1)
  736. # cusolver depends on libcusolver_metis and cublasLt
  737. # https://docs.nvidia.com/cuda/archive/11.2.2/cusolver/index.html#link-dependency
  738. _CUDAToolkit_find_and_add_import_lib(cusolver DEPS cublasLt)
  739. _CUDAToolkit_find_and_add_import_lib(cusolver_metis_static ALT metis_static) # implementation detail static lib
  740. _CUDAToolkit_find_and_add_import_lib(cusolver_static DEPS cusolver_metis_static cublasLt_static)
  741. endif()
  742. # nvGRAPH depends on cuRAND, and cuSOLVER.
  743. _CUDAToolkit_find_and_add_import_lib(nvgraph DEPS curand cusolver)
  744. _CUDAToolkit_find_and_add_import_lib(nvgraph_static DEPS curand_static cusolver_static)
  745. # Process the majority of the NPP libraries.
  746. foreach (cuda_lib nppial nppicc nppidei nppif nppig nppim nppist nppitc npps nppicom nppisu)
  747. _CUDAToolkit_find_and_add_import_lib(${cuda_lib} DEPS nppc)
  748. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS nppc_static)
  749. endforeach()
  750. _CUDAToolkit_find_and_add_import_lib(cupti
  751. EXTRA_PATH_SUFFIXES ../extras/CUPTI/lib64/
  752. ../extras/CUPTI/lib/)
  753. _CUDAToolkit_find_and_add_import_lib(cupti_static
  754. EXTRA_PATH_SUFFIXES ../extras/CUPTI/lib64/
  755. ../extras/CUPTI/lib/)
  756. _CUDAToolkit_find_and_add_import_lib(nvrtc DEPS cuda_driver)
  757. _CUDAToolkit_find_and_add_import_lib(nvml ALT nvidia-ml nvml)
  758. if(WIN32)
  759. # nvtools can be installed outside the CUDA toolkit directory
  760. # so prefer the NVTOOLSEXT_PATH windows only environment variable
  761. # In addition on windows the most common name is nvToolsExt64_1
  762. find_library(CUDA_nvToolsExt_LIBRARY
  763. NAMES nvToolsExt64_1 nvToolsExt64 nvToolsExt
  764. PATHS ENV NVTOOLSEXT_PATH
  765. ENV CUDA_PATH
  766. PATH_SUFFIXES lib/x64 lib
  767. )
  768. endif()
  769. _CUDAToolkit_find_and_add_import_lib(nvToolsExt ALT nvToolsExt64)
  770. _CUDAToolkit_find_and_add_import_lib(OpenCL)
  771. endif()
  772. if(_CUDAToolkit_Pop_ROOT_PATH)
  773. list(REMOVE_AT CMAKE_FIND_ROOT_PATH 0)
  774. unset(_CUDAToolkit_Pop_ROOT_PATH)
  775. endif()