433 lines · plain
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:9 config = object()10 lit_config = object()11 12# Use the CUDA device as suggested by the env13if 'CUDA_VISIBLE_DEVICES' in os.environ:14 config.environment['CUDA_VISIBLE_DEVICES'] = os.environ['CUDA_VISIBLE_DEVICES']15 16# Use the ROCR device as suggested by the env17if 'ROCR_VISIBLE_DEVICES' in os.environ:18 config.environment['ROCR_VISIBLE_DEVICES'] = os.environ['ROCR_VISIBLE_DEVICES']19 20# Allow running the tests with omptarget debug output21if 'LIBOMPTARGET_DEBUG' in os.environ:22 config.environment['LIBOMPTARGET_DEBUG'] = os.environ['LIBOMPTARGET_DEBUG']23 24# Allow running the tests with nextgen plugins when available25if 'LIBOMPTARGET_NEXTGEN_PLUGINS' in os.environ:26 config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS'] = os.environ['LIBOMPTARGET_NEXTGEN_PLUGINS']27 28if 'LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS' in os.environ:29 config.environment['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS'] = os.environ['LIBOMPTARGET_LOCK_MAPPED_HOST_BUFFERS']30 31if 'OMP_TARGET_OFFLOAD' in os.environ:32 config.environment['OMP_TARGET_OFFLOAD'] = os.environ['OMP_TARGET_OFFLOAD']33 34if 'HSA_ENABLE_SDMA' in os.environ:35 config.environment['HSA_ENABLE_SDMA'] = os.environ['HSA_ENABLE_SDMA']36 37# Architectures like gfx942 may or may not be APUs so an additional environment38# variable is required as some tests can be APU specific.39config.environment['IS_APU'] = os.environ.get('IS_APU', '0')40 41# set default environment variables for test42if 'CHECK_OPENMP_ENV' in os.environ:43 test_env = os.environ['CHECK_OPENMP_ENV'].split()44 for env in test_env:45 name = env.split('=')[0]46 value = env.split('=')[1]47 config.environment[name] = value48 49def append_dynamic_library_path(name, value, sep):50 if name in config.environment:51 config.environment[name] = value + sep + config.environment[name]52 else:53 config.environment[name] = value54 55# Evaluate the environment variable which is a string boolean value.56def evaluate_bool_env(env):57 env = env.lower()58 possible_true_values = ["on", "true", "1"]59 for v in possible_true_values:60 if env == v:61 return True62 return False63 64# name: The name of this test suite.65config.name = 'libomptarget :: ' + config.libomptarget_current_target66 67# suffixes: A list of file extensions to treat as test files.68config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td']69 70# excludes: A list of directories to exclude from the testuites.71config.excludes = ['Inputs', 'unit']72 73# test_source_root: The root path where tests are located.74config.test_source_root = os.path.dirname(__file__)75 76# test_exec_root: The root object directory where output is placed77config.test_exec_root = config.libomptarget_obj_root78 79# test format80config.test_format = lit.formats.ShTest()81 82# compiler flags83config.test_flags = " -I " + config.test_source_root + \84 " -I " + config.omp_header_directory + \85 " -L " + config.library_dir + \86 " -L " + config.llvm_library_intdir + \87 " -L " + config.llvm_lib_directory88 89# compiler specific flags90config.test_flags_clang = ""91config.test_flags_flang = "-fopenmp-version=52"92 93if config.omp_host_rtl_directory:94 config.test_flags = config.test_flags + " -L " + \95 config.omp_host_rtl_directory96 97config.test_flags = config.test_flags + " " + config.test_extra_flags98 99# Allow REQUIRES / UNSUPPORTED / XFAIL to work100config.target_triple = [ ]101for feature in config.test_compiler_features:102 config.available_features.add(feature)103 104if config.libomptarget_debug:105 config.available_features.add('libomptarget-debug')106 107if config.has_libomptarget_ompt:108 config.available_features.add('ompt')109 110config.available_features.add(config.libomptarget_current_target)111 112if config.libomptarget_has_libc:113 config.available_features.add('libc')114 115profdata_path = os.path.join(config.bin_llvm_tools_dir, "llvm-profdata")116if config.libomptarget_test_pgo:117 config.available_features.add('pgo')118 config.substitutions.append(("%profdata", profdata_path))119 120# Determine whether the test system supports unified memory.121# For CUDA, this is the case with compute capability 70 (Volta) or higher.122# For all other targets, we currently assume it is.123supports_unified_shared_memory = True124supports_apu = False125supports_large_allocation_memory_pool = False126if config.libomptarget_current_target.startswith('nvptx'):127 try:128 cuda_arch = int(config.cuda_test_arch[:3])129 if cuda_arch < 70:130 supports_unified_shared_memory = False131 except ValueError:132 # If the architecture is invalid, assume it is supported.133 supports_unified_shared_memory = True134elif config.libomptarget_current_target.startswith('amdgcn'):135 # amdgpu_test_arch contains a list of AMD GPUs in the system136 # only check the first one assuming that we will run the test on it.137 if (config.amdgpu_test_arch.startswith("gfx90a") or138 config.amdgpu_test_arch.startswith("gfx942") or139 config.amdgpu_test_arch.startswith("gfx950")):140 supports_large_allocation_memory_pool = True141 else:142 supports_unified_shared_memory = False143 # check if AMD architecture is an APU:144 if ((config.amdgpu_test_arch.startswith("gfx942") and145 evaluate_bool_env(config.environment['IS_APU']))):146 supports_apu = True147if supports_unified_shared_memory:148 config.available_features.add('unified_shared_memory')149if supports_apu:150 config.available_features.add('apu')151if supports_large_allocation_memory_pool:152 config.available_features.add('large_allocation_memory_pool')153 154# Setup environment to find dynamic library at runtime155if config.operating_system == 'Windows':156 append_dynamic_library_path('PATH', config.library_dir, ";")157 append_dynamic_library_path('PATH', config.omp_host_rtl_directory, ";")158elif config.operating_system == 'Darwin':159 append_dynamic_library_path('DYLD_LIBRARY_PATH', config.library_dir, ":")160 append_dynamic_library_path('DYLD_LIBRARY_PATH', \161 config.omp_host_rtl_directory, ";")162 config.test_flags += " -Wl,-rpath," + config.library_dir163 config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory164else: # Unices165 if config.libomptarget_current_target != "nvptx64-nvidia-cuda":166 config.test_flags += " -nogpulib"167 config.test_flags += " -Wl,-rpath," + config.library_dir168 config.test_flags += " -Wl,-rpath," + config.omp_host_rtl_directory169 config.test_flags += " -Wl,-rpath," + config.llvm_library_intdir170 config.test_flags += " -Wl,-rpath," + config.llvm_lib_directory171 if config.cuda_libdir:172 config.test_flags += " -Wl,-rpath," + config.cuda_libdir173 if config.libomptarget_current_target.startswith('nvptx'):174 config.test_flags_clang += " --libomptarget-nvptx-bc-path=" + config.llvm_library_intdir + "/nvptx64-nvidia-cuda"175 if config.libomptarget_current_target.endswith('-LTO'):176 config.test_flags += " -foffload-lto"177 if config.libomptarget_current_target.endswith('-JIT-LTO') and evaluate_bool_env(178 config.environment['LIBOMPTARGET_NEXTGEN_PLUGINS']179 ):180 config.test_flags += " -foffload-lto"181 config.test_flags += " -Wl,--embed-bitcode"182 183# Add platform targets184host_targets = [185 "aarch64-unknown-linux-gnu",186 "aarch64-unknown-linux-gnu-LTO",187 "x86_64-unknown-linux-gnu",188 "x86_64-unknown-linux-gnu-LTO",189 "s390x-ibm-linux-gnu",190 "s390x-ibm-linux-gnu-LTO",191]192if config.libomptarget_current_target.startswith('nvptx'):193 config.available_features.add('gpu')194 config.available_features.add('nvidiagpu')195if config.libomptarget_current_target.startswith('amdgcn'):196 config.available_features.add('gpu')197 config.available_features.add('amdgpu')198if config.libomptarget_current_target in host_targets:199 config.available_features.add('host')200 201def remove_suffix_if_present(name):202 if name.endswith('-LTO'):203 return name[:-4]204 elif name.endswith('-JIT-LTO'):205 return name[:-8]206 else:207 return name208 209def add_libraries(source):210 if "gpu" not in config.available_features:211 return source212 if config.libomptarget_has_libc:213 return source + " -Xoffload-linker -lc " + \214 "-Xoffload-linker -lm " + \215 "-Xoffload-linker -lompdevice"216 else:217 return source + " " + "-Xoffload-linker -lompdevice"218 219# substitutions220# - for targets that exist in the system create the actual command.221# - for valid targets that do not exist in the system, return false, so that the222# same test can be used for different targets.223 224# Scan all the valid targets.225for libomptarget_target in config.libomptarget_all_targets:226 # Is this target in the current system? If so create a compile, run and test227 # command. Otherwise create command that return false.228 if libomptarget_target == config.libomptarget_current_target:229 config.substitutions.append(("%libomptarget-compilexx-run-and-check-generic",230 "%libomptarget-compilexx-run-and-check-" + libomptarget_target))231 config.substitutions.append(("%libomptarget-compile-run-and-check-generic",232 "%libomptarget-compile-run-and-check-" + libomptarget_target))233 config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-generic",234 "%libomptarget-compile-fortran-run-and-check-" + libomptarget_target))235 config.substitutions.append(("%libomptarget-compilexx-and-run-generic",236 "%libomptarget-compilexx-and-run-" + libomptarget_target))237 config.substitutions.append(("%libomptarget-compile-and-run-generic",238 "%libomptarget-compile-and-run-" + libomptarget_target))239 config.substitutions.append(("%libomptarget-compilexx-generic",240 "%libomptarget-compilexx-" + libomptarget_target))241 config.substitutions.append(("%libomptarget-compilexxx-generic-force-usm",242 "%libomptarget-compilexxx-force-usm-" + libomptarget_target))243 config.substitutions.append(("%libomptarget-compile-generic",244 "%libomptarget-compile-" + libomptarget_target))245 config.substitutions.append(("%libomptarget-compile-fortran-generic",246 "%libomptarget-compile-fortran-" + libomptarget_target))247 config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-generic",248 "%libomptarget-compileoptxx-run-and-check-" + libomptarget_target))249 config.substitutions.append(("%libomptarget-compileopt-run-and-check-generic",250 "%libomptarget-compileopt-run-and-check-" + libomptarget_target))251 config.substitutions.append(("%libomptarget-compileoptxx-and-run-generic",252 "%libomptarget-compileoptxx-and-run-" + libomptarget_target))253 config.substitutions.append(("%libomptarget-compileopt-and-run-generic",254 "%libomptarget-compileopt-and-run-" + libomptarget_target))255 config.substitutions.append(("%libomptarget-compileoptxx-generic",256 "%libomptarget-compileoptxx-" + libomptarget_target))257 config.substitutions.append(("%libomptarget-compileopt-generic",258 "%libomptarget-compileopt-" + libomptarget_target))259 config.substitutions.append(("%libomptarget-run-generic",260 "%libomptarget-run-" + libomptarget_target))261 config.substitutions.append(("%libomptarget-run-fail-generic",262 "%libomptarget-run-fail-" + libomptarget_target))263 config.substitutions.append(("%clangxx-generic",264 "%clangxx-" + libomptarget_target))265 config.substitutions.append(("%clang-generic",266 "%clang-" + libomptarget_target))267 config.substitutions.append(("%fcheck-generic",268 config.libomptarget_filecheck + " %s"))269 config.substitutions.append(("%fcheck-plain-generic",270 config.libomptarget_filecheck))271 272 273 config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \274 libomptarget_target, \275 "%libomptarget-compilexx-and-run-" + libomptarget_target + \276 " | " + config.libomptarget_filecheck + " %s"))277 config.substitutions.append(("%libomptarget-compile-run-and-check-" + \278 libomptarget_target, \279 "%libomptarget-compile-and-run-" + libomptarget_target + \280 " | " + config.libomptarget_filecheck + " %s"))281 config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \282 libomptarget_target, \283 "%libomptarget-compile-fortran-and-run-" + libomptarget_target + \284 " | " + config.libomptarget_filecheck + " %s"))285 config.substitutions.append(("%libomptarget-compilexx-and-run-" + \286 libomptarget_target, \287 "%libomptarget-compilexx-" + libomptarget_target + " && " + \288 "%libomptarget-run-" + libomptarget_target))289 config.substitutions.append(("%libomptarget-compile-and-run-" + \290 libomptarget_target, \291 "%libomptarget-compile-" + libomptarget_target + " && " + \292 "%libomptarget-run-" + libomptarget_target))293 config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \294 libomptarget_target, \295 "%libomptarget-compile-fortran-" + libomptarget_target + " && " + \296 "%libomptarget-run-" + libomptarget_target))297 config.substitutions.append(("%libomptarget-compilexx-" + \298 libomptarget_target, \299 "%clangxx-" + libomptarget_target + add_libraries(" %s -o %t")))300 config.substitutions.append(("%libomptarget-compilexxx-force-usm-" +301 libomptarget_target, "%clangxxx-force-usm-" + libomptarget_target + \302 add_libraries(" %s -o %t")))303 config.substitutions.append(("%libomptarget-compile-" + \304 libomptarget_target, \305 "%clang-" + libomptarget_target + add_libraries(" %s -o %t")))306 config.substitutions.append(("%libomptarget-compile-fortran-" + \307 libomptarget_target, \308 "%flang-" + libomptarget_target + add_libraries(" %s -o %t")))309 config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \310 libomptarget_target, \311 "%libomptarget-compileoptxx-and-run-" + libomptarget_target + \312 " | " + config.libomptarget_filecheck + " %s"))313 config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \314 libomptarget_target, \315 "%libomptarget-compileopt-and-run-" + libomptarget_target + \316 " | " + config.libomptarget_filecheck + " %s"))317 config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \318 libomptarget_target, \319 "%libomptarget-compileoptxx-" + libomptarget_target + " && " + \320 "%libomptarget-run-" + libomptarget_target))321 config.substitutions.append(("%libomptarget-compileopt-and-run-" + \322 libomptarget_target, \323 "%libomptarget-compileopt-" + libomptarget_target + " && " + \324 "%libomptarget-run-" + libomptarget_target))325 config.substitutions.append(("%libomptarget-compileoptxx-" + \326 libomptarget_target, \327 "%clangxx-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))328 config.substitutions.append(("%libomptarget-compileopt-" + \329 libomptarget_target, \330 "%clang-" + libomptarget_target + add_libraries(" -O3 %s -o %t")))331 config.substitutions.append(("%libomptarget-run-" + \332 libomptarget_target, \333 "%t"))334 config.substitutions.append(("%libomptarget-run-fail-" + \335 libomptarget_target, \336 "%not --crash %t"))337 config.substitutions.append(("%clangxx-" + libomptarget_target, \338 "%clangxx %openmp_flags %cuda_flags %flags %flags_clang -fopenmp-targets=" +\339 remove_suffix_if_present(libomptarget_target)))340 config.substitutions.append(("%clangxxx-force-usm-" + libomptarget_target, \341 "%clangxx %openmp_flags -fopenmp-force-usm %cuda_flags %flags %flags_clang -fopenmp-targets=" +\342 remove_suffix_if_present(libomptarget_target)))343 config.substitutions.append(("%clang-" + libomptarget_target, \344 "%clang %openmp_flags %cuda_flags %flags %flags_clang -fopenmp-targets=" +\345 remove_suffix_if_present(libomptarget_target)))346 config.substitutions.append(("%flang-" + libomptarget_target, \347 "%flang %openmp_flags %flags %flags_flang -fopenmp-targets=" +\348 remove_suffix_if_present(libomptarget_target)))349 config.substitutions.append(("%fcheck-" + libomptarget_target, \350 config.libomptarget_filecheck + " %s"))351 else:352 config.substitutions.append(("%libomptarget-compile-run-and-check-" + \353 libomptarget_target, \354 "echo ignored-command"))355 config.substitutions.append(("%libomptarget-compile-fortran-run-and-check-" + \356 libomptarget_target, \357 "echo ignored-command"))358 config.substitutions.append(("%libomptarget-compilexx-run-and-check-" + \359 libomptarget_target, \360 "echo ignored-command"))361 config.substitutions.append(("%libomptarget-compile-and-run-" + \362 libomptarget_target, \363 "echo ignored-command"))364 config.substitutions.append(("%libomptarget-compile-fortran-and-run-" + \365 libomptarget_target, \366 "echo ignored-command"))367 config.substitutions.append(("%libomptarget-compilexx-and-run-" + \368 libomptarget_target, \369 "echo ignored-command"))370 config.substitutions.append(("%libomptarget-compilexx-" + \371 libomptarget_target, \372 "echo ignored-command"))373 config.substitutions.append(("%libomptarget-compile-" + \374 libomptarget_target, \375 "echo ignored-command"))376 config.substitutions.append(("%libomptarget-compile-fortran-" + \377 libomptarget_target, \378 "echo ignored-command"))379 config.substitutions.append(("%libomptarget-compileopt-run-and-check-" + \380 libomptarget_target, \381 "echo ignored-command"))382 config.substitutions.append(("%libomptarget-compileoptxx-run-and-check-" + \383 libomptarget_target, \384 "echo ignored-command"))385 config.substitutions.append(("%libomptarget-compileopt-and-run-" + \386 libomptarget_target, \387 "echo ignored-command"))388 config.substitutions.append(("%libomptarget-compileoptxx-and-run-" + \389 libomptarget_target, \390 "echo ignored-command"))391 config.substitutions.append(("%libomptarget-compileoptxx-" + \392 libomptarget_target, \393 "echo ignored-command"))394 config.substitutions.append(("%libomptarget-compileopt-" + \395 libomptarget_target, \396 "echo ignored-command"))397 config.substitutions.append(("%libomptarget-run-" + \398 libomptarget_target, \399 "echo ignored-command"))400 config.substitutions.append(("%libomptarget-run-fail-" + \401 libomptarget_target, \402 "echo ignored-command"))403 config.substitutions.append(("%clang-" + libomptarget_target, \404 "echo ignored-command"))405 config.substitutions.append(("%clangxx-" + libomptarget_target, \406 "echo ignored-command"))407 config.substitutions.append(("%fcheck-" + libomptarget_target, \408 "echo ignored-command"))409 config.substitutions.append(("%flang-" + libomptarget_target, \410 "echo ignored-command"))411 412config.substitutions.append(("%clangxx", config.test_cxx_compiler))413config.substitutions.append(("%clang", config.test_c_compiler))414 415if config.test_fortran_compiler:416 config.available_features.add('flang')417 config.substitutions.append(("%flang", config.test_fortran_compiler))418 419config.substitutions.append(("%target_triple", config.libomptarget_current_target))420 421config.substitutions.append(("%openmp_flags", config.test_openmp_flags))422if config.libomptarget_current_target.startswith('nvptx') and config.cuda_path:423 config.substitutions.append(("%cuda_flags", "--cuda-path=" + config.cuda_path))424else:425 config.substitutions.append(("%cuda_flags", ""))426config.substitutions.append(("%flags_clang", config.test_flags_clang))427config.substitutions.append(("%flags_flang", config.test_flags_flang))428config.substitutions.append(("%flags", config.test_flags))429config.substitutions.append(("%not", config.libomptarget_not))430config.substitutions.append(("%offload-device-info",431 config.offload_device_info))432config.substitutions.append(("%offload-tblgen", config.offload_tblgen))433