llvm-project
417 строк · 20.2 Кб
1# -*- Python -*- vim: set ft=python ts=4 sw=4 expandtab tw=79:
2# Configuration file for the 'lit' test runner.
3
4import os5import lit.formats6
7# Tell pylint that we know config and lit_config exist somewhere.
8if 'PYLINT_IMPORT' in os.environ:9config = object()10lit_config = object()11
12# Use the CUDA device as suggested by the env
13if 'CUDA_VISIBLE_DEVICES' in os.environ:14config.environment['CUDA_VISIBLE_DEVICES'] = os.environ['CUDA_VISIBLE_DEVICES']15
16# Use the ROCR device as suggested by the env
17if 'ROCR_VISIBLE_DEVICES' in os.environ:18config.environment['ROCR_VISIBLE_DEVICES'] = os.environ['ROCR_VISIBLE_DEVICES']19
20# Allow running the tests with omptarget debug output
21if 'LIBOMPTARGET_DEBUG' in os.environ:22config.environment['LIBOMPTARGET_DEBUG'] = os.environ['LIBOMPTARGET_DEBUG']23
24# Allow running the tests with nextgen plugins when available
25if 'LIBOMPTARGET_NEXTGEN_PLUGINS' in os.environ:26config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS'] = os.environ['LIBOMPTARGET_NEXTGEN_PLUGINS']27
28if 'LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS' in os.environ:29config.environment['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS'] = os.environ['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS']30
31if 'OMP_TARGET_OFFLOAD' in os.environ:32config.environment['OMP_TARGET_OFFLOAD'] = os.environ['OMP_TARGET_OFFLOAD']33
34if 'HSA_ENABLE_SDMA' in os.environ:35config.environment['HSA_ENABLE_SDMA'] = os.environ['HSA_ENABLE_SDMA']36
37# Architectures like gfx942 may or may not be APUs so an additional environment
38# variable is required as some tests can be APU specific.
39if 'IS_APU' in os.environ:40config.environment['IS_APU'] = os.environ['IS_APU']41
42# set default environment variables for test
43if 'CHECK_OPENMP_ENV' in os.environ:44test_env = os.environ['CHECK_OPENMP_ENV'].split()45for env in test_env:46name = env.split('=')[0]47value = env.split('=')[1]48config.environment[name] = value49
50def append_dynamic_library_path(name, value, sep):51if name in config.environment:52config.environment[name] = value + sep + config.environment[name]53else:54config.environment[name] = value55
56# Evaluate the environment variable which is a string boolean value.
57def evaluate_bool_env(env):58env = env.lower()59possible_true_values = ["on", "true", "1"]60for v in possible_true_values:61if env == v:62return True63return False64
65# name: The name of this test suite.
66config.name = 'libomptarget :: ' + config.libomptarget_current_target67
68# suffixes: A list of file extensions to treat as test files.
69config.suffixes = ['.c', '.cpp', '.cc', '.f90']70
71# excludes: A list of directories to exclude from the testuites.
72config.excludes = ['Inputs']73
74# test_source_root: The root path where tests are located.
75config.test_source_root = os.path.dirname(__file__)76
77# test_exec_root: The root object directory where output is placed
78config.test_exec_root = config.libomptarget_obj_root79
80# test format
81config.test_format = lit.formats.ShTest()82
83# compiler flags
84config.test_flags = " -I " + config.test_source_root + \85" -I " + config.omp_header_directory + \86" -L " + config.library_dir + \87" -L " + config.llvm_lib_directory88
89# compiler specific flags
90config.test_flags_clang = ""91config.test_flags_flang = ""92
93if config.omp_host_rtl_directory:94config.test_flags = config.test_flags + " -L " + \95config.omp_host_rtl_directory96
97config.test_flags = config.test_flags + " " + config.test_extra_flags98
99# Allow REQUIRES / UNSUPPORTED / XFAIL to work
100config.target_triple = [ ]101for feature in config.test_compiler_features:102config.available_features.add(feature)103
104if config.libomptarget_debug:105config.available_features.add('libomptarget-debug')106
107if config.has_libomptarget_ompt:108config.available_features.add('ompt')109
110config.available_features.add(config.libomptarget_current_target)111
112if config.libomptarget_has_libc:113config.available_features.add('libc')114
115# Determine whether the test system supports unified memory.
116# For CUDA, this is the case with compute capability 70 (Volta) or higher.
117# For all other targets, we currently assume it is.
118supports_unified_shared_memory = True119supports_apu = False120if config.libomptarget_current_target.startswith('nvptx'):121try:122cuda_arch = int(config.cuda_test_arch[:3])123if cuda_arch < 70:124supports_unified_shared_memory = False125except ValueError:126# If the architecture is invalid, assume it is supported.127supports_unified_shared_memory = True128elif config.libomptarget_current_target.startswith('amdgcn'):129# amdgpu_test_arch contains a list of AMD GPUs in the system130# only check the first one assuming that we will run the test on it.131if not (config.amdgpu_test_arch.startswith("gfx90a") or132config.amdgpu_test_arch.startswith("gfx940") or133config.amdgpu_test_arch.startswith("gfx942")):134supports_unified_shared_memory = False135# check if AMD architecture is an APU:136if (config.amdgpu_test_arch.startswith("gfx940") or137(config.amdgpu_test_arch.startswith("gfx942") and138evaluate_bool_env(config.environment['IS_APU']))):139supports_apu = True140if supports_unified_shared_memory:141config.available_features.add('unified_shared_memory')142if supports_apu:143config.available_features.add('apu')144
145# Setup environment to find dynamic library at runtime
146if config.operating_system == 'Windows':147append_dynamic_library_path('PATH', config.library_dir, ";")148append_dynamic_library_path('PATH', config.omp_host_rtl_directory, ";")149elif config.operating_system == 'Darwin':150append_dynamic_library_path('DYLD_LIBRARY_PATH', config.library_dir, ":")151append_dynamic_library_path('DYLD_LIBRARY_PATH', \152config.omp_host_rtl_directory, ";")153config.test_flags += " -Wl,-rpath," + config.library_dir154config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory155else: # Unices156if config.libomptarget_current_target != "nvptx64-nvidia-cuda":157config.test_flags += " -nogpulib"158config.test_flags += " -Wl,-rpath," + config.library_dir159config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory160config.test_flags += " -Wl,-rpath," + config.llvm_lib_directory161if config.cuda_libdir:162config.test_flags += " -Wl,-rpath," + config.cuda_libdir163if config.libomptarget_current_target.startswith('nvptx'):164config.test_flags_clang += " --libomptarget-nvptx-bc-path=" + config.library_dir + '/DeviceRTL'165if config.libomptarget_current_target.endswith('-LTO'):166config.test_flags += " -foffload-lto"167if config.libomptarget_current_target.endswith('-JIT-LTO') and evaluate_bool_env(168config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS']169):170config.test_flags += " -foffload-lto"171config.test_flags += " -Wl,--embed-bitcode"172
173def remove_suffix_if_present(name):174if name.endswith('-LTO'):175return name[:-4]176elif name.endswith('-JIT-LTO'):177return name[:-8]178else:179return name180
181def add_libraries(source):182if config.libomptarget_has_libc:183if config.libomptarget_current_target.startswith('nvptx'):184return source + " " + config.llvm_library_dir + "/libcgpu-nvptx.a " + \185config.llvm_library_intdir + "/libomptarget.devicertl.a"186elif config.libomptarget_current_target.startswith('amdgcn'):187return source + " " + config.llvm_library_dir + "/libcgpu-amdgpu.a " + \188config.llvm_library_intdir + "/libomptarget.devicertl.a"189return source + " " + config.llvm_library_intdir + "/libomptarget.devicertl.a"190
191# Add platform targets
192host_targets = [193"aarch64-unknown-linux-gnu",194"aarch64-unknown-linux-gnu-LTO",195"x86_64-pc-linux-gnu",196"x86_64-pc-linux-gnu-LTO",197"s390x-ibm-linux-gnu",198"s390x-ibm-linux-gnu-LTO",199]
200if config.libomptarget_current_target.startswith('nvptx'):201config.available_features.add('gpu')202config.available_features.add('nvidiagpu')203if config.libomptarget_current_target.startswith('amdgcn'):204config.available_features.add('gpu')205config.available_features.add('amdgpu')206if config.libomptarget_current_target in host_targets:207config.available_features.add('host')208
209# substitutions
210# - for targets that exist in the system create the actual command.
211# - for valid targets that do not exist in the system, return false, so that the
212# same test can be used for different targets.
213
214# Scan all the valid targets.
215for libomptarget_target in config.libomptarget_all_targets:216# Is this target in the current system? If so create a compile, run and test217# command. Otherwise create command that return false.218if libomptarget_target == config.libomptarget_current_target:219config.substitutions.append(("%libomptarget-compilexx-run-and-check-generic",220"%libomptarget-compilexx-run-and-check-" + libomptarget_target))221config.substitutions.append(("%libomptarget-compile-run-and-check-generic",222"%libomptarget-compile-run-and-check-" + libomptarget_target))223config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-generic",224"%libomptarget-compile-fortran-run-and-check-" + libomptarget_target))225config.substitutions.append(("%libomptarget-compilexx-and-run-generic",226"%libomptarget-compilexx-and-run-" + libomptarget_target))227config.substitutions.append(("%libomptarget-compile-and-run-generic",228"%libomptarget-compile-and-run-" + libomptarget_target))229config.substitutions.append(("%libomptarget-compilexx-generic",230"%libomptarget-compilexx-" + libomptarget_target))231config.substitutions.append(("%libomptarget-compilexxx-generic-force-usm",232"%libomptarget-compilexxx-force-usm-" + libomptarget_target))233config.substitutions.append(("%libomptarget-compile-generic",234"%libomptarget-compile-" + libomptarget_target))235config.substitutions.append(("%libomptarget-compile-fortran-generic",236"%libomptarget-compile-fortran-" + libomptarget_target))237config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-generic",238"%libomptarget-compileoptxx-run-and-check-" + libomptarget_target))239config.substitutions.append(("%libomptarget-compileopt-run-and-check-generic",240"%libomptarget-compileopt-run-and-check-" + libomptarget_target))241config.substitutions.append(("%libomptarget-compileoptxx-and-run-generic",242"%libomptarget-compileoptxx-and-run-" + libomptarget_target))243config.substitutions.append(("%libomptarget-compileopt-and-run-generic",244"%libomptarget-compileopt-and-run-" + libomptarget_target))245config.substitutions.append(("%libomptarget-compileoptxx-generic",246"%libomptarget-compileoptxx-" + libomptarget_target))247config.substitutions.append(("%libomptarget-compileopt-generic",248"%libomptarget-compileopt-" + libomptarget_target))249config.substitutions.append(("%libomptarget-run-generic",250"%libomptarget-run-" + libomptarget_target))251config.substitutions.append(("%libomptarget-run-fail-generic",252"%libomptarget-run-fail-" + libomptarget_target))253config.substitutions.append(("%clangxx-generic",254"%clangxx-" + libomptarget_target))255config.substitutions.append(("%clang-generic",256"%clang-" + libomptarget_target))257config.substitutions.append(("%fcheck-generic",258config.libomptarget_filecheck + " %s"))259config.substitutions.append(("%fcheck-plain-generic",260config.libomptarget_filecheck))261
262
263config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \264libomptarget_target, \265"%libomptarget-compilexx-and-run-" + libomptarget_target + \266" | " + config.libomptarget_filecheck + " %s"))267config.substitutions.append(("%libomptarget-compile-run-and-check-" + \268libomptarget_target, \269"%libomptarget-compile-and-run-" + libomptarget_target + \270" | " + config.libomptarget_filecheck + " %s"))271config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \272libomptarget_target, \273"%libomptarget-compile-fortran-and-run-" + libomptarget_target + \274" | " + config.libomptarget_filecheck + " %s"))275config.substitutions.append(("%libomptarget-compilexx-and-run-" + \276libomptarget_target, \277"%libomptarget-compilexx-" + libomptarget_target + " && " + \278"%libomptarget-run-" + libomptarget_target))279config.substitutions.append(("%libomptarget-compile-and-run-" + \280libomptarget_target, \281"%libomptarget-compile-" + libomptarget_target + " && " + \282"%libomptarget-run-" + libomptarget_target))283config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \284libomptarget_target, \285"%libomptarget-compile-fortran-" + libomptarget_target + " && " + \286"%libomptarget-run-" + libomptarget_target))287config.substitutions.append(("%libomptarget-compilexx-" + \288libomptarget_target, \289"%clangxx-" + libomptarget_target + add_libraries(" %s -o %t")))290config.substitutions.append(("%libomptarget-compilexxx-force-usm-" +291libomptarget_target, "%clangxxx-force-usm-" + libomptarget_target + \292add_libraries(" %s -o %t")))293config.substitutions.append(("%libomptarget-compile-" + \294libomptarget_target, \295"%clang-" + libomptarget_target + add_libraries(" %s -o %t")))296config.substitutions.append(("%libomptarget-compile-fortran-" + \297libomptarget_target, \298"%flang-" + libomptarget_target + add_libraries(" %s -o %t")))299config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \300libomptarget_target, \301"%libomptarget-compileoptxx-and-run-" + libomptarget_target + \302" | " + config.libomptarget_filecheck + " %s"))303config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \304libomptarget_target, \305"%libomptarget-compileopt-and-run-" + libomptarget_target + \306" | " + config.libomptarget_filecheck + " %s"))307config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \308libomptarget_target, \309"%libomptarget-compileoptxx-" + libomptarget_target + " && " + \310"%libomptarget-run-" + libomptarget_target))311config.substitutions.append(("%libomptarget-compileopt-and-run-" + \312libomptarget_target, \313"%libomptarget-compileopt-" + libomptarget_target + " && " + \314"%libomptarget-run-" + libomptarget_target))315config.substitutions.append(("%libomptarget-compileoptxx-" + \316libomptarget_target, \317"%clangxx-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))318config.substitutions.append(("%libomptarget-compileopt-" + \319libomptarget_target, \320"%clang-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))321config.substitutions.append(("%libomptarget-run-" + \322libomptarget_target, \323"%t"))324config.substitutions.append(("%libomptarget-run-fail-" + \325libomptarget_target, \326"%not --crash %t"))327config.substitutions.append(("%clangxx-" + libomptarget_target, \328"%clangxx %openmp_flags %cuda_flags %flags %flags_clang -fopenmp-targets=" +\329remove_suffix_if_present(libomptarget_target)))330config.substitutions.append(("%clangxxx-force-usm-" + libomptarget_target, \331"%clangxx %openmp_flags -fopenmp-force-usm %cuda_flags %flags %flags_clang -fopenmp-targets=" +\332remove_suffix_if_present(libomptarget_target)))333config.substitutions.append(("%clang-" + libomptarget_target, \334"%clang %openmp_flags %cuda_flags %flags %flags_clang -fopenmp-targets=" +\335remove_suffix_if_present(libomptarget_target)))336config.substitutions.append(("%flang-" + libomptarget_target, \337"%flang %openmp_flags %flags %flags_flang -fopenmp-targets=" +\338remove_suffix_if_present(libomptarget_target)))339config.substitutions.append(("%fcheck-" + libomptarget_target, \340config.libomptarget_filecheck + " %s"))341else:342config.substitutions.append(("%libomptarget-compile-run-and-check-" + \343libomptarget_target, \344"echo ignored-command"))345config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \346libomptarget_target, \347"echo ignored-command"))348config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \349libomptarget_target, \350"echo ignored-command"))351config.substitutions.append(("%libomptarget-compile-and-run-" + \352libomptarget_target, \353"echo ignored-command"))354config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \355libomptarget_target, \356"echo ignored-command"))357config.substitutions.append(("%libomptarget-compilexx-and-run-" + \358libomptarget_target, \359"echo ignored-command"))360config.substitutions.append(("%libomptarget-compilexx-" + \361libomptarget_target, \362"echo ignored-command"))363config.substitutions.append(("%libomptarget-compile-" + \364libomptarget_target, \365"echo ignored-command"))366config.substitutions.append(("%libomptarget-compile-fortran-" + \367libomptarget_target, \368"echo ignored-command"))369config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \370libomptarget_target, \371"echo ignored-command"))372config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \373libomptarget_target, \374"echo ignored-command"))375config.substitutions.append(("%libomptarget-compileopt-and-run-" + \376libomptarget_target, \377"echo ignored-command"))378config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \379libomptarget_target, \380"echo ignored-command"))381config.substitutions.append(("%libomptarget-compileoptxx-" + \382libomptarget_target, \383"echo ignored-command"))384config.substitutions.append(("%libomptarget-compileopt-" + \385libomptarget_target, \386"echo ignored-command"))387config.substitutions.append(("%libomptarget-run-" + \388libomptarget_target, \389"echo ignored-command"))390config.substitutions.append(("%libomptarget-run-fail-" + \391libomptarget_target, \392"echo ignored-command"))393config.substitutions.append(("%clang-" + libomptarget_target, \394"echo ignored-command"))395config.substitutions.append(("%clangxx-" + libomptarget_target, \396"echo ignored-command"))397config.substitutions.append(("%fcheck-" + libomptarget_target, \398"echo ignored-command"))399config.substitutions.append(("%flang-" + libomptarget_target, \400"echo ignored-command"))401
402config.substitutions.append(("%clangxx", config.test_cxx_compiler))403config.substitutions.append(("%clang", config.test_c_compiler))404
405if config.test_fortran_compiler:406config.available_features.add('flang')407config.substitutions.append(("%flang", config.test_fortran_compiler))408
409config.substitutions.append(("%openmp_flags", config.test_openmp_flags))410if config.libomptarget_current_target.startswith('nvptx') and config.cuda_path:411config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))412else:413config.substitutions.append(("%cuda_flags", ""))414config.substitutions.append(("%flags_clang", config.test_flags_clang))415config.substitutions.append(("%flags_flang", config.test_flags_flang))416config.substitutions.append(("%flags", config.test_flags))417config.substitutions.append(("%not", config.libomptarget_not))418