Commit Graph

105 Commits

Author SHA1 Message Date
Brad King
781a67bf5e CUDA/Clang: Determine cross-compiling target from CMAKE_CUDA_COMPILER_TARGET
When cross-compiling CUDA with Clang, `CMAKE_CUDA_COMPILER_TARGET` is
typically set to the target triple.  Use it to select the CUDA toolkit
target directory.
2025-03-04 13:51:29 -05:00
Brad King
40eeca77c3 CUDA/Clang: Sync target directory table with FindCUDAToolkit
Since commit 6636693134 (FindCUDAToolkit: Re-unify with
Internal/CUDAToolkit, 2020-06-11, v3.18.0-rc2~6^2~7) the table is
duplicated.

Update the CUDA target directory table for Clang to account for changes
to the equivalent table in FindCUDAToolkit:

* commit bcdd486bf7 (CUDA: Enable support on QNX, 2020-10-30,
                     v3.19.0-rc3~8^2~1)
* commit 743d4181b4 (FindCUDAToolkit: Support cross-compilation to
                     sbsa-linux, 2023-01-11, v3.26.0-rc1~118^2)
2025-03-04 13:51:29 -05:00
Kitware Robot
1772622772 LICENSE: Replace references to Copyright.txt with LICENSE.rst
```
git grep -lz 'Copyright.txt or https://cmake.org/licensing ' |
  while IFS= read -r -d $'\0' f ; do
    sed -i '/Copyright.txt or https:\/\/cmake.org\/licensing / {
              s/Copyright.txt/LICENSE.rst/
            }' "$f" ; done
```
2025-03-03 10:43:35 -05:00
Brad King
88c740462c CUDA/Clang: Add support for MSVC ABI on Windows using GNU-like frontend
Fixes: #20776
2024-01-22 09:33:54 -05:00
Brad King
79f3f29e50 CUDA: Parse NVCC implicit compile/link information in Visual Studio generators
Refactoring in commit deff0e638d (CUDA: Factor out helper to parse NVCC
implicit compiler and linker flags, 2023-09-15, v3.28.0-rc1~63^2~6)
incorrectly dropped detection of the default CUDA architecture and
the CUDA toolkit include directories from the code path used for
Visual Studio generators.  However, CMakeNVCCParseImplicitInfo is
now general enough that we no longer need a VS-specific code path.

Fixes: #25378
2023-11-01 13:51:21 -04:00
Brad King
b3a1f17567 CUDA: Factor out helper to validate CMAKE_CUDA_ARCHITECTURES
Prepare to use it for other languages.
2023-09-21 15:34:28 -04:00
Brad King
0db0fe7958 CUDA: Factor out helper to compute all CUDA architectures
Prepare to use it for other languages.
2023-09-21 15:34:28 -04:00
Brad King
c16f1e2b93 CUDA: Factor out helper to find CUDA Toolkit for compiler
Prepare to use it for other languages.
2023-09-21 15:34:28 -04:00
Brad King
a6841a967b CUDA: Factor out helper to filter implicit link libraries
Prepare to use it for other languages.
2023-09-21 15:34:27 -04:00
Brad King
deff0e638d CUDA: Factor out helper to parse NVCC implicit compiler and linker flags
Prepare to use it for other languages.
2023-09-21 15:34:27 -04:00
Brad King
f125dfcd30 CUDA: Clarify order of logic finding CUDA Toolkit for compiler
Finish all the search logic before using any results.
2023-09-21 15:34:27 -04:00
Brad King
7b2aec0fef CUDA: Clarify logic detecting compiler default CUDA architectures
Improve variable names and comments.

Remove a comment missed by commit c267ed205a (CUDA: Defer architecture
testing to the compiler testing step, 2022-04-25, v3.24.0-rc1~222^2)
about architecture verification.
2023-09-21 15:34:27 -04:00
Brad King
69a5ef7cc0 CUDA: Simplify isolation of work variables for determining compiler
Unset variables as soon as we are done with them.
Rename one work variable to a private name.
2023-09-21 15:34:27 -04:00
Brad King
8a966debe3 CUDA: Combine consecutive blocks using same condition for determining compiler 2023-09-21 15:34:26 -04:00
Brad King
72efbeadae CUDA: Simplify CMAKE_GENERATOR references for determining compiler 2023-09-21 15:34:23 -04:00
Brad King
f6ed2585e5 Modules: Record system inspection steps in the configure log
Replace old-style `file(APPEND .../CMake{Output,Error}.log)` logging
with calls to `message(CONFIGURE_LOG)` to record the steps in the
`CMakeConfigureLog.yaml` configure log instead.

