I'm unable to get modern cmake (per target) to set more than one CUDA gencode flag.
CMake example:
target_compile_options(myHeaderLib INTERFACE
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_50,code=sm_50>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_52,code=sm_52>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_53,code=sm_53>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_60,code=sm_60>
$<$<COMPILE_LANGUAGE:CUDA>:-gencode arch=compute_62,code=sm_62>
)
This will output:
... -gencode arch=compute_50,code=sm_50 arch=compute_52,code=sm_52 arch=compute_53,code=sm_53
But what is needed is:
... -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_53,code=sm_53 ...
And NO just settings the ${CUDA_NVCC_FLAGS} is not a robust solution (that's not how modern CMAKE should be done).
This is because of CMake "de-duplication" strategy for the compile options.
With target_compile_options
you create correct option's list
-gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 ...
but CMake removes all -gencode
except the first one:
-gencode arch=compute_50,code=sm_50 arch=compute_52,code=sm_52 ...
There is bugreport about needs to disable CMake "de-duplication" in some cases, and it has been resolved in 3.12 version by adding SHELL:
construction.
Since CMake 3.12 this should work:
target_compile_options(myHeaderLib INTERFACE
"SHELL:-gencode arch=compute_50,code=sm_50"
"SHELL:-gencode arch=compute_52,code=sm_52"
)
SHELL:
worksFirst, placing combined options into double quotes prevents CMake to "de-duplicate" common options: CMake sees different strings
-gencode arch=compute_50,code=sm_50
-gencode arch=compute_52,code=sm_52
and doesn't think of them as a duplicated.
Then, a construction SHELL
explains CMake that a string within given double quotes is needed to be splitted into separate command line options. But this splitting is performed after "de-duplication" stage, so repeated -gencode
from different SHELL:
strings are not removed.
I know it's been a while. But recently I filed an issue and it turns out generators can also works perfectly. The trick to combine "SHELL:" with generators is to surround generators with double quotes.
Here's the link where the maintainer of cmake points out my mistake. Hope this helps others in the future.
target_compile_options(foo PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-gencode arch=compute_60,code=sm_60>"
)
target_compile_options(foo PRIVATE
"$<$<COMPILE_LANGUAGE:CUDA>:SHELL:-gencode arch=compute_52,code=sm_52 -gencode arch=compute_50,code=sm_50>"
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With