-
Notifications
You must be signed in to change notification settings - Fork 94
/
lit.cfg.py
executable file
·341 lines (290 loc) · 12 KB
/
lit.cfg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# ./lit.cfg.py -*- Python -*-
#
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Copyright (C) 2022, Advanced Micro Devices, Inc.
import os
import re
import shutil
import subprocess
import lit.formats
import lit.util
from lit.llvm import llvm_config
# Configuration file for the 'lit' test runner.
# name: The name of this test suite.
config.name = "AIE_TUTORIALS"
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
# suffixes: A list of file extensions to treat as test files.
config.suffixes = [".mlir"]
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)
config.substitutions.append(("%PATH%", config.environment["PATH"]))
config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
config.substitutions.append(("%extraAieCcFlags%", config.extraAieCcFlags))
config.substitutions.append(
(
"%host_runtime_lib%",
os.path.join(config.aie_obj_root, "runtime_lib", config.aieHostTarget),
)
)
config.substitutions.append(("%aietools", config.vitis_aietools_dir))
# for xchesscc_wrapper
llvm_config.with_environment("AIETOOLS", config.vitis_aietools_dir)
# for python
llvm_config.with_environment("PYTHONPATH", os.path.join(config.aie_obj_root, "python"))
run_on_npu = "echo"
run_on_2npu = "echo"
xrt_flags = ""
# Not using run_on_board anymore, need more specific per-platform commands
config.substitutions.append(("%run_on_board", "echo"))
if config.hsa_dir and (not ("NOTFOUND" in config.hsa_dir)):
if not "hsa" in config.aieHostTarget:
print(
"ROCm found, but disabled because host target {}".format(
config.aieHostTarget
)
)
config.substitutions.append(("%run_on_vck5000", "echo"))
config.substitutions.append(("%link_against_hsa%", ""))
config.substitutions.append(("%HSA_DIR%", ""))
else:
# Getting the path to the ROCm directory. hsa-runtime64 points to the cmake
# directory so need to go up three directories
rocm_root = os.path.join(config.hsa_dir, "..", "..", "..")
print("Found ROCm:", rocm_root)
config.available_features.add("hsa")
config.substitutions.append(("%HSA_DIR%", "{}".format(rocm_root)))
config.substitutions.append(("%link_against_hsa%", "--link_against_hsa"))
found_vck5000 = False
if config.enable_board_tests:
# If board tests are enabled, make sure there is an AIE ROCm device that we can find
try:
# Making sure that we use the experimental ROCm install that can see the AIE device
my_env = os.environ.copy()
my_env.update(LD_LIBRARY_PATH="{}/lib/".format(rocm_root))
result = subprocess.run(
["rocminfo"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=my_env,
)
result = result.stdout.decode("utf-8").split("\n")
# Go through result and look for the VCK5000
for l in result:
if "Versal VCK5000" in l:
print("Found VCK500 in rocminfo. Enabling on board tests")
found_vck5000 = True
config.substitutions.append(
("%run_on_vck5000", "flock /tmp/vck5000.lock")
)
break
if not found_vck5000:
config.substitutions.append(("%run_on_vck5000", "echo"))
print(
"Enable board set and HSA found but couldn't find device using rocminfo"
)
except:
print("Enable board set and HSA found but unable to run rocminfo")
pass
else:
print("Skipping execution of unit tests (ENABLE_BOARD_TESTS=OFF)")
config.substitutions.append(("%run_on_vck5000", "echo"))
else:
print("ROCm not found")
config.substitutions.append(("%run_on_vck5000", "echo"))
config.substitutions.append(("%link_against_hsa%", ""))
config.substitutions.append(("%HSA_DIR%", ""))
if config.xrt_lib_dir:
print("xrt found at", os.path.dirname(config.xrt_lib_dir))
xrt_flags = "-I{} -L{} -luuid -lxrt_coreutil".format(
config.xrt_include_dir, config.xrt_lib_dir
)
try:
# xbutil is deprecated/renamed to xrt-smi, leaving it xbutil for now for
# compatibility with older versions of XRT
# xrtsmi = os.path.join(config.xrt_bin_dir, "xrt-smi")
xrtsmi = os.path.join(config.xrt_bin_dir, "xbutil")
result = subprocess.run(
[xrtsmi, "examine"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
result = result.stdout.decode("utf-8").split("\n")
# Starting with Linux 6.8 the format is like "[0000:66:00.1] : RyzenAI-npu1"
# Starting with Linux 6.10 the format is like "|[0000:41:00.1] ||RyzenAI-npu1 |"
p = re.compile(r"[\|]?(\[.+:.+:.+\]).+(Phoenix|RyzenAI-(npu\d))")
for l in result:
m = p.match(l)
if not m:
continue
print("Found Ryzen AI device:", m.group(1))
model = "unknown"
if len(m.groups()) == 3:
model = str(m.group(3))
print("\tmodel:", model)
config.available_features.add("ryzen_ai")
if model == "npu1":
run_on_npu = (
f"flock /tmp/npu.lock {config.aie_src_root}/utils/run_on_npu.sh"
)
if model == "npu4":
run_on_2npu = (
f"flock /tmp/npu.lock {config.aie_src_root}/utils/run_on_npu.sh"
)
break
except:
print("Failed to run xrt-smi")
pass
else:
print("xrt not found")
config.substitutions.append(("%run_on_npu", run_on_npu))
config.substitutions.append(("%run_on_2npu", run_on_2npu))
config.substitutions.append(("%xrt_flags", xrt_flags))
config.substitutions.append(("%XRT_DIR", config.xrt_dir))
config.environment["XRT_HACK_UNSECURE_LOADING_XCLBIN"] = "1"
opencv_flags = ""
if config.opencv_include_dir and config.opencv_libs:
print("opencv found")
config.available_features.add("opencv")
opencv_flags = opencv_flags + " -I" + config.opencv_include_dir
if config.opencv_lib_dir:
opencv_flags = opencv_flags + " -L" + config.opencv_lib_dir
libs = config.opencv_libs.split(";")
opencv_flags = opencv_flags + " " + " ".join(["-l" + l for l in libs])
else:
print("opencv not found")
opencv_flags = ""
config.substitutions.append(("%opencv_flags", opencv_flags))
try:
import torch
config.available_features.add("torch")
except ImportError:
print("torch not found", file=sys.stderr)
pass
VitisSysrootFlag = ""
if "x86_64" in config.aieHostTarget:
config.substitutions.append(("%aieHostTargetTriplet%", "x86_64-unknown-linux-gnu"))
elif config.aieHostTarget == "aarch64":
config.substitutions.append(("%aieHostTargetTriplet%", "aarch64-linux-gnu"))
VitisSysrootFlag = "--sysroot=" + config.vitis_sysroot
config.substitutions.append(("%VitisSysrootFlag%", VitisSysrootFlag))
config.substitutions.append(("%aieHostTargetArch%", config.aieHostTarget))
llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
llvm_config.use_default_substitutions()
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
# subdirectories contain auxiliary inputs for various tests in their parent
# directories.
config.excludes = [
"Inputs",
"Examples",
"CMakeLists.txt",
"README.txt",
"LICENSE.txt",
"aie.mlir.prj",
"lit.cfg.py",
]
config.aie_tools_dir = os.path.join(config.aie_obj_root, "bin")
def prepend_path(path):
global llvm_config
paths = [path]
current_paths = llvm_config.config.environment.get("PATH", None)
if current_paths:
paths.extend(current_paths.split(os.path.pathsep))
paths = [os.path.normcase(os.path.normpath(p)) for p in paths]
else:
paths = []
llvm_config.config.environment["PATH"] = os.pathsep.join(paths)
# Setup the path.
prepend_path(config.aie_tools_dir)
# llvm_config.with_environment('LM_LICENSE_FILE', os.getenv('LM_LICENSE_FILE'))
# llvm_config.with_environment('XILINXD_LICENSE_FILE', os.getenv('XILINXD_LICENSE_FILE'))
if config.vitis_root:
config.vitis_aietools_bin = os.path.join(config.vitis_aietools_dir, "bin")
prepend_path(config.vitis_aietools_bin)
llvm_config.with_environment("VITIS", config.vitis_root)
peano_tools_dir = os.path.join(config.peano_install_dir, "bin")
prepend_path(config.llvm_tools_dir)
prepend_path(peano_tools_dir)
# Certainly the prepend works but I would rather be explicit
config.substitutions.append(("%LLVM_TOOLS_DIR", config.llvm_tools_dir))
prepend_path(config.aie_tools_dir)
tool_dirs = [config.aie_tools_dir, config.llvm_tools_dir]
# Test to see if we have the peano backend.
try:
result = subprocess.run(
[os.path.join(peano_tools_dir, "llc"), "-mtriple=aie", "--version"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
if re.search("Xilinx AI Engine", result.stdout.decode("utf-8")) is not None:
config.available_features.add("peano")
config.substitutions.append(("%PEANO_INSTALL_DIR", config.peano_install_dir))
config.environment["PEANO_INSTALL_DIR"] = config.peano_install_dir
print("Peano found: " + os.path.join(peano_tools_dir, "llc"))
tool_dirs.append(os.path.join(peano_tools_dir, "bin"))
else:
print("Peano not found, but expected at ", peano_tools_dir)
except Exception as e:
print("Peano not found, but expected at ", peano_tools_dir)
if not config.enable_chess_tests:
print("Chess tests disabled")
else:
print("Looking for Chess...")
result = None
if config.vitis_root:
result = shutil.which("xchesscc")
if result != None:
print("Chess found: " + result)
config.available_features.add("chess")
config.available_features.add("valid_xchess_license")
lm_license_file = os.getenv("LM_LICENSE_FILE")
if lm_license_file != None:
llvm_config.with_environment("LM_LICENSE_FILE", lm_license_file)
xilinxd_license_file = os.getenv("XILINXD_LICENSE_FILE")
if xilinxd_license_file != None:
llvm_config.with_environment("XILINXD_LICENSE_FILE", xilinxd_license_file)
# test if LM_LICENSE_FILE valid
validate_chess = False
if validate_chess:
import subprocess
result = subprocess.run(
["xchesscc", "+v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
validLMLicense = len(result.stderr.decode("utf-8")) == 0
else:
validLMLicense = lm_license_file or xilinxd_license_file
if not lm_license_file and not xilinxd_license_file:
print(
"WARNING: no valid xchess license that is required by some of the lit tests"
)
elif os.getenv("XILINXD_LICENSE_FILE") is not None:
print("Chess license found")
llvm_config.with_environment(
"XILINXD_LICENSE_FILE", os.getenv("XILINXD_LICENSE_FILE")
)
else:
print("Chess not found")
# look for aiesimulator
result = shutil.which("aiesimulator")
if result != None:
print("aiesimulator found: " + result)
config.available_features.add("aiesimulator")
else:
print("aiesimulator not found")
# add vitis components as available features
for c in config.vitis_components:
config.available_features.add(f"aietools_{c.lower()}")
tools = [
"aie-opt",
"aie-translate",
"aiecc.py",
"ld.lld",
"llc",
"llvm-objdump",
"opt",
"xchesscc_wrapper",
]
llvm_config.add_tool_substitutions(tools, tool_dirs)
if config.enable_board_tests:
lit_config.parallelism_groups["board"] = 1
config.parallelism_group = "board"