phhhy
phhhy

Reputation: 67

CMake Cuda architecture flags

Is there any difference between

CMAKE_CUDA_ARCHITECTURES="75"

and

CMAKE_CUDA_FLAGS="--generate-code=arch=compute_75,code=[compute_75,sm_75]"?

I compiled a code in "Debug" mode and I get Segmentation Fault with the first version while the other one works fine.

Upvotes: 1

Views: 2993

Answers (1)

einpoklum
einpoklum

Reputation: 131646

These are two CMake variables. The second one is simply tacked on to the CUDA compiler line, typically nvcc. (I actually am not sure your second line is even valid... that gencode syntax always confuses me with all the commas and equals signs.)

I compiled a code in "Debug" mode and I get Segmentation Fault with the first version while the other one works fine.

That's why you need to keep track of what actually gets executed. So - assuming you're building with GNU make, run make VERBOSE=yes, and grep the output for the actual compilation lines. Or if it's ninja, or some Windows build mechanism, follow that - with the first option enabled, then with the second one. That way you'll know if you got the same program or not.


Another point of difference worth mentioning is that CMAKE_CUDA_ARCHITECTURES only came into use with CMake 3.18, so on most installed systems today (May 2021), it's not available :-(

with earlier CMake versions, you would write something like:

cuda_select_nvcc_arch_flags(ARCH_FLAGS 7.5)
list(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS})

instead of your second line.

For a longer discussion of this older mechanism, see the FindCUDA module documentation.

Upvotes: 2

Related Questions