llvm-project

Форк
0
/
lit.cfg.py 
255 строк · 8.2 Кб
1
# -*- Python -*-
2

3
import os
4
import platform
5
import re
6
import subprocess
7
import tempfile
8

9
import lit.formats
10
import lit.util
11

12
from lit.llvm import llvm_config
13
from lit.llvm.subst import ToolSubst
14
from lit.llvm.subst import FindTool
15

16
# Configuration file for the 'lit' test runner.
17

18
# name: The name of this test suite.
19
config.name = "MLIR"
20

21
# We prefer the lit internal shell which provides a better user experience on failures
22
# unless the user explicitly disables it with LIT_USE_INTERNAL_SHELL=0 env var.
23
use_lit_shell = True
24
lit_shell_env = os.environ.get("LIT_USE_INTERNAL_SHELL")
25
if lit_shell_env:
26
  use_lit_shell = not lit.util.pythonize_bool(lit_shell_env)
27

28
config.test_format = lit.formats.ShTest(execute_external=not use_lit_shell)
29

30
# suffixes: A list of file extensions to treat as test files.
31
config.suffixes = [
32
    ".td",
33
    ".mlir",
34
    ".toy",
35
    ".ll",
36
    ".tc",
37
    ".py",
38
    ".yaml",
39
    ".test",
40
    ".pdll",
41
    ".c",
42
]
43

44
# test_source_root: The root path where tests are located.
45
config.test_source_root = os.path.dirname(__file__)
46

47
# test_exec_root: The root path where tests should be run.
48
config.test_exec_root = os.path.join(config.mlir_obj_root, "test")
49

50
config.substitutions.append(("%PATH%", config.environment["PATH"]))
51
config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
52
config.substitutions.append(("%mlir_src_root", config.mlir_src_root))
53
config.substitutions.append(("%host_cxx", config.host_cxx))
54
config.substitutions.append(("%host_cc", config.host_cc))
55

56

57
# Searches for a runtime library with the given name and returns the found path.
58
# Correctly handles the platforms shared library directory and naming conventions.
59
def find_runtime(name):
60
    path = ""
61
    for prefix in ["", "lib"]:
62
        path = os.path.join(
63
            config.llvm_shlib_dir, f"{prefix}{name}{config.llvm_shlib_ext}"
64
        )
65
        if os.path.isfile(path):
66
            break
67
    return path
68

69

70
# Searches for a runtime library with the given name and returns a tool
71
# substitution of the same name and the found path.
72
def add_runtime(name):
73
    return ToolSubst(f"%{name}", find_runtime(name))
74

75

76
llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
77

78
llvm_config.use_default_substitutions()
79

80
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
81
# subdirectories contain auxiliary inputs for various tests in their parent
82
# directories.
83
config.excludes = [
84
    "Inputs",
85
    "CMakeLists.txt",
86
    "README.txt",
87
    "LICENSE.txt",
88
    "lit.cfg.py",
89
    "lit.site.cfg.py",
90
]
91

92
# Tweak the PATH to include the tools dir.
93
llvm_config.with_environment("PATH", config.mlir_tools_dir, append_path=True)
94
llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
95

96
tool_dirs = [config.mlir_tools_dir, config.llvm_tools_dir]
97
tools = [
98
    "mlir-tblgen",
99
    "mlir-translate",
100
    "mlir-lsp-server",
101
    "mlir-capi-execution-engine-test",
102
    "mlir-capi-ir-test",
103
    "mlir-capi-irdl-test",
104
    "mlir-capi-llvm-test",
105
    "mlir-capi-pass-test",
106
    "mlir-capi-pdl-test",
107
    "mlir-capi-quant-test",
108
    "mlir-capi-sparse-tensor-test",
109
    "mlir-capi-transform-test",
110
    "mlir-capi-transform-interpreter-test",
111
    "mlir-capi-translation-test",
112
    "mlir-cpu-runner",
113
    add_runtime("mlir_runner_utils"),
114
    add_runtime("mlir_c_runner_utils"),
115
    add_runtime("mlir_async_runtime"),
116
    add_runtime("mlir_float16_utils"),
117
    "mlir-linalg-ods-yaml-gen",
118
    "mlir-reduce",
119
    "mlir-pdll",
120
    "not",
121
]
122

123
if config.enable_spirv_cpu_runner:
124
    tools.extend(
125
        ["mlir-spirv-cpu-runner", add_runtime("mlir_test_spirv_cpu_runner_c_wrappers")]
126
    )
127

128
if config.enable_vulkan_runner:
129
    tools.extend([add_runtime("vulkan-runtime-wrappers")])
130

131
if config.enable_rocm_runner:
132
    tools.extend([add_runtime("mlir_rocm_runtime")])
133

134
if config.enable_cuda_runner:
135
    tools.extend([add_runtime("mlir_cuda_runtime")])
136

137
if config.enable_sycl_runner:
138
    tools.extend([add_runtime("mlir_sycl_runtime")])
139

