|
| 1 | +# -*- Python -*- |
| 2 | + |
| 3 | +import os |
| 4 | +import platform |
| 5 | +import copy |
| 6 | +import subprocess |
| 7 | + |
| 8 | +import lit.util |
| 9 | +import lit.formats |
| 10 | + |
| 11 | +from lit.llvm import llvm_config |
| 12 | +from lit.llvm.subst import FindTool |
| 13 | + |
| 14 | +# name: The name of this test suite. |
| 15 | +config.name = 'SYCL-Unit-syclcompat' |
| 16 | + |
| 17 | +# suffixes: A list of file extensions to treat as test files. |
| 18 | +config.suffixes = [] |
| 19 | + |
| 20 | +# test_source_root: The root path where tests are located. |
| 21 | +# test_exec_root: The root path where tests should be run. |
| 22 | +config.test_exec_root = config.sycl_obj_root |
| 23 | +config.test_source_root = config.test_exec_root |
| 24 | + |
| 25 | +# testFormat: The test format to use to interpret tests. |
| 26 | +config.test_format = lit.formats.GoogleTest('.', 'Tests') |
| 27 | + |
| 28 | +# allow expanding substitutions that are based on other substitutions |
| 29 | +config.recursiveExpansionLimit = 10 |
| 30 | + |
| 31 | +# Cleanup environment variables which may affect tests |
| 32 | +possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS', |
| 33 | + 'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH', |
| 34 | + 'CPATH', 'C_INCLUDE_PATH', 'CPLUS_INCLUDE_PATH', |
| 35 | + 'OBJC_INCLUDE_PATH', 'OBJCPLUS_INCLUDE_PATH', |
| 36 | + 'LIBCLANG_TIMING', 'LIBCLANG_OBJTRACKING', |
| 37 | + 'LIBCLANG_LOGGING', 'LIBCLANG_BGPRIO_INDEX', |
| 38 | + 'LIBCLANG_BGPRIO_EDIT', 'LIBCLANG_NOTHREADS', |
| 39 | + 'LIBCLANG_RESOURCE_USAGE', |
| 40 | + 'LIBCLANG_CODE_COMPLETION_LOGGING'] |
| 41 | + |
| 42 | +# Clang/Win32 may refer to %INCLUDE%. vsvarsall.bat sets it. |
| 43 | +if platform.system() != 'Windows': |
| 44 | + possibly_dangerous_env_vars.append('INCLUDE') |
| 45 | + |
| 46 | +for name in possibly_dangerous_env_vars: |
| 47 | + if name in llvm_config.config.environment: |
| 48 | + del llvm_config.config.environment[name] |
| 49 | + |
| 50 | +# Propagate some variables from the host environment. |
| 51 | +llvm_config.with_system_environment(['PATH', 'OCL_ICD_FILENAMES', |
| 52 | + 'CL_CONFIG_DEVICES', 'SYCL_DEVICE_ALLOWLIST', 'SYCL_CONFIG_FILE_NAME']) |
| 53 | + |
| 54 | +llvm_config.with_environment('PATH', config.lit_tools_dir, append_path=True) |
| 55 | + |
| 56 | +# Configure LD_LIBRARY_PATH or corresponding os-specific alternatives |
| 57 | +if platform.system() == "Linux": |
| 58 | + llvm_config.with_system_environment(['LD_LIBRARY_PATH','LIBRARY_PATH','CPATH']) |
| 59 | + llvm_config.with_environment('LD_LIBRARY_PATH', config.sycl_libs_dir, append_path=True) |
| 60 | + |
| 61 | +elif platform.system() == "Windows": |
| 62 | + llvm_config.with_system_environment(['LIB','CPATH','INCLUDE']) |
| 63 | + llvm_config.with_environment('LIB', config.sycl_libs_dir, append_path=True) |
| 64 | + llvm_config.with_environment('PATH', config.sycl_libs_dir, append_path=True) |
| 65 | + llvm_config.with_environment('LIB', os.path.join(config.dpcpp_root_dir, 'lib'), append_path=True) |
| 66 | + |
| 67 | +elif platform.system() == "Darwin": |
| 68 | + llvm_config.with_system_environment('CPATH') |
| 69 | + llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1", append_path=True) |
| 70 | + llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/", append_path=True) |
| 71 | + llvm_config.with_environment('DYLD_LIBRARY_PATH', config.sycl_libs_dir) |
| 72 | + |
| 73 | +llvm_config.with_environment('PATH', config.sycl_tools_dir, append_path=True) |
| 74 | + |
| 75 | +lit_config.note("Targeted devices: {}".format(', '.join(config.sycl_devices))) |
| 76 | + |
| 77 | +sycl_ls = FindTool('sycl-ls').resolve(llvm_config, config.llvm_tools_dir) |
| 78 | +if not sycl_ls: |
| 79 | + lit_config.fatal("can't find `sycl-ls`") |
| 80 | + |
| 81 | +if len(config.sycl_devices) == 1 and config.sycl_devices[0] == 'all': |
| 82 | + devices = set() |
| 83 | + sp = subprocess.check_output(sycl_ls, text=True) |
| 84 | + for line in sp.splitlines(): |
| 85 | + (backend, device, _) = line[1:].split(':', 2) |
| 86 | + devices.add('{}:{}'.format(backend, device)) |
| 87 | + config.sycl_devices = list(devices) |
| 88 | + |
| 89 | +lit_config.note("Expanded devices: {}".format(', '.join(config.sycl_devices))) |
| 90 | + |
| 91 | +available_devices = {'opencl': ('cpu', 'gpu', 'acc'), |
| 92 | + 'ext_oneapi_cuda':('gpu'), |
| 93 | + 'ext_oneapi_level_zero':('gpu'), |
| 94 | + 'ext_oneapi_hip':('gpu'), |
| 95 | + 'ext_intel_esimd_emulator':('gpu'), |
| 96 | + 'native_cpu':('cpu')} |
| 97 | + |
| 98 | +for d in config.sycl_devices: |
| 99 | + be, dev = d.split(':') |
| 100 | + if be not in available_devices or dev not in available_devices[be]: |
| 101 | + lit_config.error('Unsupported device {}'.format(d)) |
| 102 | + |
| 103 | +llvm_config.with_environment('ONEAPI_DEVICE_SELECTOR', ';'.join(config.sycl_devices)) |
| 104 | +lit_config.note("ONEAPI_DEVICE_SELECTOR={}".format(';'.join(config.sycl_devices))) |
| 105 | + |
| 106 | +# If HIP_PLATFORM flag is not set, default to AMD, and check if HIP platform is supported |
| 107 | +supported_hip_platforms=["AMD", "NVIDIA"] |
| 108 | +if config.hip_platform == "": |
| 109 | + config.hip_platform = "AMD" |
| 110 | +if config.hip_platform not in supported_hip_platforms: |
| 111 | + lit_config.error("Unknown HIP platform '" + config.hip_platform + "' supported platforms are " + ', '.join(supported_hip_platforms)) |
| 112 | + |
| 113 | +# We use this to simply detect errors in sycl devices |
| 114 | +config.sycl_dev_features = {} |
| 115 | +for sycl_device in config.sycl_devices: |
| 116 | + env = copy.copy(llvm_config.config.environment) |
| 117 | + env['ONEAPI_DEVICE_SELECTOR'] = sycl_device |
| 118 | + if sycl_device.startswith('ext_oneapi_cuda:'): |
| 119 | + env['SYCL_PI_CUDA_ENABLE_IMAGE_SUPPORT'] = '1' |
| 120 | + # When using the ONEAPI_DEVICE_SELECTOR environment variable, sycl-ls |
| 121 | + # prints warnings that might derail a user thinking something is wrong |
| 122 | + # with their test run. It's just us filtering here, so silence them unless |
| 123 | + # we get an exit status. |
| 124 | + try: |
| 125 | + sp = subprocess.run([sycl_ls, '--verbose'], env=env, text=True, |
| 126 | + capture_output=True) |
| 127 | + sp.check_returncode() |
| 128 | + except subprocess.CalledProcessError as e: |
| 129 | + # capturing e allows us to see path resolution errors / system |
| 130 | + # permissions errors etc |
| 131 | + lit_config.fatal(f'Cannot list device aspects for {sycl_device}\n' |
| 132 | + f'{e}\n' |
| 133 | + f'stdout:{sp.stdout}\n' |
| 134 | + f'stderr:{sp.stderr}\n') |
| 135 | + |
| 136 | + |
| 137 | +# Set timeout for a single test |
| 138 | +try: |
| 139 | + import psutil |
| 140 | + lit_config.maxIndividualTestTime = 600 |
| 141 | +except ImportError: |
| 142 | + pass |
0 commit comments