From fcf701864a36394cfb2b8bcc0b5b8534fa79fc74 Mon Sep 17 00:00:00 2001 From: Olexa Bilaniuk Date: Fri, 12 Mar 2021 18:09:22 -0500 Subject: [PATCH] Strip host-compiler -std flag from NVCC line. Closes #8523. --- mesonbuild/compilers/cuda.py | 12 +++++++++++- test cases/cuda/16 multistd/main.cu | 20 ++++++++++++++++++++ test cases/cuda/16 multistd/meson.build | 4 ++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test cases/cuda/16 multistd/main.cu create mode 100644 test cases/cuda/16 multistd/meson.build diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index 411dff1a145c..aaa2b8e17dd2 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -616,8 +616,18 @@ def get_options(self) -> 'KeyedOptionDictType': return opts def _to_host_compiler_options(self, options: 'KeyedOptionDictType') -> 'KeyedOptionDictType': + """ + Convert an NVCC Option set to a host compiler's option set. + """ + + # We must strip the -std option from the host compiler option set, as NVCC has + # its own -std flag that may not agree with the host compiler's. overrides = {name: opt.value for name, opt in options.items()} - return OptionOverrideProxy(overrides, self.host_compiler.get_options()) + overrides.pop(OptionKey('std', machine=self.for_machine, + lang=self.host_compiler.language), None) + host_options = self.host_compiler.get_options().copy() + host_options.pop('std', '') + return OptionOverrideProxy(overrides, host_options) def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = self.get_ccbin_args(options) diff --git a/test cases/cuda/16 multistd/main.cu b/test cases/cuda/16 multistd/main.cu new file mode 100644 index 000000000000..a2ffba4896c3 --- /dev/null +++ b/test cases/cuda/16 multistd/main.cu @@ -0,0 +1,20 @@ +#include +#include + +auto cuda_devices(void) { + int result = 0; + cudaGetDeviceCount(&result); + return result; +} + + +int main(void) { + int n = cuda_devices(); + if (n == 0) { + std::cout << "No Cuda hardware found. Exiting.\n"; + return 0; + } + + std::cout << "Found " << n << "Cuda devices.\n"; + return 0; +} diff --git a/test cases/cuda/16 multistd/meson.build b/test cases/cuda/16 multistd/meson.build new file mode 100644 index 000000000000..4769a87dddd1 --- /dev/null +++ b/test cases/cuda/16 multistd/meson.build @@ -0,0 +1,4 @@ +project('C++-CUDA multi-std', 'cpp', 'cuda', version : '1.0.0', default_options : ['cpp_std=c++17', 'cuda_std=c++14']) + +exe = executable('prog', 'main.cu') +test('cudatest', exe)