140
if config.mlir_run_arm_sve_tests or config.mlir_run_arm_sme_tests:
141
    tools.extend([add_runtime("mlir_arm_runner_utils")])
142

143
if config.mlir_run_arm_sme_tests:
144
    config.substitutions.append(
145
        (
146
            "%arm_sme_abi_shlib",
147
            # Use passed Arm SME ABI routines, if not present default to stubs.
148
            config.arm_sme_abi_routines_shlib or find_runtime("mlir_arm_sme_abi_stubs"),
149
        )
150
    )
151

152
# The following tools are optional
153
tools.extend(
154
    [
155
        ToolSubst("toyc-ch1", unresolved="ignore"),
156
        ToolSubst("toyc-ch2", unresolved="ignore"),
157
        ToolSubst("toyc-ch3", unresolved="ignore"),
158
        ToolSubst("toyc-ch4", unresolved="ignore"),
159
        ToolSubst("toyc-ch5", unresolved="ignore"),
160
        ToolSubst("toyc-ch6", unresolved="ignore"),
161
        ToolSubst("toyc-ch7", unresolved="ignore"),
162
        ToolSubst("transform-opt-ch2", unresolved="ignore"),
163
        ToolSubst("transform-opt-ch3", unresolved="ignore"),
164
        ToolSubst("transform-opt-ch4", unresolved="ignore"),
165
        ToolSubst("mlir-transform-opt", unresolved="ignore"),
166
        ToolSubst("%mlir_lib_dir", config.mlir_lib_dir, unresolved="ignore"),
167
        ToolSubst("%mlir_src_dir", config.mlir_src_root, unresolved="ignore"),
168
    ]
169
)
170

171
python_executable = config.python_executable
172
# Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
173
# TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
174
if "asan" in config.available_features and "Linux" in config.host_os:
175
    python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
176
# On Windows the path to python could contains spaces in which case it needs to be provided in quotes.
177
# This is the equivalent of how %python is setup in llvm/utils/lit/lit/llvm/config.py.
178
elif "Windows" in config.host_os:
179
    python_executable = '"%s"' % (python_executable)
180
tools.extend(
181
    [
182
        ToolSubst("%PYTHON", python_executable, unresolved="ignore"),
183
    ]
184
)
185

186
if "MLIR_OPT_CHECK_IR_ROUNDTRIP" in os.environ:
187
    tools.extend(
188
        [
189
            ToolSubst("mlir-opt", "mlir-opt --verify-roundtrip", unresolved="fatal"),
190
        ]
191
    )
192
else:
193
    tools.extend(["mlir-opt"])
194

195
llvm_config.add_tool_substitutions(tools, tool_dirs)
196

197

198
# FileCheck -enable-var-scope is enabled by default in MLIR test
199
# This option avoids to accidentally reuse variable across -LABEL match,
200
# it can be explicitly opted-in by prefixing the variable name with $
201
config.environment["FILECHECK_OPTS"] = "-enable-var-scope --allow-unused-prefixes=false"
202

203
# Add the python path for both the source and binary tree.
204
# Note that presently, the python sources come from the source tree and the
205
# binaries come from the build tree. This should be unified to the build tree
206
# by copying/linking sources to build.
207
if config.enable_bindings_python:
208
    config.environment["PYTHONPATH"] = os.getenv("MLIR_LIT_PYTHONPATH", "")
209
    llvm_config.with_environment(
210
        "PYTHONPATH",
211
        [
212
            os.path.join(config.mlir_obj_root, "python_packages", "mlir_core"),
213
            os.path.join(config.mlir_obj_root, "python_packages", "mlir_test"),
214
        ],
215
        append_path=True,
216
    )
217

218
if config.enable_assertions:
219
    config.available_features.add("asserts")
220
else:
221
    config.available_features.add("noasserts")
222

223

224
def have_host_jit_feature_support(feature_name):
225
    mlir_cpu_runner_exe = lit.util.which("mlir-cpu-runner", config.mlir_tools_dir)
226

227
    if not mlir_cpu_runner_exe:
228
        return False
229

230
    try:
231
        mlir_cpu_runner_cmd = subprocess.Popen(
232
            [mlir_cpu_runner_exe, "--host-supports-" + feature_name],
233
            stdout=subprocess.PIPE,
234
        )
235
    except OSError:
236
        print("could not exec mlir-cpu-runner")
237
        return False
238

239
    mlir_cpu_runner_out = mlir_cpu_runner_cmd.stdout.read().decode("ascii")
240
    mlir_cpu_runner_cmd.wait()
241

242
    return "true" in mlir_cpu_runner_out
243

244

245
if have_host_jit_feature_support("jit"):
246
    config.available_features.add("host-supports-jit")
247

248
if config.run_nvptx_tests:
249
    config.available_features.add("host-supports-nvptx")
250

251
if config.run_rocm_tests:
252
    config.available_features.add("host-supports-amdgpu")
253

254
if config.arm_emulator_executable:
255
    config.available_features.add("arm-emulator")
256

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.