Issue: #23200
2023-01-18 17:59:10 -05:00
Brad King
dae13c214f Merge topic 'cuda_support_sm90a'
234aa7e0aa CUDA: Support upcoming sm90a architecture

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7649
2022-09-07 09:48:25 -04:00
Robert Maynard
234aa7e0aa CUDA: Support upcoming sm90a architecture
The architecture values are being extended to have at time
a trailing `a`. This updates the CMake regex to support
this syntax.
2022-09-06 11:09:46 -04:00
Robert Maynard
93f2cd5b7c CMakeParseImplicitLinkInfo: Better detection of msvc
Use the compiler id information in addition to checking for `cl.exe`.
2022-09-02 08:04:39 -04:00
Brad King
7bf5200699 CUDA: Restore CMAKE_CUDA_ARCHITECTURES support for -real and -virtual suffixes
Fix the validation regex added by commit c267ed205a (CUDA: Defer
architecture testing to the compiler testing step, 2022-04-25) to
allow these values.
2022-04-29 09:07:53 -04:00
Brad King
c267ed205a CUDA: Defer architecture testing to the compiler testing step
Verifying the architectures during compiler identification is redundant,
and requires a lot more up-front information than we should need.
It also causes unsupported architectures to break the compiler id and
version detection, so the resulting output from CMake does not report
the compiler version, which is useful information to know why the
specified architectures are not supported.

The "detecting compiler ABI info" and "check for working compiler" steps
already pass `CMAKE_CUDA_ARCHITECTURES` into their test projects.
Therefore we can just drop the earlier architecture testing.  Bad
architectures will be reported as a not-working compiler, and the
output will include the compiler's error message.

This reverts the approach from:

