C0D3R
C0D3R

Reputation: 349

How do I set CUDA architecture to compute_50 and sm_50 from cmake (3.10 version)?

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.

Upvotes: 11

Views: 19920

Answers (3)

codecircuit
codecircuit

Reputation: 121

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.

Upvotes: 12

C0D3R
C0D3R

Reputation: 349

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")

Upvotes: 5

Jimmy Pettersson
Jimmy Pettersson

Reputation: 464

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.

Upvotes: 12

Related Questions