CUDA DEVICE_LINK with multiple -Xcompiler options
The DEVICE_LINK
generator expression and -Xcompiler
with multiple sub options does not behave as (I) expected (under windows atleast), generating invalid NVCC commands with some usage options.
-Xcompiler
(--compiler-options) can be passed multiple options at once.
This is documented as being a comma separated list by nvcc --compiler-options options,...
.
In practice, it's also possible to pass multiple options as a quoted, space-separated string --compiler-options "option_a option_b"
; or multiple --compiler-options
commands can be passed --compiler-options option_a --compiler-options option_b
This would all also apply to --linker-options/-Xlinker
, --archive-otpions/-Xarchive
, --ptxas-options/-Xptxas
and --nvlink-options/-Xnvlink
.
At link time, under windows we want to pass /wd4100,/WX
to suppress some warnings that appear at link time under windows, but otherwise promote warnings to errors for CI.
We've managed to achieve this using the following, however initially we tried several other combinations of passing these to DEVICE_LINK
with no success, resulting in NVCC errors.
target_link_options(${NAME} PRIVATE $<DEVICE_LINK:-Xcompiler "/wd4100 /WX">)
<AdditionalOptions>-forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets -Xcompiler "/wd4100 /WX"</AdditionalOptions>
Without adding anything to the DEVICE_LINK
generator expression, the AdditionalOptions
portion of CudaLink
in the .vcxproj
file looks like:
<AdditionalOptions>-forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets </AdditionalOptions>
Just adding a single option to -Xcompiler
works as expected
target_link_options(${NAME} PRIVATE $<DEVICE_LINK:-Xcompiler /wd4100>)
<AdditionalOptions>-forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets -Xcompiler /wd4100</AdditionalOptions>
However, adding -Xcompiler /wd4100,/Wx
does not work as (I) expected, leading to an NVCC error as it does not know what to do with C:/WX
:
target_link_options(${NAME} PRIVATE $<DEVICE_LINK:-Xcompiler /wd4100,/WX>)
<AdditionalOptions>-forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets -Xcompiler /wd4100 /WX</AdditionalOptions>
Passing multiple options does not appear to work either:
target_link_options(${NAME} PRIVATE $<DEVICE_LINK:-Xcompiler /wd4100>)
target_link_options(${NAME} PRIVATE $<DEVICE_LINK:-Xcompiler /WX>)
<AdditionalOptions>-forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets -Xcompiler /wd4100 /WX</AdditionalOptions>
And neither did passing quoted, comma separated options.
target_link_options(${NAME} PRIVATE $<DEVICE_LINK:-Xcompiler "/wd4100,/WX">)
<AdditionalOptions>-forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets -Xcompiler /wd4100 /WX</AdditionalOptions>
This is using 3.18RC2, and Visual Studio 16/2019 with CUDA 11.0 RC.
I've not tested this behaviour under linux/Makefile generators (we only need one Xcompiler option currently).