1

Suppose I have a CUDA project and I'm writing its CMakeLists.txt.

In my project, I have several .cu source files with kernels, each of which has a minimum NVIDIA microarchitecture version it supports.

In my CMakeLists.txt, I would like to be able to...

  • Detect, or at least be able to specify, this minimum uarch of each file (not the set of uarchitectures to build for - a minimum for which the target may be built).
  • (perhaps) Compute and print the intersection of these acceptable ranges of compute capabuilties (since I've only talked about minimum - it's the maximum of the minima).
  • Have CMake configuration fail if there are no GPUs on the system supporting a uarch in the intersection (... unless this is a cross-build, in which case the user has specified the target architecture/s and the build system GPUs are irrelevant).
  • Be able to specify which GPU I'm targetting, so that only its CC is checked against the range of acceptable uarches/CC values.

I don't really see any of that when looking at the documentation, e.g. at the CUDA_ARCHITECTURES and CMAKE_CUDA_ARCHITECTURES pages.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • This is strange requirement: `fail if there are no GPUs on the system supporting a uarch in the intersection.` - example where this requirement doesn't make sense: build application in continues integration system which do not have required hardware, but then for tests. Having to restrictive build system is bad thing. – Marek R Jul 18 '23 at 12:32
  • @MarekR: That would be an example of a cross-build. I'll clarify in the question. – einpoklum Jul 18 '23 at 14:50
  • do it outside of CMake. use a shell script, python program, etc. run it via CMake's `execute_process()` and act on its results. – nega Jul 19 '23 at 03:37
  • @nega: But CMake should support this itself - it's one of, if not the, most common scenario when building GPU-targeting CUDA code. Of course I can always do things instead of CMake by programming them myself and running execute_process()... – einpoklum Jul 19 '23 at 06:08
  • to detect your minimum uarch you'll have to "shell out", or slurp the files into cmake strings, and do a substring/regex search. to specify your min uarch use source _file properties_ (`COMPILE_*`) to set the relevant compiler flags. you'll have to roll your own function/macro to compute the intersection of cmake lists (or google for one, or ask a separate question here, etc). to detect capabilities of installed GPU's you'll have to "shell out". to specify the GPU you're targeting, use _target properties_ to set the relevant compiler/linker flags. – nega Jul 19 '23 at 17:16

1 Answers1

0

Apparently, CMake does not support this. I have filed a bug with Kitware for adding such support via a source file property and some set arithmetic during configuration time.

einpoklum
  • 118,144
  • 57
  • 340
  • 684