10

My project uses CMake-GUI with visual studio. There is no gpu card installed on my system. The visual studio solution generated sets the nvcc flags to compute_30 and sm_30 but I need to set it to compute_50 and sm_50.

I use CMake 3.10.1 and Visual studio 14 2015 with 64 bit compilation.

I wish to supersede the default setting from CMake. I am not using the Find CUDA method to search and add CUDA. I am adding CUDA as a language support in CMAKE and VS enables the CUDA Build customization based on that.

talonmies
  • 70,661
  • 34
  • 192
  • 269
C0D3R
  • 339
  • 1
  • 3
  • 12
  • 1
    It didnt work out for me. It is not gettting set. – C0D3R Jan 16 '18 at 04:42
  • 1
    I am not using the Find CUDA method to search and add CUDA. I am adding CUDA as a language support in CMAKE and VS enables the CUDA Build customization based on that. – C0D3R Jan 16 '18 at 05:10
  • Your question is not really abouy CMake; the CUDA architecture is just a compiler flag. Once you have it, setting it is not much of an issue. – einpoklum Apr 23 '18 at 15:39
  • Upgrading your CMake version is more easy than people realize. Their binary distributions are very tolerant of different system configurations, so you probably don't have to build it – einpoklum Jan 28 '22 at 08:36

3 Answers3

12

The correct way is:

target_compile_options(myTarget PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_50,code=sm_50>)

Select PRIVATE/PUBLIC as needed. This is the correct way to set per target flags.

Jimmy Pettersson
  • 465
  • 4
  • 13
10

With CMake 3.18 there is the new target property CUDA_ARCHITECTURES. From the documentation here:

set_property(TARGET myTarget PROPERTY CUDA_ARCHITECTURES 35 50 72)

Generates code for real and virtual architectures 30, 50 and 72.

set_property(TARGET myTarget PROPERTY CUDA_ARCHITECTURES 70-real 72-virtual)

Generates code for real architecture 70 and virtual architecture 72.

codecircuit
  • 101
  • 2
  • 3
5

So I was able to figure it out myself. The following way we can set it -

string(APPEND CMAKE_CUDA_FLAGS " -gencode arch=compute_50,code=sm_50")
Kolay.Ne
  • 1,345
  • 1
  • 8
  • 23
C0D3R
  • 339
  • 1
  • 3
  • 12
  • 1
    this will append to all targets, this is the old way of using CMAKE which does not help modularity. Modern CMAKE has these flags as per target properties where each target can be viewed as an object. – Jimmy Pettersson Jun 04 '21 at 14:05