FindCUDAToolkit.cmake 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindCUDAToolkit
  5. ---------------
  6. .. versionadded:: 3.17
  7. Finds the NVIDIA CUDA toolkit and the associated libraries, but does not
  8. require the ``CUDA`` language be enabled for a given project:
  9. .. code-block:: cmake
  10. find_package(CUDAToolkit [<version>] [QUIET] [REQUIRED] [EXACT] [...])
  11. This module does not search for the NVIDIA CUDA Samples.
  12. .. versionadded:: 3.19
  13. QNX support.
  14. Search Behavior
  15. ^^^^^^^^^^^^^^^
  16. The CUDA Toolkit search behavior uses the following order:
  17. 1. If the ``CUDA`` language has been enabled we will use the directory
  18. containing the compiler as the first search location for ``nvcc``.
  19. 2. If the variable :variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>` or
  20. the environment variable :envvar:`CUDACXX` is defined, it will be used
  21. as the path to the ``nvcc`` executable.
  22. 3. If the ``CUDAToolkit_ROOT`` cmake configuration variable (e.g.,
  23. ``-DCUDAToolkit_ROOT=/some/path``) *or* environment variable is defined, it
  24. will be searched. If both an environment variable **and** a
  25. configuration variable are specified, the *configuration* variable takes
  26. precedence.
  27. The directory specified here must be such that the executable ``nvcc`` or
  28. the appropriate ``version.txt`` or ``version.json`` file can be found
  29. underneath the specified directory.
  30. 4. If the CUDA_PATH environment variable is defined, it will be searched
  31. for ``nvcc``.
  32. 5. The user's path is searched for ``nvcc`` using :command:`find_program`. If
  33. this is found, no subsequent search attempts are performed. Users are
  34. responsible for ensuring that the first ``nvcc`` to show up in the path is
  35. the desired path in the event that multiple CUDA Toolkits are installed.
  36. 6. On Unix systems, if the symbolic link ``/usr/local/cuda`` exists, this is
  37. used. No subsequent search attempts are performed. No default symbolic link
  38. location exists for the Windows platform.
  39. 7. The platform specific default install locations are searched. If exactly one
  40. candidate is found, this is used. The default CUDA Toolkit install locations
  41. searched are:
  42. +-------------+-------------------------------------------------------------+
  43. | Platform | Search Pattern |
  44. +=============+=============================================================+
  45. | macOS | ``/Developer/NVIDIA/CUDA-X.Y`` |
  46. +-------------+-------------------------------------------------------------+
  47. | Other Unix | ``/usr/local/cuda-X.Y`` |
  48. +-------------+-------------------------------------------------------------+
  49. | Windows | ``C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y`` |
  50. +-------------+-------------------------------------------------------------+
  51. Where ``X.Y`` would be a specific version of the CUDA Toolkit, such as
  52. ``/usr/local/cuda-9.0`` or
  53. ``C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0``
  54. .. note::
  55. When multiple CUDA Toolkits are installed in the default location of a
  56. system (e.g., both ``/usr/local/cuda-9.0`` and ``/usr/local/cuda-10.0``
  57. exist but the ``/usr/local/cuda`` symbolic link does **not** exist), this
  58. package is marked as **not** found.
  59. There are too many factors involved in making an automatic decision in
  60. the presence of multiple CUDA Toolkits being installed. In this
  61. situation, users are encouraged to either (1) set ``CUDAToolkit_ROOT`` or
  62. (2) ensure that the correct ``nvcc`` executable shows up in ``$PATH`` for
  63. :command:`find_program` to find.
  64. Arguments
  65. ^^^^^^^^^
  66. ``[<version>]``
  67. The ``[<version>]`` argument requests a version with which the package found
  68. should be compatible. See :ref:`find_package version format <FIND_PACKAGE_VERSION_FORMAT>`
  69. for more details.
  70. Options
  71. ^^^^^^^
  72. ``REQUIRED``
  73. If specified, configuration will error if a suitable CUDA Toolkit is not
  74. found.
  75. ``QUIET``
  76. If specified, the search for a suitable CUDA Toolkit will not produce any
  77. messages.
  78. ``EXACT``
  79. If specified, the CUDA Toolkit is considered found only if the exact
  80. ``VERSION`` specified is recovered.
  81. Imported Targets
  82. ^^^^^^^^^^^^^^^^
  83. An :ref:`imported target <Imported targets>` named ``CUDA::toolkit`` is provided.
  84. This module provides :ref:`Imported Targets` for each
  85. of the following libraries that are part of the CUDAToolkit:
  86. - `CUDA Runtime Library`_
  87. - `CUDA Driver Library`_
  88. - `cuBLAS`_
  89. - `cuDLA`_
  90. - `cuFile`_
  91. - `cuFFT`_
  92. - `cuRAND`_
  93. - `cuSOLVER`_
  94. - `cuSPARSE`_
  95. - `cuPTI`_
  96. - `NPP`_
  97. - `nvBLAS`_
  98. - `nvGRAPH`_
  99. - `nvJPEG`_
  100. - `nvidia-ML`_
  101. - `nvPTX Compiler`_
  102. - `nvRTC`_
  103. - `nvJitLink`_
  104. - `nvFatBin`_
  105. - `nvToolsExt`_
  106. - `nvtx3`_
  107. - `OpenCL`_
  108. - `cuLIBOS`_
  109. CUDA Runtime Library
  110. """"""""""""""""""""
  111. The CUDA Runtime library (cudart) are what most applications will typically
  112. need to link against to make any calls such as `cudaMalloc`, and `cudaFree`.
  113. Targets Created:
  114. - ``CUDA::cudart``
  115. - ``CUDA::cudart_static``
  116. CUDA Driver Library
  117. """"""""""""""""""""
  118. The CUDA Driver library (cuda) are used by applications that use calls
  119. such as `cuMemAlloc`, and `cuMemFree`.
  120. Targets Created:
  121. - ``CUDA::cuda_driver``
  122. cuBLAS
  123. """"""
  124. The `CUDA Basic Linear Algebra Subroutine`_ library.
  125. Targets Created:
  126. - ``CUDA::cublas``
  127. - ``CUDA::cublas_static``
  128. - ``CUDA::cublasLt`` starting in CUDA 10.1
  129. - ``CUDA::cublasLt_static`` starting in CUDA 10.1
  130. .. _`CUDA Basic Linear Algebra Subroutine`: https://docs.nvidia.com/cuda/cublas
  131. cuDLA
  132. """"""
  133. .. versionadded:: 3.27
  134. The `NVIDIA Tegra Deep Learning Accelerator`_ library.
  135. Targets Created:
  136. - ``CUDA::cudla`` starting in CUDA 11.6
  137. .. _`NVIDIA Tegra Deep Learning Accelerator`: https://docs.nvidia.com/cuda/cuda-for-tegra-appnote#cudla
  138. cuFile
  139. """"""
  140. .. versionadded:: 3.25
  141. The `NVIDIA GPUDirect Storage cuFile`_ library.
  142. Targets Created:
  143. - ``CUDA::cuFile`` starting in CUDA 11.4
  144. - ``CUDA::cuFile_static`` starting in CUDA 11.4
  145. - ``CUDA::cuFile_rdma`` starting in CUDA 11.4
  146. - ``CUDA::cuFile_rdma_static`` starting in CUDA 11.4
  147. .. _`NVIDIA GPUDirect Storage cuFile`: https://docs.nvidia.com/gpudirect-storage/api-reference-guide
  148. cuFFT
  149. """""
  150. The `CUDA Fast Fourier Transform`_ library.
  151. Targets Created:
  152. - ``CUDA::cufft``
  153. - ``CUDA::cufftw``
  154. - ``CUDA::cufft_static``
  155. - ``CUDA::cufft_static_nocallback`` starting in CUDA 9.2, requires CMake 3.23+
  156. - ``CUDA::cufftw_static``
  157. .. _`CUDA Fast Fourier Transform`: https://docs.nvidia.com/cuda/cufft
  158. cuRAND
  159. """"""
  160. The `CUDA random number generation`_ library.
  161. Targets Created:
  162. - ``CUDA::curand``
  163. - ``CUDA::curand_static``
  164. .. _`CUDA random number generation`: https://docs.nvidia.com/cuda/curand
  165. cuSOLVER
  166. """"""""
  167. A `GPU accelerated linear system solver`_ library.
  168. Targets Created:
  169. - ``CUDA::cusolver``
  170. - ``CUDA::cusolver_static``
  171. .. _`GPU accelerated linear system solver`: https://docs.nvidia.com/cuda/cusolver
  172. cuSPARSE
  173. """"""""
  174. The `CUDA sparse matrix`_ library.
  175. Targets Created:
  176. - ``CUDA::cusparse``
  177. - ``CUDA::cusparse_static``
  178. .. _`CUDA sparse matrix`: https://docs.nvidia.com/cuda/cusparse
  179. cupti
  180. """""
  181. The `NVIDIA CUDA Profiling Tools Interface`_.
  182. Targets Created:
  183. - ``CUDA::cupti``
  184. - ``CUDA::cupti_static``
  185. .. versionadded:: 3.27
  186. - ``CUDA::nvperf_host`` starting in CUDA 10.2
  187. - ``CUDA::nvperf_host_static`` starting in CUDA 10.2
  188. - ``CUDA::nvperf_target`` starting in CUDA 10.2
  189. - ``CUDA::pcsamplingutil`` starting in CUDA 11.3
  190. .. _`NVIDIA CUDA Profiling Tools Interface`: https://developer.nvidia.com/cupti
  191. NPP
  192. """
  193. The `NVIDIA 2D Image and Signal Processing Performance Primitives`_ libraries.
  194. Targets Created:
  195. - `nppc`:
  196. - ``CUDA::nppc``
  197. - ``CUDA::nppc_static``
  198. - `nppial`: Arithmetic and logical operation functions in `nppi_arithmetic_and_logical_operations.h`
  199. - ``CUDA::nppial``
  200. - ``CUDA::nppial_static``
  201. - `nppicc`: Color conversion and sampling functions in `nppi_color_conversion.h`
  202. - ``CUDA::nppicc``
  203. - ``CUDA::nppicc_static``
  204. - `nppicom`: JPEG compression and decompression functions in `nppi_compression_functions.h`
  205. Removed starting in CUDA 11.0, use `nvJPEG`_ instead.
  206. - ``CUDA::nppicom``
  207. - ``CUDA::nppicom_static``
  208. - `nppidei`: Data exchange and initialization functions in `nppi_data_exchange_and_initialization.h`
  209. - ``CUDA::nppidei``
  210. - ``CUDA::nppidei_static``
  211. - `nppif`: Filtering and computer vision functions in `nppi_filter_functions.h`
  212. - ``CUDA::nppif``
  213. - ``CUDA::nppif_static``
  214. - `nppig`: Geometry transformation functions found in `nppi_geometry_transforms.h`
  215. - ``CUDA::nppig``
  216. - ``CUDA::nppig_static``
  217. - `nppim`: Morphological operation functions found in `nppi_morphological_operations.h`
  218. - ``CUDA::nppim``
  219. - ``CUDA::nppim_static``
  220. - `nppist`: Statistics and linear transform in `nppi_statistics_functions.h` and `nppi_linear_transforms.h`
  221. - ``CUDA::nppist``
  222. - ``CUDA::nppist_static``
  223. - `nppisu`: Memory support functions in `nppi_support_functions.h`
  224. - ``CUDA::nppisu``
  225. - ``CUDA::nppisu_static``
  226. - `nppitc`: Threshold and compare operation functions in `nppi_threshold_and_compare_operations.h`
  227. - ``CUDA::nppitc``
  228. - ``CUDA::nppitc_static``
  229. - `npps`:
  230. - ``CUDA::npps``
  231. - ``CUDA::npps_static``
  232. .. _`NVIDIA 2D Image and Signal Processing Performance Primitives`: https://docs.nvidia.com/cuda/npp
  233. nvBLAS
  234. """"""
  235. The `GPU-accelerated drop-in BLAS`_ library.
  236. This is a shared library only.
  237. Targets Created:
  238. - ``CUDA::nvblas``
  239. .. _`GPU-accelerated drop-in BLAS`: https://docs.nvidia.com/cuda/nvblas
  240. nvGRAPH
  241. """""""
  242. A `GPU-accelerated graph analytics`_ library.
  243. Removed starting in CUDA 11.0
  244. Targets Created:
  245. - ``CUDA::nvgraph``
  246. - ``CUDA::nvgraph_static``
  247. .. _`GPU-accelerated graph analytics`: https://docs.nvidia.com/cuda/archive/10.0/nvgraph
  248. nvJPEG
  249. """"""
  250. A `GPU-accelerated JPEG codec`_ library.
  251. Introduced in CUDA 10.
  252. Targets Created:
  253. - ``CUDA::nvjpeg``
  254. - ``CUDA::nvjpeg_static``
  255. .. _`GPU-accelerated JPEG codec`: https://docs.nvidia.com/cuda/nvjpeg
  256. nvPTX Compiler
  257. """"""""""""""
  258. .. versionadded:: 3.25
  259. The `PTX Compiler APIs`_.
  260. These are a set of APIs which can be used to compile a PTX program into GPU assembly code.
  261. Introduced in CUDA 11.1
  262. This is a static library only.
  263. Targets Created:
  264. - ``CUDA::nvptxcompiler_static`` starting in CUDA 11.1
  265. .. _`PTX Compiler APIs`: https://docs.nvidia.com/cuda/ptx-compiler-api
  266. nvRTC
  267. """""
  268. A `runtime compilation library for CUDA`_.
  269. Targets Created:
  270. - ``CUDA::nvrtc``
  271. .. versionadded:: 3.26
  272. - ``CUDA::nvrtc_builtins``
  273. - ``CUDA::nvrtc_static`` starting in CUDA 11.5
  274. - ``CUDA::nvrtc_builtins_static`` starting in CUDA 11.5
  275. .. _`runtime compilation library for CUDA`: https://docs.nvidia.com/cuda/nvrtc
  276. nvJitLink
  277. """""""""
  278. The `JIT Link APIs`_.
  279. Targets Created:
  280. - ``CUDA::nvJitLink`` starting in CUDA 12.0
  281. - ``CUDA::nvJitLink_static`` starting in CUDA 12.0
  282. .. _`JIT Link APIs`: https://docs.nvidia.com/cuda/nvjitlink
  283. nvFatBin
  284. """""""""
  285. .. versionadded:: 3.30
  286. The `Fatbin Creator APIs`_.
  287. Targets Created:
  288. - ``CUDA::nvfatbin`` starting in CUDA 12.4
  289. - ``CUDA::nvfatbin_static`` starting in CUDA 12.4
  290. .. _`Fatbin Creator APIs`: https://docs.nvidia.com/cuda/nvfatbin
  291. nvidia-ML
  292. """""""""
  293. The `NVIDIA Management Library`_.
  294. Targets Created:
  295. - ``CUDA::nvml``
  296. - ``CUDA::nvml_static`` starting in CUDA 12.4
  297. .. versionadded:: 3.31
  298. Added ``CUDA::nvml_static``.
  299. .. _`NVIDIA Management Library`: https://developer.nvidia.com/management-library-nvml
  300. .. _`FindCUDAToolkit_nvToolsExt`:
  301. nvToolsExt
  302. """"""""""
  303. .. deprecated:: 3.25
  304. With CUDA 10.0+, use `nvtx3`_.
  305. Starting in CUDA 12.9 the `nvToolsExt` library no longer exists
  306. The `legacy NVIDIA Tools Extension`_.
  307. This is a shared library only.
  308. Targets Created:
  309. - ``CUDA::nvToolsExt``
  310. .. _`legacy NVIDIA Tools Extension`: https://docs.nvidia.com/cuda/archive/9.0/profiler-users-guide#nvtx
  311. .. _`FindCUDAToolkit_nvtx3`:
  312. nvtx3
  313. """""
  314. .. versionadded:: 3.25
  315. The header-only `NVIDIA Tools Extension`_ library.
  316. Introduced in CUDA 10.0.
  317. Targets created:
  318. - ``CUDA::nvtx3``
  319. - ``CUDA::nvtx3_interop``
  320. .. versionadded:: 4.1
  321. This is provided by CUDA 12.9 and above for use by languages that
  322. cannot consume C++ header-only libraries, such as ``Fortran``.
  323. .. _`NVIDIA Tools Extension`: https://nvidia.github.io/NVTX/doxygen
  324. OpenCL
  325. """"""
  326. The `NVIDIA Open Computing Language`_ library.
  327. This is a shared library only.
  328. Targets Created:
  329. - ``CUDA::OpenCL``
  330. .. _`NVIDIA Open Computing Language`: https://developer.nvidia.com/opencl
  331. cuLIBOS
  332. """""""
  333. The cuLIBOS library is a backend thread abstraction layer library which is
  334. static only. The ``CUDA::cublas_static``, ``CUDA::cusparse_static``,
  335. ``CUDA::cufft_static``, ``CUDA::curand_static``, and (when implemented) NPP
  336. libraries all automatically have this dependency linked.
  337. Target Created:
  338. - ``CUDA::culibos``
  339. **Note**: direct usage of this target by consumers should not be necessary.
  340. Result variables
  341. ^^^^^^^^^^^^^^^^
  342. ``CUDAToolkit_FOUND``
  343. A boolean specifying whether or not the CUDA Toolkit was found.
  344. ``CUDAToolkit_VERSION``
  345. The exact version of the CUDA Toolkit found (as reported by
  346. ``nvcc --version``, ``version.txt``, or ``version.json``).
  347. ``CUDAToolkit_VERSION_MAJOR``
  348. The major version of the CUDA Toolkit.
  349. ``CUDAToolkit_VERSION_MINOR``
  350. The minor version of the CUDA Toolkit.
  351. ``CUDAToolkit_VERSION_PATCH``
  352. The patch version of the CUDA Toolkit.
  353. ``CUDAToolkit_BIN_DIR``
  354. The path to the CUDA Toolkit library directory that contains the CUDA
  355. executable ``nvcc``.
  356. ``CUDAToolkit_INCLUDE_DIRS``
  357. List of paths to all the CUDA Toolkit folders containing header files
  358. required to compile a project linking against CUDA.
  359. ``CUDAToolkit_LIBRARY_DIR``
  360. The path to the CUDA Toolkit library directory that contains the CUDA
  361. Runtime library ``cudart``.
  362. ``CUDAToolkit_LIBRARY_ROOT``
  363. .. versionadded:: 3.18
  364. The path to the CUDA Toolkit directory containing the nvvm directory and
  365. either version.txt or version.json.
  366. ``CUDAToolkit_TARGET_DIR``
  367. The path to the CUDA Toolkit directory including the target architecture
  368. when cross-compiling. When not cross-compiling this will be equivalent to
  369. the parent directory of ``CUDAToolkit_BIN_DIR``.
  370. ``CUDAToolkit_NVCC_EXECUTABLE``
  371. The path to the NVIDIA CUDA compiler ``nvcc``. Note that this path may
  372. **not** be the same as
  373. :variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>`. ``nvcc`` must be
  374. found to determine the CUDA Toolkit version as well as determining other
  375. features of the Toolkit. This variable is set for the convenience of
  376. modules that depend on this one.
  377. #]=======================================================================]
  378. # NOTE: much of this was simply extracted from FindCUDA.cmake.
  379. # James Bigler, NVIDIA Corp (nvidia.com - jbigler)
  380. # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
  381. #
  382. # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
  383. #
  384. # Copyright (c) 2007-2009
  385. # Scientific Computing and Imaging Institute, University of Utah
  386. #
  387. # This code is licensed under the MIT License. See the FindCUDA.cmake script
  388. # for the text of the license.
  389. # The MIT License
  390. #
  391. # License for the specific language governing rights and limitations under
  392. # Permission is hereby granted, free of charge, to any person obtaining a
  393. # copy of this software and associated documentation files (the "Software"),
  394. # to deal in the Software without restriction, including without limitation
  395. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  396. # and/or sell copies of the Software, and to permit persons to whom the
  397. # Software is furnished to do so, subject to the following conditions:
  398. #
  399. # The above copyright notice and this permission notice shall be included
  400. # in all copies or substantial portions of the Software.
  401. #
  402. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  403. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  404. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  405. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  406. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  407. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  408. # DEALINGS IN THE SOFTWARE.
  409. #
  410. ###############################################################################
  411. function(_CUDAToolkit_build_include_dirs result_variable default_paths_variable)
  412. set(content "${${default_paths_variable}}")
  413. set(${result_variable} "${content}" PARENT_SCOPE)
  414. endfunction()
  415. function(_CUDAToolkit_build_library_dirs result_variable default_paths_variable)
  416. set(content "${${default_paths_variable}}")
  417. set(${result_variable} "${content}" PARENT_SCOPE)
  418. endfunction()
  419. # The toolkit is located during compiler detection for CUDA and stored in CMakeCUDACompiler.cmake as
  420. # - CMAKE_CUDA_COMPILER_TOOLKIT_ROOT
  421. # - CMAKE_CUDA_COMPILER_LIBRARY_ROOT
  422. # - CMAKE_CUDA_COMPILER_LIBRARY_DIRECTORIES_FROM_IMPLICIT_LIBRARIES
  423. # - CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES
  424. # We compute the rest based on those here to avoid re-searching and to avoid finding a possibly
  425. # different installation.
  426. if(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT)
  427. set(CUDAToolkit_ROOT_DIR "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}")
  428. set(CUDAToolkit_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_LIBRARY_ROOT}")
  429. _CUDAToolkit_build_library_dirs(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES)
  430. _CUDAToolkit_build_include_dirs(CUDAToolkit_INCLUDE_DIRECTORIES CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES)
  431. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_ROOT_DIR}/bin")
  432. set(CUDAToolkit_NVCC_EXECUTABLE "${CUDAToolkit_BIN_DIR}/nvcc${CMAKE_EXECUTABLE_SUFFIX}")
  433. set(CUDAToolkit_VERSION "${CMAKE_CUDA_COMPILER_TOOLKIT_VERSION}")
  434. if(CUDAToolkit_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  435. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  436. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  437. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  438. endif()
  439. else()
  440. function(_CUDAToolkit_find_root_dir )
  441. cmake_parse_arguments(arg "COMPILER_PATHS" "" "SEARCH_PATHS;FIND_FLAGS" ${ARGN})
  442. if(NOT CUDAToolkit_BIN_DIR)
  443. if(arg_COMPILER_PATHS)
  444. # need to find parent dir, since this could clang and not nvcc
  445. if(EXISTS "${CMAKE_CUDA_COMPILER}")
  446. get_filename_component(possible_nvcc_path "${CMAKE_CUDA_COMPILER}" PROGRAM PROGRAM_ARGS CUDAToolkit_compiler_args)
  447. get_filename_component(possible_nvcc_path "${possible_nvcc_path}" DIRECTORY)
  448. elseif(EXISTS "$ENV{CUDACXX}")
  449. get_filename_component(possible_nvcc_path "$ENV{CUDACXX}" PROGRAM PROGRAM_ARGS CUDAToolkit_compiler_args)
  450. get_filename_component(possible_nvcc_path "${possible_nvcc_path}" DIRECTORY)
  451. endif()
  452. if(possible_nvcc_path)
  453. find_program(CUDAToolkit_NVCC_EXECUTABLE
  454. NAMES nvcc nvcc.exe
  455. NO_DEFAULT_PATH
  456. PATHS ${possible_nvcc_path}
  457. )
  458. endif()
  459. endif()
  460. if(NOT CUDAToolkit_SENTINEL_FILE)
  461. find_program(CUDAToolkit_NVCC_EXECUTABLE
  462. NAMES nvcc nvcc.exe
  463. PATHS ${arg_SEARCH_PATHS}
  464. ${arg_FIND_FLAGS}
  465. )
  466. endif()
  467. if(NOT CUDAToolkit_NVCC_EXECUTABLE)
  468. find_file(CUDAToolkit_SENTINEL_FILE
  469. NAMES version.txt version.json
  470. PATHS ${arg_SEARCH_PATHS}
  471. NO_DEFAULT_PATH
  472. )
  473. endif()
  474. if(EXISTS "${CUDAToolkit_NVCC_EXECUTABLE}")
  475. # If NVCC exists then invoke it to find the toolkit location.
  476. # This allows us to support wrapper scripts (e.g. ccache or colornvcc), CUDA Toolkit,
  477. # NVIDIA HPC SDK, and distro's splayed layouts
  478. execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda"
  479. OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT)
  480. message(CONFIGURE_LOG
  481. "Executed nvcc to extract CUDAToolkit information:\n${_CUDA_NVCC_OUT}\n\n")
  482. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ TOP=([^\r\n]*)")
  483. get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}/bin" ABSOLUTE)
  484. message(CONFIGURE_LOG
  485. "Parsed CUDAToolkit nvcc location:\n${CUDAToolkit_BIN_DIR}\n\n")
  486. else()
  487. get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY)
  488. endif()
  489. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ INCLUDES=([^\r\n]*)")
  490. separate_arguments(_nvcc_output NATIVE_COMMAND "${CMAKE_MATCH_1}")
  491. foreach(line IN LISTS _nvcc_output)
  492. string(REGEX REPLACE "^-I" "" line "${line}")
  493. get_filename_component(line "${line}" ABSOLUTE)
  494. list(APPEND _cmake_CUDAToolkit_include_directories "${line}")
  495. endforeach()
  496. endif()
  497. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ SYSTEM_INCLUDES=([^\r\n]*)")
  498. unset(_nvcc_output)
  499. separate_arguments(_nvcc_output NATIVE_COMMAND "${CMAKE_MATCH_1}")
  500. foreach(line IN LISTS _nvcc_output)
  501. string(REGEX REPLACE "^-isystem" "" line "${line}")
  502. if(line)
  503. get_filename_component(line "${line}" ABSOLUTE)
  504. list(APPEND _cmake_CUDAToolkit_include_directories "${line}")
  505. endif()
  506. endforeach()
  507. endif()
  508. if(DEFINED _cmake_CUDAToolkit_include_directories)
  509. message(CONFIGURE_LOG
  510. "Parsed CUDAToolkit nvcc implicit include information:\n${_cmake_CUDAToolkit_include_directories}\n\n")
  511. set(_cmake_CUDAToolkit_include_directories "${_cmake_CUDAToolkit_include_directories}" CACHE INTERNAL "CUDAToolkit internal list of include directories")
  512. endif()
  513. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ LIBRARIES=([^\r\n]*)")
  514. include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
  515. set(_nvcc_link_line "cuda-fake-ld ${CMAKE_MATCH_1}")
  516. CMAKE_PARSE_IMPLICIT_LINK_INFO("${_nvcc_link_line}"
  517. _cmake_CUDAToolkit_implicit_link_libs
  518. _cmake_CUDAToolkit_implicit_link_directories
  519. _cmake_CUDAToolkit_implicit_frameworks
  520. _nvcc_log
  521. "${CMAKE_CUDA_IMPLICIT_OBJECT_REGEX}"
  522. LANGUAGE CUDA)
  523. message(CONFIGURE_LOG
  524. "Parsed CUDAToolkit nvcc implicit link information:\n${_nvcc_log}\n${_cmake_CUDAToolkit_implicit_link_directories}\n\n")
  525. unset(_nvcc_link_line)
  526. unset(_cmake_CUDAToolkit_implicit_link_libs)
  527. unset(_cmake_CUDAToolkit_implicit_frameworks)
  528. set(_cmake_CUDAToolkit_implicit_link_directories "${_cmake_CUDAToolkit_implicit_link_directories}" CACHE INTERNAL "CUDAToolkit internal list of implicit link directories")
  529. endif()
  530. unset(_CUDA_NVCC_OUT)
  531. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
  532. mark_as_advanced(CUDAToolkit_BIN_DIR)
  533. endif()
  534. if(CUDAToolkit_SENTINEL_FILE)
  535. get_filename_component(CUDAToolkit_BIN_DIR ${CUDAToolkit_SENTINEL_FILE} DIRECTORY ABSOLUTE)
  536. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}/bin")
  537. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
  538. mark_as_advanced(CUDAToolkit_BIN_DIR)
  539. endif()
  540. endif()
  541. if(DEFINED _cmake_CUDAToolkit_include_directories)
  542. _CUDAToolkit_build_include_dirs(_cmake_CUDAToolkit_contents _cmake_CUDAToolkit_include_directories)
  543. set(CUDAToolkit_INCLUDE_DIRECTORIES "${_cmake_CUDAToolkit_contents}" PARENT_SCOPE)
  544. endif()
  545. if(DEFINED _cmake_CUDAToolkit_implicit_link_directories)
  546. _CUDAToolkit_build_library_dirs(_cmake_CUDAToolkit_contents _cmake_CUDAToolkit_implicit_link_directories)
  547. set(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES "${_cmake_CUDAToolkit_contents}" PARENT_SCOPE)
  548. endif()
  549. if(CUDAToolkit_BIN_DIR)
  550. get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE)
  551. set(CUDAToolkit_ROOT_DIR "${CUDAToolkit_ROOT_DIR}" PARENT_SCOPE)
  552. endif()
  553. endfunction()
  554. function(_CUDAToolkit_find_version_file result_variable)
  555. # We first check for a non-scattered installation to prefer it over a scattered installation.
  556. set(version_files version.txt version.json)
  557. foreach(vf IN LISTS version_files)
  558. if(CUDAToolkit_ROOT AND EXISTS "${CUDAToolkit_ROOT}/${vf}")
  559. set(${result_variable} "${CUDAToolkit_ROOT}/${vf}" PARENT_SCOPE)
  560. break()
  561. elseif(CUDAToolkit_ROOT_DIR AND EXISTS "${CUDAToolkit_ROOT_DIR}/${vf}")
  562. set(${result_variable} "${CUDAToolkit_ROOT_DIR}/${vf}" PARENT_SCOPE)
  563. break()
  564. elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/${vf}")
  565. set(${result_variable} "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/${vf}" PARENT_SCOPE)
  566. break()
  567. elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/${vf}")
  568. set(${result_variable} "${CMAKE_SYSROOT}/usr/lib/cuda/${vf}" PARENT_SCOPE)
  569. break()
  570. endif()
  571. endforeach()
  572. endfunction()
  573. function(_CUDAToolkit_parse_version_file version_file)
  574. if(version_file)
  575. file(READ "${version_file}" file_contents)
  576. cmake_path(GET version_file EXTENSION LAST_ONLY version_ext)
  577. if(version_ext STREQUAL ".json")
  578. string(JSON cuda_version_info GET "${file_contents}" "cuda" "version")
  579. set(cuda_version_match_regex [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  580. elseif(version_ext STREQUAL ".txt")
  581. set(cuda_version_info "${file_contents}")
  582. set(cuda_version_match_regex [=[CUDA Version ([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  583. endif()
  584. if(cuda_version_info MATCHES "${cuda_version_match_regex}")
  585. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
  586. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
  587. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}" PARENT_SCOPE)
  588. set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" PARENT_SCOPE)
  589. endif()
  590. endif()
  591. endfunction()
  592. # For NVCC we can easily deduce the SDK binary directory from the compiler path.
  593. if(CMAKE_CUDA_COMPILER_LOADED AND NOT CUDAToolkit_BIN_DIR AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
  594. get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_CUDA_COMPILER}" DIRECTORY)
  595. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "")
  596. # Try language provided path first.
  597. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_BIN_DIR}" FIND_FLAGS NO_DEFAULT_PATH)
  598. mark_as_advanced(CUDAToolkit_BIN_DIR)
  599. endif()
  600. # Try user provided path
  601. _CUDAToolkit_find_root_dir(COMPILER_PATHS)
  602. if(NOT CUDAToolkit_ROOT_DIR AND CUDAToolkit_ROOT)
  603. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_ROOT}" FIND_FLAGS PATH_SUFFIXES bin NO_DEFAULT_PATH)
  604. endif()
  605. if(NOT CUDAToolkit_ROOT_DIR)
  606. _CUDAToolkit_find_root_dir(FIND_FLAGS PATHS ENV CUDA_PATH PATH_SUFFIXES bin)
  607. endif()
  608. # If the user specified CUDAToolkit_ROOT but the toolkit could not be found, this is an error.
  609. if(NOT CUDAToolkit_ROOT_DIR AND (DEFINED CUDAToolkit_ROOT OR DEFINED ENV{CUDAToolkit_ROOT}))
  610. # Declare error messages now, print later depending on find_package args.
  611. set(fail_base "Could not find nvcc executable in path specified by")
  612. set(cuda_root_fail "${fail_base} CUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
  613. set(env_cuda_root_fail "${fail_base} environment variable CUDAToolkit_ROOT=$ENV{CUDAToolkit_ROOT}")
  614. if(CUDAToolkit_FIND_REQUIRED)
  615. if(DEFINED CUDAToolkit_ROOT)
  616. message(FATAL_ERROR ${cuda_root_fail})
  617. elseif(DEFINED ENV{CUDAToolkit_ROOT})
  618. message(FATAL_ERROR ${env_cuda_root_fail})
  619. endif()
  620. else()
  621. if(NOT CUDAToolkit_FIND_QUIETLY)
  622. if(DEFINED CUDAToolkit_ROOT)
  623. message(STATUS ${cuda_root_fail})
  624. elseif(DEFINED ENV{CUDAToolkit_ROOT})
  625. message(STATUS ${env_cuda_root_fail})
  626. endif()
  627. endif()
  628. set(CUDAToolkit_FOUND FALSE)
  629. unset(fail_base)
  630. unset(cuda_root_fail)
  631. unset(env_cuda_root_fail)
  632. return()
  633. endif()
  634. endif()
  635. # CUDAToolkit_ROOT cmake / env variable not specified, try platform defaults.
  636. #
  637. # - Linux: /usr/local/cuda-X.Y
  638. # - macOS: /Developer/NVIDIA/CUDA-X.Y
  639. # - Windows: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y
  640. #
  641. # We will also search the default symlink location /usr/local/cuda first since
  642. # if CUDAToolkit_ROOT is not specified, it is assumed that the symlinked
  643. # directory is the desired location.
  644. if(NOT CUDAToolkit_ROOT_DIR)
  645. if(UNIX)
  646. if(NOT APPLE)
  647. set(platform_base "/usr/local/cuda-")
  648. else()
  649. set(platform_base "/Developer/NVIDIA/CUDA-")
  650. endif()
  651. else()
  652. set(platform_base "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v")
  653. endif()
  654. # Build out a descending list of possible cuda installations, e.g.
  655. file(GLOB possible_paths "${platform_base}*")
  656. # Iterate the glob results and create a descending list.
  657. set(versions)
  658. foreach(p ${possible_paths})
  659. # Extract version number from end of string
  660. string(REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${p})
  661. if(IS_DIRECTORY ${p} AND p_version)
  662. list(APPEND versions ${p_version})
  663. endif()
  664. endforeach()
  665. # Sort numerically in descending order, so we try the newest versions first.
  666. list(SORT versions COMPARE NATURAL ORDER DESCENDING)
  667. # With a descending list of versions, populate possible paths to search.
  668. set(search_paths)
  669. foreach(v ${versions})
  670. list(APPEND search_paths "${platform_base}${v}")
  671. endforeach()
  672. # Force the global default /usr/local/cuda to the front on Unix.
  673. if(UNIX)
  674. list(INSERT search_paths 0 "/usr/local/cuda")
  675. endif()
  676. # Now search for the toolkit again using the platform default search paths.
  677. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${search_paths}" FIND_FLAGS PATH_SUFFIXES bin)
  678. # We are done with these variables now, cleanup for caller.
  679. unset(platform_base)
  680. unset(possible_paths)
  681. unset(versions)
  682. unset(search_paths)
  683. if(NOT CUDAToolkit_ROOT_DIR)
  684. if(CUDAToolkit_FIND_REQUIRED)
  685. message(FATAL_ERROR "Could not find nvcc, please set CUDAToolkit_ROOT.")
  686. elseif(NOT CUDAToolkit_FIND_QUIETLY)
  687. message(STATUS "Could not find nvcc, please set CUDAToolkit_ROOT.")
  688. endif()
  689. set(CUDAToolkit_FOUND FALSE)
  690. return()
  691. endif()
  692. endif()
  693. _CUDAToolkit_find_version_file( _CUDAToolkit_version_file )
  694. if(_CUDAToolkit_version_file)
  695. # CUDAToolkit_LIBRARY_ROOT contains the device library and version file.
  696. get_filename_component(CUDAToolkit_LIBRARY_ROOT "${_CUDAToolkit_version_file}" DIRECTORY ABSOLUTE)
  697. endif()
  698. unset(_CUDAToolkit_version_file)
  699. if(CUDAToolkit_NVCC_EXECUTABLE AND
  700. CMAKE_CUDA_COMPILER_VERSION AND
  701. CUDAToolkit_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER)
  702. # Need to set these based off the already computed CMAKE_CUDA_COMPILER_VERSION value
  703. # This if statement will always match, but is used to provide variables for MATCH 1,2,3...
  704. if(CMAKE_CUDA_COMPILER_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  705. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  706. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  707. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  708. set(CUDAToolkit_VERSION "${CMAKE_CUDA_COMPILER_VERSION}")
  709. endif()
  710. elseif(CUDAToolkit_NVCC_EXECUTABLE)
  711. # Compute the version by invoking nvcc
  712. execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
  713. if(NVCC_OUT MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  714. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  715. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  716. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  717. set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  718. endif()
  719. unset(NVCC_OUT)
  720. else()
  721. _CUDAToolkit_find_version_file(version_file)
  722. _CUDAToolkit_parse_version_file("${version_file}")
  723. endif()
  724. endif()
  725. # Find target directory when crosscompiling.
  726. if(CMAKE_CROSSCOMPILING)
  727. # When a language is enabled we can use its compiler's target architecture.
  728. if(CMAKE_CUDA_COMPILER_LOADED AND CMAKE_CUDA_COMPILER_ARCHITECTURE_ID)
  729. set(_CUDA_TARGET_PROCESSOR "${CMAKE_CUDA_COMPILER_ARCHITECTURE_ID}")
  730. elseif(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
  731. set(_CUDA_TARGET_PROCESSOR "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
  732. elseif(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ARCHITECTURE_ID)
  733. set(_CUDA_TARGET_PROCESSOR "${CMAKE_C_COMPILER_ARCHITECTURE_ID}")
  734. elseif(CMAKE_SYSTEM_PROCESSOR)
  735. set(_CUDA_TARGET_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
  736. else()
  737. message(FATAL_ERROR "Cross-compiling with the CUDA toolkit requires CMAKE_SYSTEM_PROCESSOR to be set.")
  738. endif()
  739. # Keep in sync with equivalent table in CMakeDetermineCUDACompiler and FindCUDA!
  740. if(_CUDA_TARGET_PROCESSOR STREQUAL "armv7-a")
  741. # Support for NVPACK
  742. set(CUDAToolkit_TARGET_NAMES "armv7-linux-androideabi")
  743. elseif(_CUDA_TARGET_PROCESSOR MATCHES "arm")
  744. set(CUDAToolkit_TARGET_NAMES "armv7-linux-gnueabihf")
  745. elseif(_CUDA_TARGET_PROCESSOR MATCHES "aarch64")
  746. if(ANDROID_ARCH_NAME STREQUAL "arm64")
  747. set(CUDAToolkit_TARGET_NAMES "aarch64-linux-androideabi")
  748. elseif (CMAKE_SYSTEM_NAME STREQUAL "QNX")
  749. set(CUDAToolkit_TARGET_NAMES "aarch64-qnx")
  750. else()
  751. set(CUDAToolkit_TARGET_NAMES "aarch64-linux" "sbsa-linux")
  752. endif()
  753. elseif(_CUDA_TARGET_PROCESSOR STREQUAL "x86_64")
  754. set(CUDAToolkit_TARGET_NAMES "x86_64-linux")
  755. endif()
  756. unset(_CUDA_TARGET_PROCESSOR)
  757. foreach(CUDAToolkit_TARGET_NAME IN LISTS CUDAToolkit_TARGET_NAMES)
  758. if(EXISTS "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
  759. set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
  760. # add known CUDA target root path to the set of directories we search for programs, libraries and headers
  761. list(PREPEND CMAKE_FIND_ROOT_PATH "${CUDAToolkit_TARGET_DIR}")
  762. # Mark that we need to pop the root search path changes after we have
  763. # found all cuda libraries so that searches for our cross-compilation
  764. # libraries work when another cuda sdk is in CMAKE_PREFIX_PATH or
  765. # PATh
  766. set(_CUDAToolkit_Pop_ROOT_PATH True)
  767. break()
  768. endif()
  769. endforeach()
  770. endif()
  771. # Determine windows search path suffix for libraries
  772. if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
  773. if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
  774. set(_CUDAToolkit_win_search_dirs lib/x64)
  775. set(_CUDAToolkit_win_stub_search_dirs lib/x64/stubs)
  776. endif()
  777. endif()
  778. # If not already set we can simply use the toolkit root or it's a scattered installation.
  779. if(NOT CUDAToolkit_TARGET_DIR)
  780. # Not cross compiling
  781. set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}")
  782. # Now that we have the real ROOT_DIR, find components inside it.
  783. list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR})
  784. # Mark that we need to pop the prefix path changes after we have
  785. # found the cudart library.
  786. set(_CUDAToolkit_Pop_Prefix True)
  787. endif()
  788. # We don't need to verify the cuda_runtime header when we are using `nvcc` include paths
  789. # as the compiler being enabled means the header was found
  790. if(NOT CUDAToolkit_INCLUDE_DIRECTORIES)
  791. # Otherwise use CUDAToolkit_TARGET_DIR to guess where the `cuda_runtime.h` is located
  792. # On a scattered installation /usr, on a non-scattered something like /usr/local/cuda or /usr/local/cuda-10.2/targets/aarch64-linux.
  793. if(EXISTS "${CUDAToolkit_TARGET_DIR}/include/cuda_runtime.h")
  794. set(CUDAToolkit_INCLUDE_DIRECTORIES "${CUDAToolkit_TARGET_DIR}/include")
  795. else()
  796. message(STATUS "Unable to find cuda_runtime.h in \"${CUDAToolkit_TARGET_DIR}/include\" for CUDAToolkit_INCLUDE_DIRECTORIES.")
  797. endif()
  798. endif()
  799. # The NVHPC layout moves math library headers and libraries to a sibling directory and it could be nested under
  800. # the version of the CUDA toolchain
  801. # Create a separate variable so this directory can be selectively added to math targets.
  802. find_path(CUDAToolkit_CUBLAS_INCLUDE_DIR cublas_v2.h PATHS
  803. ${CUDAToolkit_INCLUDE_DIRECTORIES}
  804. NO_DEFAULT_PATH)
  805. if(NOT CUDAToolkit_CUBLAS_INCLUDE_DIR)
  806. file(REAL_PATH "${CUDAToolkit_TARGET_DIR}" CUDAToolkit_MATH_INCLUDE_DIR)
  807. cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "../../math_libs/")
  808. if(EXISTS "${CUDAToolkit_MATH_INCLUDE_DIR}/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/")
  809. cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/")
  810. endif()
  811. cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "include")
  812. cmake_path(NORMAL_PATH CUDAToolkit_MATH_INCLUDE_DIR)
  813. find_path(CUDAToolkit_CUBLAS_INCLUDE_DIR cublas_v2.h PATHS
  814. ${CUDAToolkit_INCLUDE_DIRECTORIES}
  815. )
  816. if(CUDAToolkit_CUBLAS_INCLUDE_DIR)
  817. list(APPEND CUDAToolkit_INCLUDE_DIRECTORIES "${CUDAToolkit_CUBLAS_INCLUDE_DIR}")
  818. endif()
  819. endif()
  820. unset(CUDAToolkit_CUBLAS_INCLUDE_DIR CACHE)
  821. unset(CUDAToolkit_CUBLAS_INCLUDE_DIR)
  822. # Find the CUDA Runtime Library libcudart
  823. find_library(CUDA_CUDART
  824. NAMES cudart
  825. PATHS ${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES}
  826. PATH_SUFFIXES lib64 ${_CUDAToolkit_win_search_dirs}
  827. )
  828. find_library(CUDA_CUDART
  829. NAMES cudart
  830. PATHS ${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES}
  831. PATH_SUFFIXES lib64/stubs ${_CUDAToolkit_win_stub_search_dirs} lib/stubs stubs
  832. )
  833. if(NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY)
  834. message(STATUS "Unable to find cudart library.")
  835. endif()
  836. if(_CUDAToolkit_Pop_Prefix)
  837. list(REMOVE_AT CMAKE_PREFIX_PATH -1)
  838. unset(_CUDAToolkit_Pop_Prefix)
  839. endif()
  840. #-----------------------------------------------------------------------------
  841. # Perform version comparison and validate all required variables are set.
  842. include(FindPackageHandleStandardArgs)
  843. find_package_handle_standard_args(CUDAToolkit
  844. REQUIRED_VARS
  845. CUDAToolkit_INCLUDE_DIRECTORIES
  846. CUDA_CUDART
  847. CUDAToolkit_BIN_DIR
  848. VERSION_VAR
  849. CUDAToolkit_VERSION
  850. )
  851. unset(CUDAToolkit_ROOT_DIR)
  852. mark_as_advanced(CUDA_CUDART
  853. CUDAToolkit_NVCC_EXECUTABLE
  854. CUDAToolkit_SENTINEL_FILE
  855. )
  856. #-----------------------------------------------------------------------------
  857. # Construct result variables
  858. if(CUDAToolkit_FOUND)
  859. set(CUDAToolkit_INCLUDE_DIRS "${CUDAToolkit_INCLUDE_DIRECTORIES}")
  860. get_filename_component(CUDAToolkit_LIBRARY_DIR ${CUDA_CUDART} DIRECTORY ABSOLUTE)
  861. # Build search paths without any symlinks
  862. file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}" _cmake_search_dir)
  863. set(CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}")
  864. # Detect we are in a splayed nvhpc toolkit layout and add extra
  865. # search paths without symlinks
  866. if(CUDAToolkit_LIBRARY_DIR MATCHES ".*/cuda/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/lib64$")
  867. # Search location for math_libs/
  868. block(SCOPE_FOR POLICIES)
  869. cmake_policy(SET CMP0152 NEW)
  870. file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../../../../../" _cmake_search_dir)
  871. list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}")
  872. # Search location for extras like cupti
  873. file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../../../" _cmake_search_dir)
  874. list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}")
  875. endblock()
  876. endif()
  877. if(DEFINED CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES)
  878. list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES}")
  879. endif()
  880. # If no `CUDAToolkit_LIBRARY_ROOT` exists set it based on CUDAToolkit_LIBRARY_DIR
  881. if(NOT DEFINED CUDAToolkit_LIBRARY_ROOT)
  882. foreach(CUDAToolkit_search_loc IN LISTS CUDAToolkit_LIBRARY_DIR CUDAToolkit_BIN_DIR)
  883. get_filename_component(CUDAToolkit_possible_lib_root "${CUDAToolkit_search_loc}" DIRECTORY ABSOLUTE)
  884. if(EXISTS "${CUDAToolkit_possible_lib_root}/nvvm/")
  885. set(CUDAToolkit_LIBRARY_ROOT "${CUDAToolkit_possible_lib_root}")
  886. break()
  887. endif()
  888. endforeach()
  889. unset(CUDAToolkit_search_loc)
  890. unset(CUDAToolkit_possible_lib_root)
  891. endif()
  892. else()
  893. # clear cache results when we fail
  894. unset(_cmake_CUDAToolkit_implicit_link_directories CACHE)
  895. unset(_cmake_CUDAToolkit_include_directories CACHE)
  896. unset(CUDA_CUDART CACHE)
  897. unset(CUDAToolkit_BIN_DIR CACHE)
  898. unset(CUDAToolkit_NVCC_EXECUTABLE CACHE)
  899. unset(CUDAToolkit_SENTINEL_FILE CACHE)
  900. endif()
  901. unset(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES)
  902. unset(CUDAToolkit_INCLUDE_DIRECTORIES)
  903. #-----------------------------------------------------------------------------
  904. # Construct import targets
  905. if(CUDAToolkit_FOUND)
  906. function(_CUDAToolkit_find_and_add_import_lib lib_name)
  907. cmake_parse_arguments(arg "" "" "ALT;DEPS;EXTRA_PATH_SUFFIXES;EXTRA_INCLUDE_DIRS;ONLY_SEARCH_FOR" ${ARGN})
  908. if(arg_ONLY_SEARCH_FOR)
  909. set(search_names ${arg_ONLY_SEARCH_FOR})
  910. else()
  911. set(search_names ${lib_name} ${arg_ALT})
  912. endif()
  913. find_library(CUDA_${lib_name}_LIBRARY
  914. NAMES ${search_names}
  915. HINTS ${CUDAToolkit_LIBRARY_SEARCH_DIRS}
  916. ENV CUDA_PATH
  917. PATH_SUFFIXES nvidia/current lib64 ${_CUDAToolkit_win_search_dirs} lib
  918. # Support NVHPC splayed math library layout
  919. math_libs/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/lib64
  920. math_libs/lib64
  921. ${arg_EXTRA_PATH_SUFFIXES}
  922. )
  923. # Don't try any stub directories until we have exhausted all other
  924. # search locations.
  925. set(CUDA_IMPORT_PROPERTY IMPORTED_LOCATION)
  926. set(CUDA_IMPORT_TYPE UNKNOWN)
  927. if(NOT CUDA_${lib_name}_LIBRARY)
  928. find_library(CUDA_${lib_name}_LIBRARY
  929. NAMES ${search_names}
  930. HINTS ${CUDAToolkit_LIBRARY_SEARCH_DIRS}
  931. ENV CUDA_PATH
  932. PATH_SUFFIXES lib64/stubs ${_CUDAToolkit_win_stub_search_dirs} lib/stubs stubs
  933. )
  934. endif()
  935. if(CUDA_${lib_name}_LIBRARY MATCHES "/stubs/" AND NOT CUDA_${lib_name}_LIBRARY MATCHES "\\.a$" AND NOT WIN32)
  936. # Use a SHARED library with IMPORTED_IMPLIB, but not IMPORTED_LOCATION,
  937. # to indicate that the stub is for linkers but not dynamic loaders.
  938. # It will not contribute any RPATH entry. When encountered as
  939. # a private transitive dependency of another shared library,
  940. # it will be passed explicitly to linkers so they can find it
  941. # even when the runtime library file does not exist on disk.
  942. set(CUDA_IMPORT_PROPERTY IMPORTED_IMPLIB)
  943. set(CUDA_IMPORT_TYPE SHARED)
  944. endif()
  945. mark_as_advanced(CUDA_${lib_name}_LIBRARY)
  946. if (NOT TARGET CUDA::${lib_name} AND CUDA_${lib_name}_LIBRARY)
  947. add_library(CUDA::${lib_name} ${CUDA_IMPORT_TYPE} IMPORTED)
  948. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  949. if(DEFINED CUDAToolkit_MATH_INCLUDE_DIR)
  950. string(FIND ${CUDA_${lib_name}_LIBRARY} "math_libs" math_libs)
  951. if(NOT ${math_libs} EQUAL -1)
  952. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_MATH_INCLUDE_DIR}")
  953. endif()
  954. endif()
  955. set_property(TARGET CUDA::${lib_name} PROPERTY ${CUDA_IMPORT_PROPERTY} "${CUDA_${lib_name}_LIBRARY}")
  956. foreach(dep ${arg_DEPS})
  957. if(TARGET CUDA::${dep})
  958. target_link_libraries(CUDA::${lib_name} INTERFACE CUDA::${dep})
  959. endif()
  960. endforeach()
  961. if(arg_EXTRA_INCLUDE_DIRS)
  962. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${arg_EXTRA_INCLUDE_DIRS}")
  963. endif()
  964. endif()
  965. endfunction()
  966. if(NOT TARGET CUDA::toolkit)
  967. add_library(CUDA::toolkit IMPORTED INTERFACE)
  968. target_include_directories(CUDA::toolkit SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  969. target_link_directories(CUDA::toolkit INTERFACE "${CUDAToolkit_LIBRARY_DIR}")
  970. endif()
  971. # setup dependencies that are required for cudart/cudart_static when building
  972. # on linux. These are generally only required when using the CUDA toolkit
  973. # when CUDA language is disabled
  974. if(NOT TARGET CUDA::cudart_static_deps)
  975. add_library(CUDA::cudart_static_deps IMPORTED INTERFACE)
  976. if(UNIX AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
  977. find_package(Threads REQUIRED)
  978. target_link_libraries(CUDA::cudart_static_deps INTERFACE Threads::Threads ${CMAKE_DL_LIBS})
  979. endif()
  980. if(UNIX AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX"))
  981. # On Linux, you must link against librt when using the static cuda runtime.
  982. find_library(CUDAToolkit_rt_LIBRARY rt)
  983. mark_as_advanced(CUDAToolkit_rt_LIBRARY)
  984. if(NOT CUDAToolkit_rt_LIBRARY)
  985. message(WARNING "Could not find librt library, needed by CUDA::cudart_static")
  986. else()
  987. target_link_libraries(CUDA::cudart_static_deps INTERFACE ${CUDAToolkit_rt_LIBRARY})
  988. endif()
  989. endif()
  990. endif()
  991. _CUDAToolkit_find_and_add_import_lib(cuda_driver ALT cuda DEPS cudart_static_deps)
  992. _CUDAToolkit_find_and_add_import_lib(cudart DEPS cudart_static_deps)
  993. _CUDAToolkit_find_and_add_import_lib(cudart_static DEPS cudart_static_deps)
  994. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.0.0)
  995. _CUDAToolkit_find_and_add_import_lib(nvJitLink)
  996. _CUDAToolkit_find_and_add_import_lib(nvJitLink_static DEPS cudart_static_deps)
  997. endif()
  998. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.4.0)
  999. _CUDAToolkit_find_and_add_import_lib(nvfatbin DEPS cudart_static_deps)
  1000. _CUDAToolkit_find_and_add_import_lib(nvfatbin_static DEPS cudart_static_deps)
  1001. endif()
  1002. _CUDAToolkit_find_and_add_import_lib(culibos) # it's a static library
  1003. foreach (cuda_lib cublasLt cufft nvjpeg)
  1004. _CUDAToolkit_find_and_add_import_lib(${cuda_lib})
  1005. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS cudart_static_deps culibos)
  1006. endforeach()
  1007. foreach (cuda_lib curand nppc)
  1008. _CUDAToolkit_find_and_add_import_lib(${cuda_lib})
  1009. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS culibos)
  1010. endforeach()
  1011. _CUDAToolkit_find_and_add_import_lib(cusparse DEPS nvJitLink)
  1012. _CUDAToolkit_find_and_add_import_lib(cusparse_static DEPS nvJitLink_static culibos)
  1013. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.0.0)
  1014. # cublas depends on cublasLt
  1015. # https://docs.nvidia.com/cuda/archive/11.0/cublas#static-library
  1016. _CUDAToolkit_find_and_add_import_lib(cublas DEPS cublasLt culibos)
  1017. _CUDAToolkit_find_and_add_import_lib(cublas_static DEPS cublasLt_static culibos)
  1018. else()
  1019. _CUDAToolkit_find_and_add_import_lib(cublas DEPS culibos)
  1020. _CUDAToolkit_find_and_add_import_lib(cublas_static DEPS culibos)
  1021. endif()
  1022. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.4)
  1023. _CUDAToolkit_find_and_add_import_lib(cuFile ALT cufile DEPS culibos)
  1024. _CUDAToolkit_find_and_add_import_lib(cuFile_static ALT cufile_static DEPS culibos)
  1025. _CUDAToolkit_find_and_add_import_lib(cuFile_rdma ALT cufile_rdma DEPS cuFile culibos)
  1026. _CUDAToolkit_find_and_add_import_lib(cuFile_rdma_static ALT cufile_rdma_static DEPS cuFile_static culibos)
  1027. endif()
  1028. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.6)
  1029. _CUDAToolkit_find_and_add_import_lib(cudla)
  1030. endif()
  1031. # cuFFTW depends on cuFFT
  1032. _CUDAToolkit_find_and_add_import_lib(cufftw DEPS cufft)
  1033. _CUDAToolkit_find_and_add_import_lib(cufftw_static DEPS cufft_static)
  1034. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 9.2)
  1035. _CUDAToolkit_find_and_add_import_lib(cufft_static_nocallback DEPS culibos)
  1036. endif()
  1037. # cuSOLVER depends on cuBLAS, and cuSPARSE
  1038. set(cusolver_deps cublas cusparse)
  1039. set(cusolver_static_deps cublas_static cusparse_static culibos)
  1040. if(CUDAToolkit_VERSION VERSION_GREATER 11.2.1)
  1041. # cusolver depends on libcusolver_metis and cublasLt
  1042. # https://docs.nvidia.com/cuda/archive/11.2.2/cusolver#link-dependency
  1043. list(APPEND cusolver_deps cublasLt)
  1044. _CUDAToolkit_find_and_add_import_lib(cusolver_metis_static ALT metis_static) # implementation detail static lib
  1045. list(APPEND cusolver_static_deps cusolver_metis_static cublasLt_static)
  1046. endif()
  1047. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.1.2)
  1048. # cusolver depends on liblapack_static.a starting with CUDA 10.1 update 2,
  1049. # https://docs.nvidia.com/cuda/archive/11.5.0/cusolver#static-link-lapack
  1050. _CUDAToolkit_find_and_add_import_lib(cusolver_lapack_static ALT lapack_static) # implementation detail static lib
  1051. list(APPEND cusolver_static_deps cusolver_lapack_static)
  1052. endif()
  1053. _CUDAToolkit_find_and_add_import_lib(cusolver DEPS ${cusolver_deps})
  1054. _CUDAToolkit_find_and_add_import_lib(cusolver_static DEPS ${cusolver_static_deps})
  1055. unset(cusolver_deps)
  1056. unset(cusolver_static_deps)
  1057. # nvGRAPH depends on cuRAND, and cuSOLVER.
  1058. _CUDAToolkit_find_and_add_import_lib(nvgraph DEPS curand cusolver)
  1059. _CUDAToolkit_find_and_add_import_lib(nvgraph_static DEPS curand_static cusolver_static)
  1060. # Process the majority of the NPP libraries.
  1061. foreach (cuda_lib nppial nppicc nppidei nppif nppig nppim nppist nppitc npps nppicom nppisu)
  1062. _CUDAToolkit_find_and_add_import_lib(${cuda_lib} DEPS nppc)
  1063. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS nppc_static)
  1064. endforeach()
  1065. find_path(CUDAToolkit_CUPTI_INCLUDE_DIR cupti.h PATHS
  1066. "${CUDAToolkit_ROOT_DIR}/extras/CUPTI/include"
  1067. ${CUDAToolkit_INCLUDE_DIRS}
  1068. PATH_SUFFIXES "../extras/CUPTI/include"
  1069. "../../../extras/CUPTI/include"
  1070. NO_DEFAULT_PATH)
  1071. mark_as_advanced(CUDAToolkit_CUPTI_INCLUDE_DIR)
  1072. if(CUDAToolkit_CUPTI_INCLUDE_DIR)
  1073. set(_cmake_cupti_extra_paths extras/CUPTI/lib64/
  1074. extras/CUPTI/lib/
  1075. ../extras/CUPTI/lib64/
  1076. ../extras/CUPTI/lib/
  1077. ../../../extras/CUPTI/lib64/
  1078. ../../../extras/CUPTI/lib/)
  1079. _CUDAToolkit_find_and_add_import_lib(cupti
  1080. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1081. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1082. _CUDAToolkit_find_and_add_import_lib(cupti_static
  1083. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1084. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1085. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.2.0)
  1086. _CUDAToolkit_find_and_add_import_lib(nvperf_host
  1087. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1088. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1089. _CUDAToolkit_find_and_add_import_lib(nvperf_host_static
  1090. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1091. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1092. _CUDAToolkit_find_and_add_import_lib(nvperf_target
  1093. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1094. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1095. endif()
  1096. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.3.0)
  1097. _CUDAToolkit_find_and_add_import_lib(pcsamplingutil
  1098. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1099. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1100. endif()
  1101. endif()
  1102. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.1.0)
  1103. if(NOT TARGET CUDA::nvptxcompiler_static)
  1104. _CUDAToolkit_find_and_add_import_lib(nvptxcompiler_static)
  1105. if(TARGET CUDA::nvptxcompiler_static)
  1106. target_link_libraries(CUDA::nvptxcompiler_static INTERFACE CUDA::cudart_static_deps)
  1107. endif()
  1108. endif()
  1109. endif()
  1110. _CUDAToolkit_find_and_add_import_lib(nvrtc_builtins ALT nvrtc-builtins)
  1111. _CUDAToolkit_find_and_add_import_lib(nvrtc)
  1112. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.5.0)
  1113. _CUDAToolkit_find_and_add_import_lib(nvrtc_builtins_static ALT nvrtc-builtins_static)
  1114. if(NOT TARGET CUDA::nvrtc_static)
  1115. _CUDAToolkit_find_and_add_import_lib(nvrtc_static DEPS nvrtc_builtins_static nvptxcompiler_static)
  1116. if(TARGET CUDA::nvrtc_static AND WIN32 AND NOT (BORLAND OR MINGW OR CYGWIN))
  1117. target_link_libraries(CUDA::nvrtc_static INTERFACE Ws2_32.lib)
  1118. endif()
  1119. endif()
  1120. endif()
  1121. _CUDAToolkit_find_and_add_import_lib(nvml ALT nvidia-ml nvml)
  1122. _CUDAToolkit_find_and_add_import_lib(nvml_static ONLY_SEARCH_FOR libnvidia-ml.a libnvml.a)
  1123. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.0)
  1124. # Header-only variant. Uses dlopen().
  1125. if(NOT TARGET CUDA::nvtx3)
  1126. add_library(CUDA::nvtx3 INTERFACE IMPORTED)
  1127. target_include_directories(CUDA::nvtx3 SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  1128. target_link_libraries(CUDA::nvtx3 INTERFACE ${CMAKE_DL_LIBS})
  1129. endif()
  1130. endif()
  1131. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.9)
  1132. if(NOT TARGET CUDA::nvtx3_interop)
  1133. _CUDAToolkit_find_and_add_import_lib(nvtx3_interop ALT nvtx3interop)
  1134. endif()
  1135. endif()
  1136. # nvToolsExt is removed starting in 12.9
  1137. if(CUDAToolkit_VERSION VERSION_LESS 12.9)
  1138. if(WIN32)
  1139. # nvtools can be installed outside the CUDA toolkit directory
  1140. # so prefer the NVTOOLSEXT_PATH windows only environment variable
  1141. # In addition on windows the most common name is nvToolsExt64_1
  1142. find_library(CUDA_nvToolsExt_LIBRARY
  1143. NAMES nvToolsExt64_1 nvToolsExt64 nvToolsExt
  1144. PATHS ENV NVTOOLSEXT_PATH
  1145. ENV CUDA_PATH
  1146. PATH_SUFFIXES lib/x64 lib
  1147. )
  1148. endif()
  1149. _CUDAToolkit_find_and_add_import_lib(nvToolsExt ALT nvToolsExt64)
  1150. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.0)
  1151. # nvToolsExt is deprecated since nvtx3 introduction.
  1152. # Warn only if the project requires a sufficiently new CMake to make migration possible.
  1153. if(TARGET CUDA::nvToolsExt AND CMAKE_MINIMUM_REQUIRED_VERSION VERSION_GREATER_EQUAL 3.25)
  1154. set_property(TARGET CUDA::nvToolsExt PROPERTY DEPRECATION "nvToolsExt has been superseded by nvtx3 since CUDA 10.0 and CMake 3.25. Use CUDA::nvtx3 and include <nvtx3/nvToolsExt.h> instead.")
  1155. endif()
  1156. endif()
  1157. endif()
  1158. _CUDAToolkit_find_and_add_import_lib(OpenCL)
  1159. endif()
  1160. if(_CUDAToolkit_Pop_ROOT_PATH)
  1161. list(REMOVE_AT CMAKE_FIND_ROOT_PATH 0)
  1162. unset(_CUDAToolkit_Pop_ROOT_PATH)
  1163. endif()
  1164. unset(_CUDAToolkit_win_search_dirs)
  1165. unset(_CUDAToolkit_win_stub_search_dirs)