* commit 19cc5bc296 (CUDA: Throw error if user-specified architectures
                     don't work, 2020-05-26, v3.18.0-rc1~79^2)
* commit 650c1029a0 (CUDA: Detect non-working user-specified architectures
                     on NVCC, 2020-05-28, v3.18.0-rc1~51^2)
* commit 01428c5560 (CUDA: Fail fast if CMAKE_CUDA_ARCHITECTURES
                     doesn't work during detection,
                     2020-08-29, v3.19.0-rc1~241^2).

Their goal was in part to avoid waiting until the test for working
compiler to detect unsupported architectures.  However, experience has
shown that failing earlier is more trouble than it's worth.

Fixes: #23161
Issue: #20756
2022-04-25 15:01:36 -04:00
Robert Maynard
4040173ed3 CUDA: Generate better error message when detecting nvcc
Issue: #23322, #23323
2022-03-21 15:18:22 -04:00
Brad King
d1b48bfabd CUDA: Add support for CUDA_ARCHITECTURES=native
CUDA 11.6 added the `nvcc -arch=native` flag to automatically compile
for the host GPUs' architectures.  Add support for specifying this
special `native` value in `CMAKE_CUDA_ARCHITECTURES` and
`CUDA_ARCHITECTURES`.  During the compiler ABI detection step,
detect the native architectures so we can pass them explicitly
when using Clang or older versions of nvcc.

Fixes: #22375
2022-03-10 09:27:29 -05:00
Brad King
632752d62e CUDA: Add FIXME comments about deferring architecture testing
Issue: #23161
2022-03-10 09:26:13 -05:00
Robert Maynard
2a79b647fa CUDA: Restore support for CMAKE_CUDA_ARCHITECTURES=OFF
Fixes: #23309
2022-03-09 12:30:12 -05:00
Brad King
5c1f5357b0 VS: Fix CUDA compiler id with CMAKE_CUDA_ARCHITECTURES={all,all-major}
Skip the architecture verification check for these values on Visual
Studio.  It cannot be implemented correctly until future work delays the
check to the main compiler test step.

Issue: #23164, #23161
2022-03-02 15:49:14 -05:00
Brad King
2796d6eeca CUDA: Fix CMAKE_CUDA_ARCHITECTURES=all/all-major with NVCC 11.5+
Changes in commit 8f64df0a7c (CUDA: Generic all and all-major support,
2021-12-19, v3.23.0-rc1~23^2) broke our architecture verification checks
when using `-arch={all,all-major}` with NVCC 11.5+.  If we test the
compiler with `-arch={all,all-major}`, we have no expected list of
architectures, so skip the check.

Fixes: #23278
2022-03-01 12:16:40 -05:00
Brad King
fe64c49e72 CUDA: Simplify CMAKE_CUDA_ARCHITECTURES special value logic
Refactor the logic checking `CMAKE_CUDA_ARCHITECTURES` special values.
Switch on the value first, and then make other decisions for each case.
This makes room for other special values to be added later.
2022-02-28 21:30:23 -05:00
Raul Tambre
8f64df0a7c CUDA: Generic all and all-major support
Commit 14d8a276 (CUDA: Support nvcc 11.5 new -arch=all|all-major flags,
2021-08-17) added all and all-major options to CUDA_ARCHITECTURES. These are
fairly generic and likely to see real-world use by distributors. Thus it's
desirable to support these also for Clang and older NVCC versions.

The supported architectures are dependent on the toolkit version. We determine
the toolkit version prior to compiler detection. For NVCC we get the version
from the vendor identification output, but for Clang we need to invoke NVCC
separately.

The architecture information is mostly based on the Wikipedia list with the
earliest supported version being CUDA 7.0. This could be documented and
expanded in the future to allow projects to query CUDA toolkit version and
architecture information.
For Clang we additionally constrain based on its support.

Additionally the architecture mismatch detection logic is fixed, improved and
updated for generic support:
* Commit 01428c55 (CUDA: Fail fast if CMAKE_CUDA_ARCHITECTURES doesn't work
  during detection, 2020-08-29) enabled CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS
  if CMAKE_CUDA_ARCHITECTURES is specified. This results in
  CMakeDetermineCompilerID.cmake printing the compiler error and our code for
  presenting the mismatch in a user-friendly way being useless. The custom
  logic seems preferable so go back to not enabling it.
* Commit 14d8a276 (CUDA: Support nvcc 11.5 new -arch=all|all-major flags,
  2021-08-17) tried to support CMP0054 but forgot to add x to the interpolated
  result. Thus the conditions would always evaluate to false. This is fixed as
  a byproduct of removing NVIDIA specific checks, improving the error message
  and replacing architectures_mode with a simpler architectures_explicit.

Visual Studio support omits testing the flags during detection due to
complexities in determining the toolkit version when using it.
A long-term proper implementation would be #23161.

Implements #22860.
2022-02-01 18:25:20 +02:00
Raul Tambre
daf372c4d6 CUDA: Fix issuing error if default architecture detection fails
We require CUDA_ARCHITECTURES to be set for targets (see CMP0104). If not set
anything after compiler detection such as ABI detection will fail to generate.
This means we need to error if CMAKE_CUDA_ARCHITECTURES is not set to a valid
value as a result of compiler detection.

Currently we fail to issue the error if compiler detection failed and the ID is
unset. In such a case we won't define detected_architecture making the code
responsible for the error unreachable.

Simplify the detection of architectures used during compiler detection by
always detecting all of them, which enables us to simply the check in the
"default to compiler" path if CMAKE_CUDA_ARCHITECTURES is empty.
As a result we need to move the error checking and CMAKE_CUDA_ARCHITECTURES=OFF
handling fully into the default path thus simplifying the code and unifying the
code paths for NVCC and CUDA.
This also happens to fix:
1. CMAKE_CUDA_ARCHITECTURES=OFF on Clang.
2. A theoretical issue of a compiler defaulting to multiple architectures.

I've additionally added printing of the compiler output along the error to
better reveal possible underlying compiler/system configuration issues.

Fixes #23010.
2022-01-27 22:11:13 +02:00
Raul Tambre
7a0d098352 CUDA: Error on empty/invalid CMAKE_CUDA_ARCHITECTURES set by user
If empty we otherwise treat it the same as unset in most places, but still end
up failing eventually with a confusing "Failed to find a working CUDA
architecture".

This also detects some other basic invalid ones (e.g. "al").
2022-01-27 22:11:13 +02:00
Raul Tambre
5f667d783a CUDA: Actually use reverse architecture deprecation order for Clang
The code now matches what the comment describes.
This mistake seems to have been present since the initial introduction in
commit 5df21adf (CUDA: Add support for Clang compiler, 2020-05-07).
2022-01-27 21:43:22 +02:00
Raul Tambre
70f5d9eb49 CUDA: Fix CMAKE_CUDA_COMPILER_ARG1 cache description
Also corrected the misleading indentation.
2022-01-15 21:55:06 +02:00
Robert Maynard
14d8a2768d CUDA: Support nvcc 11.5 new -arch=all|all-major flags 2021-11-01 14:57:58 -04:00
samuel100u
a1f0ddcbb7 CUDA: Fix detection of implicit link information with CUDA 6.5
Fixes: #22701
2021-09-30 09:33:17 -04:00
Robert Maynard
125bbf07b1 CUDA: Extract nvvm libdevice location from compiler verbose output
Depending on the CUDA installation the nvvm/libdevice folder can
be in different locations. Since `nvcc` outputs the expected location use that when possible.
2021-07-22 15:49:08 -04:00
Brad King
26751418a3 Merge topic 'improve_cuda_toolkit_extraction_regex'
5e931c5a97 CUDA: improve regex for CUDA Toolkit root from nvcc verbose output

Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Raul Tambre <raul@tambre.ee>
Merge-request: !6094
2021-05-07 09:12:08 -04:00
Robert Maynard
5e931c5a97 CUDA: improve regex for CUDA Toolkit root from nvcc verbose output
The original regular expression was greedy and would match any
environment variable ending with `TOP` (like `DESKTOP`). This is an
issue on windows where `nvcc -v` would output all environment variables
before the compiler's verbose output.

To resolve this issue we use a tighter match algorithm that looks
for `#$ TOP=` instead of `TOP=`.

Fixes: #22158
2021-05-06 12:08:24 -04:00
unknown
625ef88a92 CUDA: Add CMAKE_CUDA_HOST_COMPILER support on Windows non-VS generators 2021-04-22 11:40:46 -04:00
Tobias Ribizel
55233eee42
CUDA: Add support for finding nvcc in CUDA_PATH
Previously, nvcc needed to be present in PATH or specified by CUDACXX.
On Windows with vcpkg, the PATH is heavily modified, which lead to
nvcc not being found with the Ninja generator.
2021-03-15 21:34:05 +01:00
Brad King
a70f8770f2 Merge topic 'better_cuda_compiler_detection_error_messages' into release-3.20
a0fc64ac24 CUDA: Improve error messages when CUDA compiler detection fails

Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Raul Tambre <raul@tambre.ee>
Merge-request: !5844
2021-02-24 09:47:39 -05:00
Brad King
35b448a7dd Merge topic 'better_cuda_compiler_detection_error_messages'
a0fc64ac24 CUDA: Improve error messages when CUDA compiler detection fails

Acked-by: Kitware Robot <kwrobot@kitware.com>
Reviewed-by: Raul Tambre <raul@tambre.ee>
Merge-request: !5844
2021-02-24 09:47:39 -05:00
Robert Maynard
a0fc64ac24 CUDA: Improve error messages when CUDA compiler detection fails 2021-02-23 09:21:42 -05:00
Brad King
9ea66b2d86 CUDA: Capture all nvcc output when extracting toolkit root
Since commit fb2afef620 (CUDA: Support nvcc symlinking to ccache,
2021-01-07) and commit 3cef91a321 (CUDA: Always extract CUDA Toolkit
root from nvcc verbose output, 2021-02-03) we always run the command
`nvcc -v __cmake_determine_cuda` to look for the toolkit root in its
stderr.  On Windows, that command may print to stdout instead, so
capture that as well.
2021-02-12 07:23:48 -05:00
Robert Maynard
3cef91a321 CUDA: Always extract CUDA Toolkit root from nvcc verbose output
Fixes #21750, #21763

Given that NVCC can be provided by multiple different sources (NVIDIA HPC SDK, CUDA Toolkit, distro)
each of which has a different layout, we need to extract the CUDA toolkit root from the compiler
itself, allowing us to support numerious different scattered toolkit layouts.

The NVIDIA HPC SDK specifically ships two copies of nvcc one in
`compilers/bin/` and one in `cuda/bin`. Thus when using
`compilers/bin/nvcc` the Toolkit root logic fails.
2021-02-08 12:13:01 -08:00
Rong Ou
fb2afef620 CUDA: Support nvcc symlinking to ccache
Invoke `nvcc -v` to find the real CUDA bin directory.
This is needed if `nvcc` is a symlink to `ccache` or `colornvcc`.

Fixes: #21177
2021-01-11 00:18:04 -08:00
Raul Tambre
c4ae9384ff CUDA: Initialize CMAKE_CUDA_ARCHITECTURES using $ENV{CUDAARCHS}
NVCC's default architecture may be newer than the one supported by the
machine's GPU.
In such cases it's useful to have an environment variable for initializing
CMAKE_CUDA_ARCHITECTURES to avoid specifying it for every invocation.
2020-11-30 17:57:11 +02:00
Raul Tambre
046e454fdd CUDA: Error if can't determine toolkit library root
Finding the toolkit is required for Clang and is assumed to have been correctly
found by FindCUDAToolkit if the CUDA language is found.
Error out early with an useful error instead of failing later on due to the
path not being set.
2020-11-22 11:30:01 +02:00
Raul Tambre
440dc98b07 CUDA: Clang CUDA 11.1 support
version.txt is gone from CUDA 11.1 installations, but the rest is the same.
Instead of looking for version.txt look for <CUDA path>/nvvm/libdevice, which
is the main thing that Clang requires (though it also checks for the existence
of bin and include).

Fixes #21353.
2020-11-22 11:30:01 +02:00
Raul Tambre
c63fe01835 CUDA: Clang separable compilation
For NVCC the compiler takes care of device linking when passed the "-dlink"
flag.
Clang doesn't support such magic and requires the buildsystem to do the work
that NVCC does behind the scenes.

The implementation is based on Bazel's device linking documentation:
7cabcdf073/third_party/nccl/build_defs.bzl.tpl (L259)

Closes: #20726
2020-09-24 15:19:54 -04:00