From 10d4c6b5b5db90a402ae60cd3e49e810d9fd0d74 Mon Sep 17 00:00:00 2001 From: Artem Belevich Date: Mon, 16 Sep 2024 17:00:37 -0700 Subject: [PATCH] Propagate compiler flags down to libcu++ LIT tests In order to run libcu++ tests with clang lit has to use correct compiler settings. It currently appears to rely on clang automatically finding and using the default CUDA installation, but that's not necessarily the CUDA that the build itself may have been configured to use. Clang builds may also require building them with the host libc++, instead of the default libstdc++. That requires propagation of the top-level CFLAGS specified by the user. --- libcudacxx/test/libcudacxx/CMakeLists.txt | 3 ++- libcudacxx/test/libcudacxx/lit.site.cfg.in | 1 + libcudacxx/test/utils/libcudacxx/compiler.py | 8 +++++++- libcudacxx/test/utils/libcudacxx/test/config.py | 11 +++++++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/libcudacxx/test/libcudacxx/CMakeLists.txt b/libcudacxx/test/libcudacxx/CMakeLists.txt index b699b4b89f..dedd4a091c 100644 --- a/libcudacxx/test/libcudacxx/CMakeLists.txt +++ b/libcudacxx/test/libcudacxx/CMakeLists.txt @@ -36,7 +36,8 @@ else() # NOT LIBCUDACXX_TEST_WITH_NVRTC set(LIBCUDACXX_FORCE_INCLUDE "-include ${libcudacxx_SOURCE_DIR}/test/libcudacxx/force_include.h") set(LIBCUDACXX_CUDA_COMPILER "${CMAKE_CUDA_COMPILER}") set(LIBCUDACXX_CUDA_TEST_WITH_NVRTC "False") - set(LIBCUDACXX_TEST_COMPILER_FLAGS "-DLIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE") + set(LIBCUDACXX_TEST_COMPILER_FLAGS "${CMAKE_CUDA_FLAGS} -DLIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE") + set(LIBCUDACXX_TEST_LINKER_FLAGS "${CMAKE_CUDA_FLAGS}") endif() if (NOT MSVC AND NOT ${CMAKE_CUDA_COMPILER_ID} STREQUAL "Clang") diff --git a/libcudacxx/test/libcudacxx/lit.site.cfg.in b/libcudacxx/test/libcudacxx/lit.site.cfg.in index ae6e699c49..400ed6ce2a 100644 --- a/libcudacxx/test/libcudacxx/lit.site.cfg.in +++ b/libcudacxx/test/libcudacxx/lit.site.cfg.in @@ -25,6 +25,7 @@ config.test_compiler_flags = "@LIBCUDACXX_TEST_COMPILER_FLAGS@" config.compute_archs = "@LIBCUDACXX_COMPUTE_ARCHS_STRING@" config.nvcc_host_compiler = "@CMAKE_CUDA_HOST_COMPILER@" +config.cuda_path = "@CMAKE_CUDA_COMPILER_TOOLKIT_ROOT@" config.executor = "@LIBCUDACXX_EXECUTOR@" config.llvm_unwinder = False diff --git a/libcudacxx/test/utils/libcudacxx/compiler.py b/libcudacxx/test/utils/libcudacxx/compiler.py index 59f01ed7cf..e1e1e06152 100644 --- a/libcudacxx/test/utils/libcudacxx/compiler.py +++ b/libcudacxx/test/utils/libcudacxx/compiler.py @@ -24,7 +24,7 @@ def __init__(self, path, first_arg, verify_flags=None, use_verify=False, modules_flags=None, use_modules=False, use_ccache=False, use_warnings=False, compile_env=None, - cxx_type=None, cxx_version=None): + cxx_type=None, cxx_version=None, cuda_path=None): self.source_lang = 'c++' self.path = path self.first_arg = first_arg or '' @@ -48,6 +48,7 @@ def __init__(self, path, first_arg, self.compile_env = None self.type = cxx_type self.version = cxx_version + self.cuda_path = cuda_path if self.type is None or self.version is None: self._initTypeAndVersion() @@ -225,6 +226,8 @@ def _basicCmd(self, source_files, out, mode=CM_Default, flags=[], cmd += ['-o', out] if input_is_cxx: cmd += ['-x', self.source_lang] + if self.type == "clang" and self.source_lang == 'cu' and self.cuda_path is not None: + cmd += ['--cuda-path=' + self.cuda_path] if isinstance(source_files, list): cmd += source_files elif isinstance(source_files, str): @@ -395,6 +398,9 @@ def hasCompileFlag(self, flag): # exit code. -Werror is supported on all known non-nvcc compiler types. if self.type is not None and self.type != 'nvcc' and self.type != 'msvc': flags += ['-Werror', '-fsyntax-only'] + if self.type == 'clang' and self.source_lang == 'cu': + flags += ['-Wno-unused-command-line-argument'] + empty_cpp = os.path.join(os.path.dirname(os.path.abspath(__file__)), "empty.cpp") cmd, out, err, rc = self.checkCompileFlag(empty_cpp, out=os.devnull, flags=flags) if out.find('flag is not supported with the configured host compiler') != -1: diff --git a/libcudacxx/test/utils/libcudacxx/test/config.py b/libcudacxx/test/utils/libcudacxx/test/config.py index d1aef968a2..8d4d635866 100644 --- a/libcudacxx/test/utils/libcudacxx/test/config.py +++ b/libcudacxx/test/utils/libcudacxx/test/config.py @@ -315,8 +315,15 @@ def configure_cxx(self): if not cxx: self.lit_config.fatal('must specify user parameter cxx_under_test ' '(e.g., --param=cxx_under_test=clang++)') - self.cxx = CXXCompiler(cxx, cxx_first_arg) if not self.cxx_is_clang_cl else \ - self._configure_clang_cl(cxx) + if self.cxx_is_clang_cl: + self.cxx = self._configure_clang_cl(cxx) + else: + self.cxx = CXXCompiler( + cxx, + cxx_first_arg, + compile_flags=self.get_lit_conf("cmake_cxx_flags"), + cuda_path= self.get_lit_conf('cuda_path'), + ) cxx_type = self.cxx.type if cxx_type is not None: assert self.cxx.version is not None