FindCUDAToolkit.cmake 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  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. This module defines the following variables:
  343. ``CUDAToolkit_FOUND``
  344. A boolean specifying whether or not the CUDA Toolkit was found.
  345. ``CUDAToolkit_VERSION``
  346. The exact version of the CUDA Toolkit found (as reported by
  347. ``nvcc --version``, ``version.txt``, or ``version.json``).
  348. ``CUDAToolkit_VERSION_MAJOR``
  349. The major version of the CUDA Toolkit.
  350. ``CUDAToolkit_VERSION_MINOR``
  351. The minor version of the CUDA Toolkit.
  352. ``CUDAToolkit_VERSION_PATCH``
  353. The patch version of the CUDA Toolkit.
  354. ``CUDAToolkit_BIN_DIR``
  355. The path to the CUDA Toolkit library directory that contains the CUDA
  356. executable ``nvcc``.
  357. ``CUDAToolkit_INCLUDE_DIRS``
  358. List of paths to all the CUDA Toolkit folders containing header files
  359. required to compile a project linking against CUDA.
  360. ``CUDAToolkit_LIBRARY_DIR``
  361. The path to the CUDA Toolkit library directory that contains the CUDA
  362. Runtime library ``cudart``.
  363. ``CUDAToolkit_LIBRARY_ROOT``
  364. .. versionadded:: 3.18
  365. The path to the CUDA Toolkit directory containing the nvvm directory and
  366. either version.txt or version.json.
  367. ``CUDAToolkit_TARGET_DIR``
  368. The path to the CUDA Toolkit directory including the target architecture
  369. when cross-compiling. When not cross-compiling this will be equivalent to
  370. the parent directory of ``CUDAToolkit_BIN_DIR``.
  371. ``CUDAToolkit_NVCC_EXECUTABLE``
  372. The path to the NVIDIA CUDA compiler ``nvcc``. Note that this path may
  373. **not** be the same as
  374. :variable:`CMAKE_CUDA_COMPILER <CMAKE_<LANG>_COMPILER>`. ``nvcc`` must be
  375. found to determine the CUDA Toolkit version as well as determining other
  376. features of the Toolkit. This variable is set for the convenience of
  377. modules that depend on this one.
  378. #]=======================================================================]
  379. # NOTE: much of this was simply extracted from FindCUDA.cmake.
  380. # James Bigler, NVIDIA Corp (nvidia.com - jbigler)
  381. # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html
  382. #
  383. # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved.
  384. #
  385. # Copyright (c) 2007-2009
  386. # Scientific Computing and Imaging Institute, University of Utah
  387. #
  388. # This code is licensed under the MIT License. See the FindCUDA.cmake script
  389. # for the text of the license.
  390. # The MIT License
  391. #
  392. # License for the specific language governing rights and limitations under
  393. # Permission is hereby granted, free of charge, to any person obtaining a
  394. # copy of this software and associated documentation files (the "Software"),
  395. # to deal in the Software without restriction, including without limitation
  396. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  397. # and/or sell copies of the Software, and to permit persons to whom the
  398. # Software is furnished to do so, subject to the following conditions:
  399. #
  400. # The above copyright notice and this permission notice shall be included
  401. # in all copies or substantial portions of the Software.
  402. #
  403. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  404. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  405. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  406. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  407. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  408. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  409. # DEALINGS IN THE SOFTWARE.
  410. #
  411. ###############################################################################
  412. function(_CUDAToolkit_build_include_dirs result_variable default_paths_variable)
  413. set(content "${${default_paths_variable}}")
  414. set(${result_variable} "${content}" PARENT_SCOPE)
  415. endfunction()
  416. function(_CUDAToolkit_build_library_dirs result_variable default_paths_variable)
  417. set(content "${${default_paths_variable}}")
  418. set(${result_variable} "${content}" PARENT_SCOPE)
  419. endfunction()
  420. # The toolkit is located during compiler detection for CUDA and stored in CMakeCUDACompiler.cmake as
  421. # - CMAKE_CUDA_COMPILER_TOOLKIT_ROOT
  422. # - CMAKE_CUDA_COMPILER_LIBRARY_ROOT
  423. # - CMAKE_CUDA_COMPILER_LIBRARY_DIRECTORIES_FROM_IMPLICIT_LIBRARIES
  424. # - CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES
  425. # We compute the rest based on those here to avoid re-searching and to avoid finding a possibly
  426. # different installation.
  427. if(CMAKE_CUDA_COMPILER_TOOLKIT_ROOT)
  428. set(CUDAToolkit_ROOT_DIR "${CMAKE_CUDA_COMPILER_TOOLKIT_ROOT}")
  429. set(CUDAToolkit_LIBRARY_ROOT "${CMAKE_CUDA_COMPILER_LIBRARY_ROOT}")
  430. _CUDAToolkit_build_library_dirs(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES CMAKE_CUDA_HOST_IMPLICIT_LINK_DIRECTORIES)
  431. _CUDAToolkit_build_include_dirs(CUDAToolkit_INCLUDE_DIRECTORIES CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES)
  432. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_ROOT_DIR}/bin")
  433. set(CUDAToolkit_NVCC_EXECUTABLE "${CUDAToolkit_BIN_DIR}/nvcc${CMAKE_EXECUTABLE_SUFFIX}")
  434. set(CUDAToolkit_VERSION "${CMAKE_CUDA_COMPILER_TOOLKIT_VERSION}")
  435. if(CUDAToolkit_VERSION MATCHES [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  436. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  437. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  438. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  439. endif()
  440. else()
  441. function(_CUDAToolkit_find_root_dir )
  442. cmake_parse_arguments(arg "COMPILER_PATHS" "" "SEARCH_PATHS;FIND_FLAGS" ${ARGN})
  443. if(NOT CUDAToolkit_BIN_DIR)
  444. if(arg_COMPILER_PATHS)
  445. # need to find parent dir, since this could clang and not nvcc
  446. if(EXISTS "${CMAKE_CUDA_COMPILER}")
  447. get_filename_component(possible_nvcc_path "${CMAKE_CUDA_COMPILER}" PROGRAM PROGRAM_ARGS CUDAToolkit_compiler_args)
  448. get_filename_component(possible_nvcc_path "${possible_nvcc_path}" DIRECTORY)
  449. elseif(EXISTS "$ENV{CUDACXX}")
  450. get_filename_component(possible_nvcc_path "$ENV{CUDACXX}" PROGRAM PROGRAM_ARGS CUDAToolkit_compiler_args)
  451. get_filename_component(possible_nvcc_path "${possible_nvcc_path}" DIRECTORY)
  452. endif()
  453. if(possible_nvcc_path)
  454. find_program(CUDAToolkit_NVCC_EXECUTABLE
  455. NAMES nvcc nvcc.exe
  456. NO_DEFAULT_PATH
  457. PATHS ${possible_nvcc_path}
  458. )
  459. endif()
  460. else()
  461. if(NOT CUDAToolkit_SENTINEL_FILE)
  462. find_program(CUDAToolkit_NVCC_EXECUTABLE
  463. NAMES nvcc nvcc.exe
  464. PATHS ${arg_SEARCH_PATHS}
  465. ${arg_FIND_FLAGS}
  466. )
  467. endif()
  468. if(NOT CUDAToolkit_NVCC_EXECUTABLE)
  469. find_file(CUDAToolkit_SENTINEL_FILE
  470. NAMES version.txt version.json
  471. PATHS ${arg_SEARCH_PATHS}
  472. NO_DEFAULT_PATH
  473. )
  474. endif()
  475. endif()
  476. if(EXISTS "${CUDAToolkit_NVCC_EXECUTABLE}")
  477. # If NVCC exists then invoke it to find the toolkit location.
  478. # This allows us to support wrapper scripts (e.g. ccache or colornvcc), CUDA Toolkit,
  479. # NVIDIA HPC SDK, and distro's splayed layouts
  480. execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "-v" "__cmake_determine_cuda"
  481. OUTPUT_VARIABLE _CUDA_NVCC_OUT ERROR_VARIABLE _CUDA_NVCC_OUT)
  482. message(CONFIGURE_LOG
  483. "Executed nvcc to extract CUDAToolkit information:\n${_CUDA_NVCC_OUT}\n\n")
  484. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ TOP=([^\r\n]*)")
  485. get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_MATCH_1}/bin" ABSOLUTE)
  486. message(CONFIGURE_LOG
  487. "Parsed CUDAToolkit nvcc location:\n${CUDAToolkit_BIN_DIR}\n\n")
  488. else()
  489. get_filename_component(CUDAToolkit_BIN_DIR "${CUDAToolkit_NVCC_EXECUTABLE}" DIRECTORY)
  490. endif()
  491. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ INCLUDES=([^\r\n]*)")
  492. separate_arguments(_nvcc_output NATIVE_COMMAND "${CMAKE_MATCH_1}")
  493. foreach(line IN LISTS _nvcc_output)
  494. string(REGEX REPLACE "^-I" "" line "${line}")
  495. get_filename_component(line "${line}" ABSOLUTE)
  496. list(APPEND _cmake_CUDAToolkit_include_directories "${line}")
  497. endforeach()
  498. endif()
  499. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ SYSTEM_INCLUDES=([^\r\n]*)")
  500. unset(_nvcc_output)
  501. separate_arguments(_nvcc_output NATIVE_COMMAND "${CMAKE_MATCH_1}")
  502. foreach(line IN LISTS _nvcc_output)
  503. string(REGEX REPLACE "^-isystem" "" line "${line}")
  504. if(line)
  505. get_filename_component(line "${line}" ABSOLUTE)
  506. list(APPEND _cmake_CUDAToolkit_include_directories "${line}")
  507. endif()
  508. endforeach()
  509. endif()
  510. if(DEFINED _cmake_CUDAToolkit_include_directories)
  511. message(CONFIGURE_LOG
  512. "Parsed CUDAToolkit nvcc implicit include information:\n${_cmake_CUDAToolkit_include_directories}\n\n")
  513. set(_cmake_CUDAToolkit_include_directories "${_cmake_CUDAToolkit_include_directories}" CACHE INTERNAL "CUDAToolkit internal list of include directories")
  514. endif()
  515. if(_CUDA_NVCC_OUT MATCHES "\\#\\$ LIBRARIES=([^\r\n]*)")
  516. include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
  517. set(_nvcc_link_line "cuda-fake-ld ${CMAKE_MATCH_1}")
  518. CMAKE_PARSE_IMPLICIT_LINK_INFO("${_nvcc_link_line}"
  519. _cmake_CUDAToolkit_implicit_link_libs
  520. _cmake_CUDAToolkit_implicit_link_directories
  521. _cmake_CUDAToolkit_implicit_frameworks
  522. _nvcc_log
  523. "${CMAKE_CUDA_IMPLICIT_OBJECT_REGEX}"
  524. LANGUAGE CUDA)
  525. message(CONFIGURE_LOG
  526. "Parsed CUDAToolkit nvcc implicit link information:\n${_nvcc_log}\n${_cmake_CUDAToolkit_implicit_link_directories}\n\n")
  527. unset(_nvcc_link_line)
  528. unset(_cmake_CUDAToolkit_implicit_link_libs)
  529. unset(_cmake_CUDAToolkit_implicit_frameworks)
  530. set(_cmake_CUDAToolkit_implicit_link_directories "${_cmake_CUDAToolkit_implicit_link_directories}" CACHE INTERNAL "CUDAToolkit internal list of implicit link directories")
  531. endif()
  532. unset(_CUDA_NVCC_OUT)
  533. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
  534. mark_as_advanced(CUDAToolkit_BIN_DIR)
  535. endif()
  536. if(CUDAToolkit_SENTINEL_FILE)
  537. get_filename_component(CUDAToolkit_BIN_DIR ${CUDAToolkit_SENTINEL_FILE} DIRECTORY ABSOLUTE)
  538. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}/bin")
  539. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "" FORCE)
  540. mark_as_advanced(CUDAToolkit_BIN_DIR)
  541. endif()
  542. endif()
  543. if(DEFINED _cmake_CUDAToolkit_include_directories)
  544. _CUDAToolkit_build_include_dirs(_cmake_CUDAToolkit_contents _cmake_CUDAToolkit_include_directories)
  545. set(CUDAToolkit_INCLUDE_DIRECTORIES "${_cmake_CUDAToolkit_contents}" PARENT_SCOPE)
  546. endif()
  547. if(DEFINED _cmake_CUDAToolkit_implicit_link_directories)
  548. _CUDAToolkit_build_library_dirs(_cmake_CUDAToolkit_contents _cmake_CUDAToolkit_implicit_link_directories)
  549. set(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES "${_cmake_CUDAToolkit_contents}" PARENT_SCOPE)
  550. endif()
  551. if(CUDAToolkit_BIN_DIR)
  552. get_filename_component(CUDAToolkit_ROOT_DIR ${CUDAToolkit_BIN_DIR} DIRECTORY ABSOLUTE)
  553. set(CUDAToolkit_ROOT_DIR "${CUDAToolkit_ROOT_DIR}" PARENT_SCOPE)
  554. endif()
  555. endfunction()
  556. function(_CUDAToolkit_guess_root_dir)
  557. # CUDAToolkit_ROOT cmake / env variable not specified, try platform defaults.
  558. #
  559. # - Linux: /usr/local/cuda-X.Y
  560. # - macOS: /Developer/NVIDIA/CUDA-X.Y
  561. # - Windows: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y
  562. #
  563. # We will also search the default symlink location /usr/local/cuda first since
  564. # if CUDAToolkit_ROOT is not specified, it is assumed that the symlinked
  565. # directory is the desired location.
  566. if(UNIX)
  567. if(NOT APPLE)
  568. set(platform_base "/usr/local/cuda-")
  569. else()
  570. set(platform_base "/Developer/NVIDIA/CUDA-")
  571. endif()
  572. else()
  573. set(platform_base "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v")
  574. endif()
  575. # Build out a descending list of possible cuda installations, e.g.
  576. file(GLOB possible_paths "${platform_base}*")
  577. # Iterate the glob results and create a descending list.
  578. set(versions)
  579. foreach(p ${possible_paths})
  580. # Extract version number from end of string
  581. string(REGEX MATCH "[0-9][0-9]?\\.[0-9]$" p_version ${p})
  582. if(IS_DIRECTORY ${p} AND p_version)
  583. list(APPEND versions ${p_version})
  584. endif()
  585. endforeach()
  586. # Sort numerically in descending order, so we try the newest versions first.
  587. list(SORT versions COMPARE NATURAL ORDER DESCENDING)
  588. # With a descending list of versions, populate possible paths to search.
  589. set(search_paths)
  590. foreach(v ${versions})
  591. list(APPEND search_paths "${platform_base}${v}")
  592. endforeach()
  593. # Force the global default /usr/local/cuda to the front on Unix.
  594. if(UNIX)
  595. list(INSERT search_paths 0 "/usr/local/cuda")
  596. endif()
  597. # Now search for the toolkit again using the platform default search paths.
  598. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${search_paths}" FIND_FLAGS PATH_SUFFIXES bin)
  599. if(CUDAToolkit_ROOT_DIR)
  600. set(CUDAToolkit_ROOT_DIR "${CUDAToolkit_ROOT_DIR}" PARENT_SCOPE)
  601. endif()
  602. # We are done with these variables now, cleanup for caller.
  603. unset(platform_base)
  604. unset(possible_paths)
  605. unset(versions)
  606. unset(search_paths)
  607. endfunction()
  608. function(_CUDAToolkit_find_version_file result_variable)
  609. # We first check for a non-scattered installation to prefer it over a scattered installation.
  610. set(version_files version.txt version.json)
  611. foreach(vf IN LISTS version_files)
  612. if(CUDAToolkit_ROOT AND EXISTS "${CUDAToolkit_ROOT}/${vf}")
  613. set(${result_variable} "${CUDAToolkit_ROOT}/${vf}" PARENT_SCOPE)
  614. break()
  615. elseif(CUDAToolkit_ROOT_DIR AND EXISTS "${CUDAToolkit_ROOT_DIR}/${vf}")
  616. set(${result_variable} "${CUDAToolkit_ROOT_DIR}/${vf}" PARENT_SCOPE)
  617. break()
  618. elseif(CMAKE_SYSROOT_LINK AND EXISTS "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/${vf}")
  619. set(${result_variable} "${CMAKE_SYSROOT_LINK}/usr/lib/cuda/${vf}" PARENT_SCOPE)
  620. break()
  621. elseif(EXISTS "${CMAKE_SYSROOT}/usr/lib/cuda/${vf}")
  622. set(${result_variable} "${CMAKE_SYSROOT}/usr/lib/cuda/${vf}" PARENT_SCOPE)
  623. break()
  624. endif()
  625. endforeach()
  626. endfunction()
  627. function(_CUDAToolkit_parse_version_file version_file)
  628. if(version_file)
  629. file(READ "${version_file}" file_contents)
  630. cmake_path(GET version_file EXTENSION LAST_ONLY version_ext)
  631. if(version_ext STREQUAL ".json")
  632. string(JSON cuda_version_info GET "${file_contents}" "cuda" "version")
  633. set(cuda_version_match_regex [=[([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  634. elseif(version_ext STREQUAL ".txt")
  635. set(cuda_version_info "${file_contents}")
  636. set(cuda_version_match_regex [=[CUDA Version ([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  637. endif()
  638. if(cuda_version_info MATCHES "${cuda_version_match_regex}")
  639. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}" PARENT_SCOPE)
  640. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}" PARENT_SCOPE)
  641. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}" PARENT_SCOPE)
  642. set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" PARENT_SCOPE)
  643. endif()
  644. endif()
  645. endfunction()
  646. macro(_CUDAToolkit_find_failure_message _CUDAToolkit_fail_mode)
  647. # Declare error messages now, print later depending on find_package args.
  648. if("${_CUDAToolkit_fail_mode}" STREQUAL "GUESS")
  649. set(_CUDAToolkit_fail_message "Could not find `nvcc` executable in any searched paths, please set CUDAToolkit_ROOT")
  650. elseif("${_CUDAToolkit_fail_mode}" STREQUAL "VARIABLE")
  651. set(_CUDAToolkit_fail_message "Could not find `nvcc` executable in path specified by variable CUDAToolkit_ROOT=${CUDAToolkit_ROOT}")
  652. else()
  653. set(_CUDAToolkit_fail_message "Could not find `nvcc` executable in path specified by environment variable CUDAToolkit_ROOT=$ENV{CUDAToolkit_ROOT}")
  654. endif()
  655. if(CUDAToolkit_FIND_REQUIRED)
  656. message(FATAL_ERROR ${_CUDAToolkit_fail_message})
  657. else()
  658. if(NOT CUDAToolkit_FIND_QUIETLY)
  659. message(STATUS ${_CUDAToolkit_fail_message})
  660. endif()
  661. set(CUDAToolkit_FOUND FALSE)
  662. unset(_CUDAToolkit_fail_message)
  663. return()
  664. endif()
  665. endmacro()
  666. # For NVCC we can easily deduce the SDK binary directory from the compiler path.
  667. if(CMAKE_CUDA_COMPILER_LOADED AND NOT CUDAToolkit_BIN_DIR AND CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
  668. get_filename_component(CUDAToolkit_BIN_DIR "${CMAKE_CUDA_COMPILER}" DIRECTORY)
  669. set(CUDAToolkit_BIN_DIR "${CUDAToolkit_BIN_DIR}" CACHE PATH "")
  670. # Try language provided path first.
  671. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_BIN_DIR}" FIND_FLAGS NO_DEFAULT_PATH)
  672. mark_as_advanced(CUDAToolkit_BIN_DIR)
  673. endif()
  674. # Try `CMAKE_CUDA_COMPILER` and `ENV{CUDACXX}`
  675. if(NOT CUDAToolkit_ROOT_DIR)
  676. _CUDAToolkit_find_root_dir(COMPILER_PATHS)
  677. endif()
  678. # Try user provided path
  679. if(NOT CUDAToolkit_ROOT_DIR AND DEFINED CUDAToolkit_ROOT)
  680. _CUDAToolkit_find_root_dir(SEARCH_PATHS "${CUDAToolkit_ROOT}" FIND_FLAGS PATH_SUFFIXES bin NO_DEFAULT_PATH)
  681. endif()
  682. if(NOT CUDAToolkit_ROOT_DIR AND DEFINED ENV{CUDAToolkit_ROOT})
  683. _CUDAToolkit_find_root_dir(SEARCH_PATHS "$ENV{CUDAToolkit_ROOT}" FIND_FLAGS PATH_SUFFIXES bin NO_DEFAULT_PATH)
  684. endif()
  685. # Try users PATH, and CUDA_PATH env variable
  686. if(NOT CUDAToolkit_ROOT_DIR)
  687. _CUDAToolkit_find_root_dir(FIND_FLAGS PATHS ENV CUDA_PATH PATH_SUFFIXES bin)
  688. endif()
  689. # If the user specified CUDAToolkit_ROOT but the toolkit could not be found, this is an error.
  690. if(NOT CUDAToolkit_ROOT_DIR AND DEFINED CUDAToolkit_ROOT)
  691. _CUDAToolkit_find_failure_message(VARIABLE)
  692. elseif(NOT CUDAToolkit_ROOT_DIR AND DEFINED ENV{CUDAToolkit_ROOT})
  693. _CUDAToolkit_find_failure_message(ENV)
  694. endif()
  695. # Try guessing where CUDA is installed
  696. if(NOT CUDAToolkit_ROOT_DIR)
  697. _CUDAToolkit_guess_root_dir()
  698. if(NOT CUDAToolkit_ROOT_DIR)
  699. _CUDAToolkit_find_failure_message(GUESS)
  700. endif()
  701. endif()
  702. _CUDAToolkit_find_version_file( _CUDAToolkit_version_file )
  703. if(_CUDAToolkit_version_file)
  704. # CUDAToolkit_LIBRARY_ROOT contains the device library and version file.
  705. get_filename_component(CUDAToolkit_LIBRARY_ROOT "${_CUDAToolkit_version_file}" DIRECTORY ABSOLUTE)
  706. endif()
  707. unset(_CUDAToolkit_version_file)
  708. if(CUDAToolkit_NVCC_EXECUTABLE AND
  709. CMAKE_CUDA_COMPILER_VERSION AND
  710. CUDAToolkit_NVCC_EXECUTABLE STREQUAL CMAKE_CUDA_COMPILER)
  711. # Need to set these based off the already computed CMAKE_CUDA_COMPILER_VERSION value
  712. # This if statement will always match, but is used to provide variables for MATCH 1,2,3...
  713. if(CMAKE_CUDA_COMPILER_VERSION MATCHES [=[([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_CUDA_COMPILER_VERSION}")
  718. endif()
  719. elseif(CUDAToolkit_NVCC_EXECUTABLE)
  720. # Compute the version by invoking nvcc
  721. execute_process(COMMAND ${CUDAToolkit_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
  722. if(NVCC_OUT MATCHES [=[ V([0-9]+)\.([0-9]+)\.([0-9]+)]=])
  723. set(CUDAToolkit_VERSION_MAJOR "${CMAKE_MATCH_1}")
  724. set(CUDAToolkit_VERSION_MINOR "${CMAKE_MATCH_2}")
  725. set(CUDAToolkit_VERSION_PATCH "${CMAKE_MATCH_3}")
  726. set(CUDAToolkit_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
  727. endif()
  728. unset(NVCC_OUT)
  729. else()
  730. _CUDAToolkit_find_version_file(version_file)
  731. _CUDAToolkit_parse_version_file("${version_file}")
  732. endif()
  733. endif()
  734. # Find target directory when crosscompiling.
  735. if(CMAKE_CROSSCOMPILING)
  736. # When a language is enabled we can use its compiler's target architecture.
  737. if(CMAKE_CUDA_COMPILER_LOADED AND CMAKE_CUDA_COMPILER_ARCHITECTURE_ID)
  738. set(_CUDA_TARGET_PROCESSOR "${CMAKE_CUDA_COMPILER_ARCHITECTURE_ID}")
  739. elseif(CMAKE_CXX_COMPILER_LOADED AND CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
  740. set(_CUDA_TARGET_PROCESSOR "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
  741. elseif(CMAKE_C_COMPILER_LOADED AND CMAKE_C_COMPILER_ARCHITECTURE_ID)
  742. set(_CUDA_TARGET_PROCESSOR "${CMAKE_C_COMPILER_ARCHITECTURE_ID}")
  743. elseif(CMAKE_SYSTEM_PROCESSOR)
  744. set(_CUDA_TARGET_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
  745. else()
  746. message(FATAL_ERROR "Cross-compiling with the CUDA toolkit requires CMAKE_SYSTEM_PROCESSOR to be set.")
  747. endif()
  748. # Keep in sync with equivalent table in CMakeDetermineCUDACompiler and FindCUDA!
  749. if(_CUDA_TARGET_PROCESSOR STREQUAL "armv7-a")
  750. # Support for NVPACK
  751. set(CUDAToolkit_TARGET_NAMES "armv7-linux-androideabi")
  752. elseif(_CUDA_TARGET_PROCESSOR MATCHES "arm")
  753. set(CUDAToolkit_TARGET_NAMES "armv7-linux-gnueabihf")
  754. elseif(_CUDA_TARGET_PROCESSOR MATCHES "aarch64")
  755. if(ANDROID_ARCH_NAME STREQUAL "arm64")
  756. set(CUDAToolkit_TARGET_NAMES "aarch64-linux-androideabi")
  757. elseif (CMAKE_SYSTEM_NAME STREQUAL "QNX")
  758. set(CUDAToolkit_TARGET_NAMES "aarch64-qnx")
  759. else()
  760. set(CUDAToolkit_TARGET_NAMES "aarch64-linux" "sbsa-linux")
  761. endif()
  762. elseif(_CUDA_TARGET_PROCESSOR STREQUAL "x86_64")
  763. set(CUDAToolkit_TARGET_NAMES "x86_64-linux")
  764. endif()
  765. unset(_CUDA_TARGET_PROCESSOR)
  766. foreach(CUDAToolkit_TARGET_NAME IN LISTS CUDAToolkit_TARGET_NAMES)
  767. if(EXISTS "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
  768. set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}/targets/${CUDAToolkit_TARGET_NAME}")
  769. # add known CUDA target root path to the set of directories we search for programs, libraries and headers
  770. list(PREPEND CMAKE_FIND_ROOT_PATH "${CUDAToolkit_TARGET_DIR}")
  771. # Mark that we need to pop the root search path changes after we have
  772. # found all cuda libraries so that searches for our cross-compilation
  773. # libraries work when another cuda sdk is in CMAKE_PREFIX_PATH or
  774. # PATh
  775. set(_CUDAToolkit_Pop_ROOT_PATH True)
  776. break()
  777. endif()
  778. endforeach()
  779. endif()
  780. # Determine windows search path suffix for libraries
  781. if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
  782. if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
  783. set(_CUDAToolkit_win_search_dirs lib/x64)
  784. set(_CUDAToolkit_win_stub_search_dirs lib/x64/stubs)
  785. endif()
  786. endif()
  787. # If not already set we can simply use the toolkit root or it's a scattered installation.
  788. if(NOT CUDAToolkit_TARGET_DIR)
  789. # Not cross compiling
  790. set(CUDAToolkit_TARGET_DIR "${CUDAToolkit_ROOT_DIR}")
  791. # Now that we have the real ROOT_DIR, find components inside it.
  792. list(APPEND CMAKE_PREFIX_PATH ${CUDAToolkit_ROOT_DIR})
  793. # Mark that we need to pop the prefix path changes after we have
  794. # found the cudart library.
  795. set(_CUDAToolkit_Pop_Prefix True)
  796. endif()
  797. # We don't need to verify the cuda_runtime header when we are using `nvcc` include paths
  798. # as the compiler being enabled means the header was found
  799. if(NOT CUDAToolkit_INCLUDE_DIRECTORIES)
  800. # Otherwise use CUDAToolkit_TARGET_DIR to guess where the `cuda_runtime.h` is located
  801. # On a scattered installation /usr, on a non-scattered something like /usr/local/cuda or /usr/local/cuda-10.2/targets/aarch64-linux.
  802. if(EXISTS "${CUDAToolkit_TARGET_DIR}/include/cuda_runtime.h")
  803. set(CUDAToolkit_INCLUDE_DIRECTORIES "${CUDAToolkit_TARGET_DIR}/include")
  804. else()
  805. message(STATUS "Unable to find cuda_runtime.h in \"${CUDAToolkit_TARGET_DIR}/include\" for CUDAToolkit_INCLUDE_DIRECTORIES.")
  806. endif()
  807. endif()
  808. # The NVHPC layout moves math library headers and libraries to a sibling directory and it could be nested under
  809. # the version of the CUDA toolchain
  810. # Create a separate variable so this directory can be selectively added to math targets.
  811. find_path(CUDAToolkit_CUBLAS_INCLUDE_DIR cublas_v2.h PATHS
  812. ${CUDAToolkit_INCLUDE_DIRECTORIES}
  813. NO_DEFAULT_PATH)
  814. if(NOT CUDAToolkit_CUBLAS_INCLUDE_DIR)
  815. file(REAL_PATH "${CUDAToolkit_TARGET_DIR}" CUDAToolkit_MATH_INCLUDE_DIR)
  816. cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "../../math_libs/")
  817. if(EXISTS "${CUDAToolkit_MATH_INCLUDE_DIR}/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/")
  818. cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/")
  819. endif()
  820. cmake_path(APPEND CUDAToolkit_MATH_INCLUDE_DIR "include")
  821. cmake_path(NORMAL_PATH CUDAToolkit_MATH_INCLUDE_DIR)
  822. find_path(CUDAToolkit_CUBLAS_INCLUDE_DIR cublas_v2.h PATHS
  823. ${CUDAToolkit_INCLUDE_DIRECTORIES}
  824. )
  825. if(CUDAToolkit_CUBLAS_INCLUDE_DIR)
  826. list(APPEND CUDAToolkit_INCLUDE_DIRECTORIES "${CUDAToolkit_CUBLAS_INCLUDE_DIR}")
  827. endif()
  828. endif()
  829. unset(CUDAToolkit_CUBLAS_INCLUDE_DIR CACHE)
  830. unset(CUDAToolkit_CUBLAS_INCLUDE_DIR)
  831. # Find the CUDA Runtime Library libcudart
  832. find_library(CUDA_CUDART
  833. NAMES cudart
  834. PATHS ${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES}
  835. PATH_SUFFIXES lib64 ${_CUDAToolkit_win_search_dirs}
  836. )
  837. find_library(CUDA_CUDART
  838. NAMES cudart
  839. PATHS ${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES}
  840. PATH_SUFFIXES lib64/stubs ${_CUDAToolkit_win_stub_search_dirs} lib/stubs stubs
  841. )
  842. if(NOT CUDA_CUDART AND NOT CUDAToolkit_FIND_QUIETLY)
  843. message(STATUS "Unable to find cudart library.")
  844. endif()
  845. if(_CUDAToolkit_Pop_Prefix)
  846. list(REMOVE_AT CMAKE_PREFIX_PATH -1)
  847. unset(_CUDAToolkit_Pop_Prefix)
  848. endif()
  849. #-----------------------------------------------------------------------------
  850. # Perform version comparison and validate all required variables are set.
  851. include(FindPackageHandleStandardArgs)
  852. find_package_handle_standard_args(CUDAToolkit
  853. REQUIRED_VARS
  854. CUDAToolkit_INCLUDE_DIRECTORIES
  855. CUDA_CUDART
  856. CUDAToolkit_BIN_DIR
  857. VERSION_VAR
  858. CUDAToolkit_VERSION
  859. )
  860. unset(CUDAToolkit_ROOT_DIR)
  861. mark_as_advanced(CUDA_CUDART
  862. CUDAToolkit_NVCC_EXECUTABLE
  863. CUDAToolkit_SENTINEL_FILE
  864. )
  865. #-----------------------------------------------------------------------------
  866. # Construct result variables
  867. if(CUDAToolkit_FOUND)
  868. set(CUDAToolkit_INCLUDE_DIRS "${CUDAToolkit_INCLUDE_DIRECTORIES}")
  869. get_filename_component(CUDAToolkit_LIBRARY_DIR ${CUDA_CUDART} DIRECTORY ABSOLUTE)
  870. # Build search paths without any symlinks
  871. file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}" _cmake_search_dir)
  872. set(CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}")
  873. # Detect we are in a splayed nvhpc toolkit layout and add extra
  874. # search paths without symlinks
  875. if(CUDAToolkit_LIBRARY_DIR MATCHES ".*/cuda/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/lib64$")
  876. # Search location for math_libs/
  877. block(SCOPE_FOR POLICIES)
  878. cmake_policy(SET CMP0152 NEW)
  879. file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../../../../../" _cmake_search_dir)
  880. list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}")
  881. # Search location for extras like cupti
  882. file(REAL_PATH "${CUDAToolkit_LIBRARY_DIR}/../../../" _cmake_search_dir)
  883. list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${_cmake_search_dir}")
  884. endblock()
  885. endif()
  886. if(DEFINED CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES)
  887. list(APPEND CUDAToolkit_LIBRARY_SEARCH_DIRS "${CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES}")
  888. endif()
  889. # If no `CUDAToolkit_LIBRARY_ROOT` exists set it based on CUDAToolkit_LIBRARY_DIR
  890. if(NOT DEFINED CUDAToolkit_LIBRARY_ROOT)
  891. foreach(CUDAToolkit_search_loc IN LISTS CUDAToolkit_LIBRARY_DIR CUDAToolkit_BIN_DIR)
  892. get_filename_component(CUDAToolkit_possible_lib_root "${CUDAToolkit_search_loc}" DIRECTORY ABSOLUTE)
  893. if(EXISTS "${CUDAToolkit_possible_lib_root}/nvvm/")
  894. set(CUDAToolkit_LIBRARY_ROOT "${CUDAToolkit_possible_lib_root}")
  895. break()
  896. endif()
  897. endforeach()
  898. unset(CUDAToolkit_search_loc)
  899. unset(CUDAToolkit_possible_lib_root)
  900. endif()
  901. else()
  902. # clear cache results when we fail
  903. unset(_cmake_CUDAToolkit_implicit_link_directories CACHE)
  904. unset(_cmake_CUDAToolkit_include_directories CACHE)
  905. unset(CUDA_CUDART CACHE)
  906. unset(CUDAToolkit_BIN_DIR CACHE)
  907. unset(CUDAToolkit_NVCC_EXECUTABLE CACHE)
  908. unset(CUDAToolkit_SENTINEL_FILE CACHE)
  909. endif()
  910. unset(CUDAToolkit_IMPLICIT_LIBRARY_DIRECTORIES)
  911. unset(CUDAToolkit_INCLUDE_DIRECTORIES)
  912. #-----------------------------------------------------------------------------
  913. # Construct import targets
  914. if(CUDAToolkit_FOUND)
  915. function(_CUDAToolkit_find_and_add_import_lib lib_name)
  916. cmake_parse_arguments(arg "" "" "ALT;DEPS;EXTRA_PATH_SUFFIXES;EXTRA_INCLUDE_DIRS;ONLY_SEARCH_FOR" ${ARGN})
  917. if(arg_ONLY_SEARCH_FOR)
  918. set(search_names ${arg_ONLY_SEARCH_FOR})
  919. else()
  920. set(search_names ${lib_name} ${arg_ALT})
  921. endif()
  922. find_library(CUDA_${lib_name}_LIBRARY
  923. NAMES ${search_names}
  924. HINTS ${CUDAToolkit_LIBRARY_SEARCH_DIRS}
  925. ENV CUDA_PATH
  926. PATH_SUFFIXES nvidia/current lib64 ${_CUDAToolkit_win_search_dirs} lib
  927. # Support NVHPC splayed math library layout
  928. math_libs/${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}/lib64
  929. math_libs/lib64
  930. ${arg_EXTRA_PATH_SUFFIXES}
  931. )
  932. # Don't try any stub directories until we have exhausted all other
  933. # search locations.
  934. set(CUDA_IMPORT_PROPERTY IMPORTED_LOCATION)
  935. set(CUDA_IMPORT_TYPE UNKNOWN)
  936. if(NOT CUDA_${lib_name}_LIBRARY)
  937. find_library(CUDA_${lib_name}_LIBRARY
  938. NAMES ${search_names}
  939. HINTS ${CUDAToolkit_LIBRARY_SEARCH_DIRS}
  940. ENV CUDA_PATH
  941. PATH_SUFFIXES lib64/stubs ${_CUDAToolkit_win_stub_search_dirs} lib/stubs stubs
  942. )
  943. endif()
  944. if(CUDA_${lib_name}_LIBRARY MATCHES "/stubs/" AND NOT CUDA_${lib_name}_LIBRARY MATCHES "\\.a$" AND NOT WIN32)
  945. # Use a SHARED library with IMPORTED_IMPLIB, but not IMPORTED_LOCATION,
  946. # to indicate that the stub is for linkers but not dynamic loaders.
  947. # It will not contribute any RPATH entry. When encountered as
  948. # a private transitive dependency of another shared library,
  949. # it will be passed explicitly to linkers so they can find it
  950. # even when the runtime library file does not exist on disk.
  951. set(CUDA_IMPORT_PROPERTY IMPORTED_IMPLIB)
  952. set(CUDA_IMPORT_TYPE SHARED)
  953. endif()
  954. mark_as_advanced(CUDA_${lib_name}_LIBRARY)
  955. if (NOT TARGET CUDA::${lib_name} AND CUDA_${lib_name}_LIBRARY)
  956. add_library(CUDA::${lib_name} ${CUDA_IMPORT_TYPE} IMPORTED)
  957. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  958. if(DEFINED CUDAToolkit_MATH_INCLUDE_DIR)
  959. string(FIND ${CUDA_${lib_name}_LIBRARY} "math_libs" math_libs)
  960. if(NOT ${math_libs} EQUAL -1)
  961. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${CUDAToolkit_MATH_INCLUDE_DIR}")
  962. endif()
  963. endif()
  964. set_property(TARGET CUDA::${lib_name} PROPERTY ${CUDA_IMPORT_PROPERTY} "${CUDA_${lib_name}_LIBRARY}")
  965. foreach(dep ${arg_DEPS})
  966. if(TARGET CUDA::${dep})
  967. target_link_libraries(CUDA::${lib_name} INTERFACE CUDA::${dep})
  968. endif()
  969. endforeach()
  970. if(arg_EXTRA_INCLUDE_DIRS)
  971. target_include_directories(CUDA::${lib_name} SYSTEM INTERFACE "${arg_EXTRA_INCLUDE_DIRS}")
  972. endif()
  973. endif()
  974. endfunction()
  975. if(NOT TARGET CUDA::toolkit)
  976. add_library(CUDA::toolkit IMPORTED INTERFACE)
  977. target_include_directories(CUDA::toolkit SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  978. target_link_directories(CUDA::toolkit INTERFACE "${CUDAToolkit_LIBRARY_DIR}")
  979. endif()
  980. # setup dependencies that are required for cudart/cudart_static when building
  981. # on linux. These are generally only required when using the CUDA toolkit
  982. # when CUDA language is disabled
  983. if(NOT TARGET CUDA::cudart_static_deps)
  984. add_library(CUDA::cudart_static_deps IMPORTED INTERFACE)
  985. if(UNIX AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
  986. find_package(Threads REQUIRED)
  987. target_link_libraries(CUDA::cudart_static_deps INTERFACE Threads::Threads ${CMAKE_DL_LIBS})
  988. endif()
  989. if(UNIX AND NOT APPLE AND NOT (CMAKE_SYSTEM_NAME STREQUAL "QNX"))
  990. # On Linux, you must link against librt when using the static cuda runtime.
  991. find_library(CUDAToolkit_rt_LIBRARY rt)
  992. mark_as_advanced(CUDAToolkit_rt_LIBRARY)
  993. if(NOT CUDAToolkit_rt_LIBRARY)
  994. message(WARNING "Could not find librt library, needed by CUDA::cudart_static")
  995. else()
  996. target_link_libraries(CUDA::cudart_static_deps INTERFACE ${CUDAToolkit_rt_LIBRARY})
  997. endif()
  998. endif()
  999. endif()
  1000. _CUDAToolkit_find_and_add_import_lib(cuda_driver ALT cuda DEPS cudart_static_deps)
  1001. _CUDAToolkit_find_and_add_import_lib(cudart DEPS cudart_static_deps)
  1002. _CUDAToolkit_find_and_add_import_lib(cudart_static DEPS cudart_static_deps)
  1003. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.0.0)
  1004. _CUDAToolkit_find_and_add_import_lib(nvJitLink)
  1005. _CUDAToolkit_find_and_add_import_lib(nvJitLink_static DEPS cudart_static_deps)
  1006. endif()
  1007. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.4.0)
  1008. _CUDAToolkit_find_and_add_import_lib(nvfatbin DEPS cudart_static_deps)
  1009. _CUDAToolkit_find_and_add_import_lib(nvfatbin_static DEPS cudart_static_deps)
  1010. endif()
  1011. _CUDAToolkit_find_and_add_import_lib(culibos) # it's a static library
  1012. foreach (cuda_lib cublasLt cufft nvjpeg)
  1013. _CUDAToolkit_find_and_add_import_lib(${cuda_lib})
  1014. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS cudart_static_deps culibos)
  1015. endforeach()
  1016. foreach (cuda_lib curand nppc)
  1017. _CUDAToolkit_find_and_add_import_lib(${cuda_lib})
  1018. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS culibos)
  1019. endforeach()
  1020. _CUDAToolkit_find_and_add_import_lib(cusparse DEPS nvJitLink)
  1021. _CUDAToolkit_find_and_add_import_lib(cusparse_static DEPS nvJitLink_static culibos)
  1022. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.0.0)
  1023. # cublas depends on cublasLt
  1024. # https://docs.nvidia.com/cuda/archive/11.0/cublas#static-library
  1025. _CUDAToolkit_find_and_add_import_lib(cublas DEPS cublasLt culibos)
  1026. _CUDAToolkit_find_and_add_import_lib(cublas_static DEPS cublasLt_static culibos)
  1027. else()
  1028. _CUDAToolkit_find_and_add_import_lib(cublas DEPS culibos)
  1029. _CUDAToolkit_find_and_add_import_lib(cublas_static DEPS culibos)
  1030. endif()
  1031. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.4)
  1032. _CUDAToolkit_find_and_add_import_lib(cuFile ALT cufile DEPS culibos)
  1033. _CUDAToolkit_find_and_add_import_lib(cuFile_static ALT cufile_static DEPS culibos)
  1034. _CUDAToolkit_find_and_add_import_lib(cuFile_rdma ALT cufile_rdma DEPS cuFile culibos)
  1035. _CUDAToolkit_find_and_add_import_lib(cuFile_rdma_static ALT cufile_rdma_static DEPS cuFile_static culibos)
  1036. endif()
  1037. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.6)
  1038. _CUDAToolkit_find_and_add_import_lib(cudla)
  1039. endif()
  1040. # cuFFTW depends on cuFFT
  1041. _CUDAToolkit_find_and_add_import_lib(cufftw DEPS cufft)
  1042. _CUDAToolkit_find_and_add_import_lib(cufftw_static DEPS cufft_static)
  1043. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 9.2)
  1044. _CUDAToolkit_find_and_add_import_lib(cufft_static_nocallback DEPS culibos)
  1045. endif()
  1046. # cuSOLVER depends on cuBLAS, and cuSPARSE
  1047. set(cusolver_deps cublas cusparse)
  1048. set(cusolver_static_deps cublas_static cusparse_static culibos)
  1049. if(CUDAToolkit_VERSION VERSION_GREATER 11.2.1)
  1050. # cusolver depends on libcusolver_metis and cublasLt
  1051. # https://docs.nvidia.com/cuda/archive/11.2.2/cusolver#link-dependency
  1052. list(APPEND cusolver_deps cublasLt)
  1053. _CUDAToolkit_find_and_add_import_lib(cusolver_metis_static ALT metis_static) # implementation detail static lib
  1054. list(APPEND cusolver_static_deps cusolver_metis_static cublasLt_static)
  1055. endif()
  1056. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.1.2)
  1057. # cusolver depends on liblapack_static.a starting with CUDA 10.1 update 2,
  1058. # https://docs.nvidia.com/cuda/archive/11.5.0/cusolver#static-link-lapack
  1059. _CUDAToolkit_find_and_add_import_lib(cusolver_lapack_static ALT lapack_static) # implementation detail static lib
  1060. list(APPEND cusolver_static_deps cusolver_lapack_static)
  1061. endif()
  1062. _CUDAToolkit_find_and_add_import_lib(cusolver DEPS ${cusolver_deps})
  1063. _CUDAToolkit_find_and_add_import_lib(cusolver_static DEPS ${cusolver_static_deps})
  1064. unset(cusolver_deps)
  1065. unset(cusolver_static_deps)
  1066. # nvGRAPH depends on cuRAND, and cuSOLVER.
  1067. _CUDAToolkit_find_and_add_import_lib(nvgraph DEPS curand cusolver)
  1068. _CUDAToolkit_find_and_add_import_lib(nvgraph_static DEPS curand_static cusolver_static)
  1069. # Process the majority of the NPP libraries.
  1070. foreach (cuda_lib nppial nppicc nppidei nppif nppig nppim nppist nppitc npps nppicom nppisu)
  1071. _CUDAToolkit_find_and_add_import_lib(${cuda_lib} DEPS nppc)
  1072. _CUDAToolkit_find_and_add_import_lib(${cuda_lib}_static DEPS nppc_static)
  1073. endforeach()
  1074. find_path(CUDAToolkit_CUPTI_INCLUDE_DIR cupti.h PATHS
  1075. "${CUDAToolkit_ROOT_DIR}/extras/CUPTI/include"
  1076. ${CUDAToolkit_INCLUDE_DIRS}
  1077. PATH_SUFFIXES "../extras/CUPTI/include"
  1078. "../../../extras/CUPTI/include"
  1079. NO_DEFAULT_PATH)
  1080. mark_as_advanced(CUDAToolkit_CUPTI_INCLUDE_DIR)
  1081. if(CUDAToolkit_CUPTI_INCLUDE_DIR)
  1082. set(_cmake_cupti_extra_paths extras/CUPTI/lib64/
  1083. extras/CUPTI/lib/
  1084. ../extras/CUPTI/lib64/
  1085. ../extras/CUPTI/lib/
  1086. ../../../extras/CUPTI/lib64/
  1087. ../../../extras/CUPTI/lib/)
  1088. _CUDAToolkit_find_and_add_import_lib(cupti
  1089. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1090. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1091. _CUDAToolkit_find_and_add_import_lib(cupti_static
  1092. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1093. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1094. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.2.0)
  1095. _CUDAToolkit_find_and_add_import_lib(nvperf_host
  1096. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1097. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1098. _CUDAToolkit_find_and_add_import_lib(nvperf_host_static
  1099. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1100. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1101. _CUDAToolkit_find_and_add_import_lib(nvperf_target
  1102. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1103. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1104. endif()
  1105. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.3.0)
  1106. _CUDAToolkit_find_and_add_import_lib(pcsamplingutil
  1107. EXTRA_PATH_SUFFIXES ${_cmake_cupti_extra_paths}
  1108. EXTRA_INCLUDE_DIRS "${CUDAToolkit_CUPTI_INCLUDE_DIR}")
  1109. endif()
  1110. endif()
  1111. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.1.0)
  1112. if(NOT TARGET CUDA::nvptxcompiler_static)
  1113. _CUDAToolkit_find_and_add_import_lib(nvptxcompiler_static)
  1114. if(TARGET CUDA::nvptxcompiler_static)
  1115. target_link_libraries(CUDA::nvptxcompiler_static INTERFACE CUDA::cudart_static_deps)
  1116. endif()
  1117. endif()
  1118. endif()
  1119. _CUDAToolkit_find_and_add_import_lib(nvrtc_builtins ALT nvrtc-builtins)
  1120. _CUDAToolkit_find_and_add_import_lib(nvrtc)
  1121. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.5.0)
  1122. _CUDAToolkit_find_and_add_import_lib(nvrtc_builtins_static ALT nvrtc-builtins_static)
  1123. if(NOT TARGET CUDA::nvrtc_static)
  1124. _CUDAToolkit_find_and_add_import_lib(nvrtc_static DEPS nvrtc_builtins_static nvptxcompiler_static)
  1125. if(TARGET CUDA::nvrtc_static AND WIN32 AND NOT (BORLAND OR MINGW OR CYGWIN))
  1126. target_link_libraries(CUDA::nvrtc_static INTERFACE Ws2_32.lib)
  1127. endif()
  1128. endif()
  1129. endif()
  1130. _CUDAToolkit_find_and_add_import_lib(nvml ALT nvidia-ml nvml)
  1131. _CUDAToolkit_find_and_add_import_lib(nvml_static ONLY_SEARCH_FOR libnvidia-ml.a libnvml.a)
  1132. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.0)
  1133. # Header-only variant. Uses dlopen().
  1134. if(NOT TARGET CUDA::nvtx3)
  1135. add_library(CUDA::nvtx3 INTERFACE IMPORTED)
  1136. target_include_directories(CUDA::nvtx3 SYSTEM INTERFACE "${CUDAToolkit_INCLUDE_DIRS}")
  1137. target_link_libraries(CUDA::nvtx3 INTERFACE ${CMAKE_DL_LIBS})
  1138. endif()
  1139. endif()
  1140. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 12.9)
  1141. if(NOT TARGET CUDA::nvtx3_interop)
  1142. _CUDAToolkit_find_and_add_import_lib(nvtx3_interop ALT nvtx3interop)
  1143. endif()
  1144. endif()
  1145. # nvToolsExt is removed starting in 12.9
  1146. if(CUDAToolkit_VERSION VERSION_LESS 12.9)
  1147. if(WIN32)
  1148. # nvtools can be installed outside the CUDA toolkit directory
  1149. # so prefer the NVTOOLSEXT_PATH windows only environment variable
  1150. # In addition on windows the most common name is nvToolsExt64_1
  1151. find_library(CUDA_nvToolsExt_LIBRARY
  1152. NAMES nvToolsExt64_1 nvToolsExt64 nvToolsExt
  1153. PATHS ENV NVTOOLSEXT_PATH
  1154. ENV CUDA_PATH
  1155. PATH_SUFFIXES lib/x64 lib
  1156. )
  1157. endif()
  1158. _CUDAToolkit_find_and_add_import_lib(nvToolsExt ALT nvToolsExt64)
  1159. if(CUDAToolkit_VERSION VERSION_GREATER_EQUAL 10.0)
  1160. # nvToolsExt is deprecated since nvtx3 introduction.
  1161. # Warn only if the project requires a sufficiently new CMake to make migration possible.
  1162. if(TARGET CUDA::nvToolsExt AND CMAKE_MINIMUM_REQUIRED_VERSION VERSION_GREATER_EQUAL 3.25)
  1163. 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.")
  1164. endif()
  1165. endif()
  1166. endif()
  1167. _CUDAToolkit_find_and_add_import_lib(OpenCL)
  1168. endif()
  1169. if(_CUDAToolkit_Pop_ROOT_PATH)
  1170. list(REMOVE_AT CMAKE_FIND_ROOT_PATH 0)
  1171. unset(_CUDAToolkit_Pop_ROOT_PATH)
  1172. endif()
  1173. unset(_CUDAToolkit_win_search_dirs)
  1174. unset(_CUDAToolkit_win_stub_search_dirs)