CMake should fail to configure if it knows the CUDA sources do not support by the target architectures
(See also this StackOverflow question about the workflow this issue is intended to enable.)
CMake supports specifying which kind of NVIDIA GPU targets (CUDA_ARCHITECTURES
) to compile CUDA code for: Recent CMake versions support CUDA_ARCHITECTURES as a target property and CMAKE_CUDA_ARCHITECTURES as a variable.
However - that does not indicate which architectures a CUDA source supports.
When writing a CUDA kernel (or device function code), one often:
- uses hardware features which are only available beginning with some GPU micro-architecture, e.g. inter-lane warp shuffle, or warp matrix-multiply-add (WMMA, a.k.a. "tensor cores").
- makes assumptions regarding resources, which are valid only on some GPU micro-architectures, e.g. using more than 96 KiB of static shared memory in a kernel.
- etc.
Now, suppose a user is trying to build a CUDA target tgt
, and that CMake is made aware, at configuration time, of:
- which micro-architectures are supported by the source file(s) of
tgt
- which architectures the generated commands should compile
tgt
for.
... then CMake should:
- Compute the intersection of supported micro-architectures of all sources;
- Compute the set difference of the target microarchitectures and the supported ones;
- If the difference is not empty, fail to complete the configuration, and notify the user of the situation, and the offending target and architectures (and perhaps individual source files).
This is an important feature to implement, because CUDA CMake project authors do very typically indeed want to restrict the targeted micro-architectures, especially with a minimum value - and doing so "manually" typically ends up meaning simply fixing a single target micro-architecture, or having writing auxiliary shell scripts, or examining the build system's GPU architectures (which ignores cross-build situations) etc.
Notes:
- Ability (2.) is possible using
CUDA_ARCHITECTURES
property on a target; ability (1.) would require a new property, e.g. aSUPPORTED_CUDA_ARCHITECTURES
property of source-files. - Naturally, the user may neglect to tell CMake which micro-architectures are supported by a source file. In that case, configuration should succeed optimistically, and the failure might occur during compilation.
- If the user has not told CMake which microarchitrectures to target, CMake could in principle figure out what targets the compiler (e.g. nvcc, clang) would choose by default, and fail based on this information; or it may only warn; or neither.