Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 336
C0D3R Avatar asked Jan 16 '18 04:01

C0D3R


3 Answers

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.

like image 91
codecircuit Avatar answered Sep 26 '22 03:09

codecircuit


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.

like image 41
Jimmy Pettersson Avatar answered Sep 27 '22 03:09

Jimmy Pettersson


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")
like image 40
C0D3R Avatar answered Sep 26 '22 03:09

C0D3R