Skip to content

Commit

Permalink
Strip host-compiler -std flag from NVCC line.
Browse files Browse the repository at this point in the history
Closes #8523.
  • Loading branch information
obilaniu committed Mar 12, 2021
1 parent 6911f49 commit fe216e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mesonbuild/compilers/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', None)
return OptionOverrideProxy(overrides, host_options)

def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args = self.get_ccbin_args(options)
Expand Down
20 changes: 20 additions & 0 deletions test cases/cuda/16 multistd/main.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <cuda_runtime.h>
#include <iostream>

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;
}
4 changes: 4 additions & 0 deletions test cases/cuda/16 multistd/meson.build
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fe216e8

Please sign in to comment.