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

C0D3R picture C0D3R · Jan 16, 2018 · Viewed 8.7k times · Source

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.

Answer

Jimmy Pettersson picture Jimmy Pettersson · Jan 31, 2019

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.