[OpenMP][CMake] Pass --cuda-path to regression tests.

The OpenMP runtime can be compiled using a CUDA installed at non-default
location with the -DCUDA_TOOLKIT_ROOT_DIR setting. However, check-openmp
will fail afterwards because Clang needs to know where to find the CUDA
headers.

Fix by passing -cuda-path to Clang using the value of
CUDA_TOOLKIT_ROOT_DIR which has been determined by CMake. Also set
LD_LIBRARY_PATH such that it can find the cuda runtime when executing.
This will ensure that the regression test do not depend on the current
environment, but use the environment it was configured for.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D101266
This commit is contained in:
Michael Kruse 2021-04-27 16:27:32 -05:00
parent 87fc97169e
commit 3244a8b536
5 changed files with 21 additions and 4 deletions

View File

@ -44,6 +44,8 @@ config.test_flags = config.test_flags + " " + config.test_extra_flags
prepend_library_path('LIBRARY_PATH', config.library_dir, ":")
prepend_library_path('LD_LIBRARY_PATH', config.library_dir, ":")
prepend_library_path('LD_LIBRARY_PATH', config.omp_host_rtl_directory, ":")
if config.cuda_libdir:
prepend_library_path('LD_LIBRARY_PATH', config.cuda_libdir, ":")
# Forbid fallback to host.
config.environment["OMP_TARGET_OFFLOAD"] = "MANDATORY"
@ -57,13 +59,17 @@ config.substitutions.append(("%compilexx-and-run", "%compilexx && %run"))
config.substitutions.append(("%compile-and-run", "%compile && %run"))
config.substitutions.append(("%compilexx",
"%clangxx %openmp_flags %flags %s -o %t"))
"%clangxx %openmp_flags %cuda_flags %flags %s -o %t"))
config.substitutions.append(("%compile",
"%clang %openmp_flags %flags %s -o %t"))
"%clang %openmp_flags %cuda_flags %flags %s -o %t"))
config.substitutions.append(("%clangxx", config.test_cxx_compiler))
config.substitutions.append(("%clang", config.test_c_compiler))
config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
if config.cuda_path:
config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))
else:
config.substitutions.append(("%cuda_flags", ""))
config.substitutions.append(("%flags", config.test_flags))
config.substitutions.append(("%run", "%t"))

View File

@ -4,6 +4,8 @@ config.test_c_compiler = "@OPENMP_TEST_C_COMPILER@"
config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
config.test_openmp_flags = "@LIBOMPTARGET_NVPTX_TEST_OPENMP_FLAGS@"
config.test_extra_flags = "@LIBOMPTARGET_NVPTX_TEST_FLAGS@"
config.cuda_path = "@CUDA_TOOLKIT_ROOT_DIR@"
config.cuda_libdir = "@CUDA_LIBDIR@"
config.binary_dir = "@CMAKE_CURRENT_BINARY_DIR@"
config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
config.omp_header_directory = "@LIBOMPTARGET_OPENMP_HEADER_FOLDER@"

View File

@ -20,6 +20,7 @@ foreach(CURRENT_TARGET IN LISTS SYSTEM_TARGETS)
# Configure the lit.site.cfg.in file
set(AUTO_GEN_COMMENT "## Autogenerated by libomptarget configuration.\n# Do not edit!")
get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)
configure_file(lit.site.cfg.in ${CURRENT_TARGET}/lit.site.cfg @ONLY)
endforeach()

View File

@ -73,6 +73,8 @@ else: # Unices
append_dynamic_library_path('LD_LIBRARY_PATH', config.library_dir, ":")
append_dynamic_library_path('LD_LIBRARY_PATH', \
config.omp_host_rtl_directory, ":")
if config.cuda_libdir:
append_dynamic_library_path('LD_LIBRARY_PATH', config.cuda_libdir, ":")
append_dynamic_library_path('LIBRARY_PATH', config.library_dir, ":")
append_dynamic_library_path('LIBRARY_PATH', \
config.omp_host_rtl_directory, ":")
@ -140,9 +142,9 @@ for libomptarget_target in config.libomptarget_all_targets:
libomptarget_target, \
"%not --crash %t"))
config.substitutions.append(("%clangxx-" + libomptarget_target, \
"%clangxx %openmp_flags %flags -fopenmp-targets=" + libomptarget_target))
"%clangxx %openmp_flags %cuda_flags %flags -fopenmp-targets=" + libomptarget_target))
config.substitutions.append(("%clang-" + libomptarget_target, \
"%clang %openmp_flags %flags -fopenmp-targets=" + libomptarget_target))
"%clang %openmp_flags %cuda_flags %flags -fopenmp-targets=" + libomptarget_target))
config.substitutions.append(("%fcheck-" + libomptarget_target, \
config.libomptarget_filecheck + " %s"))
else:
@ -180,5 +182,9 @@ for libomptarget_target in config.libomptarget_all_targets:
config.substitutions.append(("%clangxx", config.test_cxx_compiler))
config.substitutions.append(("%clang", config.test_c_compiler))
config.substitutions.append(("%openmp_flags", config.test_openmp_flags))
if config.cuda_path:
config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))
else:
config.substitutions.append(("%cuda_flags", ""))
config.substitutions.append(("%flags", config.test_flags))
config.substitutions.append(("%not", config.libomptarget_not))

View File

@ -5,6 +5,8 @@ config.test_cxx_compiler = "@OPENMP_TEST_CXX_COMPILER@"
config.test_compiler_features = @OPENMP_TEST_COMPILER_FEATURES@
config.test_openmp_flags = "@OPENMP_TEST_OPENMP_FLAGS@"
config.test_extra_flags = "@OPENMP_TEST_FLAGS@"
config.cuda_path = "@CUDA_TOOLKIT_ROOT_DIR@"
config.cuda_libdir = "@CUDA_LIBDIR@"
config.libomptarget_obj_root = "@CMAKE_CURRENT_BINARY_DIR@/@CURRENT_TARGET@"
config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
config.omp_header_directory = "@LIBOMPTARGET_OPENMP_HEADER_FOLDER@"