forked from iree-org/iree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_cmake_e2e_test_artifacts_suite.py
executable file
·85 lines (66 loc) · 2.58 KB
/
generate_cmake_e2e_test_artifacts_suite.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
#!/usr/bin/env python3
## Copyright 2022 The IREE Authors
#
# 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
"""Generates a CMake file to build test artifacts."""
import sys
import pathlib
# Add build_tools python dir to the search path.
sys.path.insert(0, str(pathlib.Path(__file__).parent.with_name("python")))
import argparse
import itertools
from e2e_test_artifacts.cmake_generator import model_rule_generator, iree_rule_generator
from e2e_test_artifacts import iree_artifacts
import benchmark_suites.iree.benchmark_collections
# CMake variable name to store IREE package name.
PACKAGE_NAME_CMAKE_VARIABLE = "PACKAGE_NAME"
ROOT_ARTIFACTS_DIR_CMAKE_VARIABLE = "ROOT_ARTIFACTS_DIR"
GENERATED_E2E_TEST_FETCH_MODELS_CMAKE_FILENAMAE = (
"generated_e2e_test_fetch_models.cmake"
)
GENERATED_E2E_TEST_IREE_ARTIFACTS_CMAKE_FILENAME = (
"generated_e2e_test_iree_artifacts.cmake"
)
def parse_arguments():
"""Parses command-line options."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--output_dir",
required=True,
help="Dir path to write the generated cmake files.",
)
return parser.parse_args()
def main(args: argparse.Namespace):
# Currently IREE benchmark suite is the only source of configs.
(
gen_configs,
run_configs,
) = benchmark_suites.iree.benchmark_collections.generate_benchmarks()
dependent_model_map = iree_artifacts.get_dependent_model_map(gen_configs)
root_path = pathlib.PurePath("${%s}" % ROOT_ARTIFACTS_DIR_CMAKE_VARIABLE)
model_rule_map = model_rule_generator.generate_model_rule_map(
root_path=root_path, models=dependent_model_map.values()
)
output_dir = pathlib.Path(args.output_dir)
fetch_models_cmake_file = (
output_dir / GENERATED_E2E_TEST_FETCH_MODELS_CMAKE_FILENAMAE
)
model_cmake_rules = itertools.chain.from_iterable(
rule.cmake_rules for rule in model_rule_map.values()
)
fetch_models_cmake_file.write_text("\n".join(model_cmake_rules))
package_name = "${%s}" % PACKAGE_NAME_CMAKE_VARIABLE
iree_cmake_rules = iree_rule_generator.generate_rules(
package_name=package_name,
root_path=root_path,
gen_configs=gen_configs,
run_configs=run_configs,
model_rule_map=model_rule_map,
)
(output_dir / GENERATED_E2E_TEST_IREE_ARTIFACTS_CMAKE_FILENAME).write_text(
"\n".join(iree_cmake_rules)
)
if __name__ == "__main__":
main(parse_arguments())