-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.py
More file actions
121 lines (104 loc) · 5.34 KB
/
Copy pathentrypoint.py
File metadata and controls
121 lines (104 loc) · 5.34 KB
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
#!/usr/bin/env python3
import os
import shutil
import error
import treenail
import kconfig
# generate mapping from ISAX config name to isax description file
def gen_isax_map():
isax_map = {}
for root, _, files in os.walk(".", topdown=False):
for name in files:
if name == "paths.csv":
csvpath = os.path.join(root, name)
try:
csvfile = open(csvpath)
current_map = { line.split(";")[0]:line.split(";")[1].replace("\n","") for line in csvfile}
isax_map = {**isax_map, **current_map}
except:
error.exit_error(f"could not parse ISAX path.csv file found in: {root}", error.INTERNAL_ERROR)
return isax_map
def get_enabled_isaxes(kconf_syms):
# get list of enabled ISAXes
enabled_isaxes = kconfig.extract_kconfig_enabled(kconfig.extract_enabled_isax_from_config(kconf_syms))
# get mapping from config option to mlir files
isax_file_mapping = gen_isax_map()
# map enabled isaxes to LN mlir input files
isax_input_files = None
try:
isax_input_files = list(map(lambda x: isax_file_mapping[x], enabled_isaxes))
except KeyError as ke:
error.exit_error(f"Could not find .core_desc file for {str(ke)}. Check your paths.csv.", error.INTERNAL_ERROR)
return enabled_isaxes, isax_input_files
def resolve_mlir_paths(scaiev_core_name, out_dir, kconf_syms):
mlir_paths = None
isax_yaml = None
if kconf_syms["DEFAULT_ENTRY_POINT"].str_value == "y":
# print enabled ISAXes
print(f"Building {scaiev_core_name} with ISAXes:")
enabled_isaxes, isax_input_files = get_enabled_isaxes(kconf_syms)
for isax, mlir in zip(enabled_isaxes, isax_input_files):
print(f" - {isax[len('ISAX_'):-len('_EN')]} (associated description: {mlir})")
if len(enabled_isaxes) == 0:
error.exit_error("No ISAXes were selected, nothing to do!", error.USER_ERROR)
# TN CoreDSL to MLIR
treenail.build_treenail()
mlir_paths = treenail.run_treenail_batch(enabled_isaxes, isax_input_files, out_dir)
elif kconf_syms["COREDSL_MLIR_ENTRY_POINT"].str_value == "y" or kconf_syms["PREPARED_MLIR_ENTRY_POINT"].str_value == "y" or kconf_syms["SOLUTION_MLIR_ENTRY_POINT"].str_value == "y":
# use the MLIR entry point path
path = kconf_syms["MLIR_ENTRY_POINT_PATH"].str_value
if not os.path.exists(path):
error.exit_error(f"Could not find mlir file '{mlir_paths[0]}'. Please check your MLIR entry point path settings!", error.USER_ERROR)
mlir_paths = [ os.path.abspath(path) ]
elif kconf_syms["SV_ENTRY_POINT"].str_value == "y":
isax_yaml = kconf_syms["SV_ENTRY_POINT_ISAX_YAML_PATH"].str_value
if not os.path.exists(isax_yaml):
error.exit_error(f"Could not find ISAX YAML file '{isax_yaml}'. Please check your SV entry point path settings!", error.USER_ERROR)
# Copy ISAX YAML file to the output folder
out_yaml_file = os.path.join(out_dir, os.path.basename(isax_yaml))
shutil.copy(isax_yaml, out_yaml_file)
isax_yaml = out_yaml_file
isax_sv = kconf_syms["SV_ENTRY_POINT_PATH"].str_value
if not os.path.exists(isax_sv):
error.exit_error(f"Could not find ISAX SV file '{isax_sv}'. Please check your SV entry point path settings!", error.USER_ERROR)
# Copy ISAX SV file to the output folder
out_sv_file = os.path.join(out_dir, os.path.basename(isax_sv))
shutil.copy(isax_sv, out_sv_file)
else:
assert kconf_syms["NO_ISAX_ENTRY_POINT"].str_value == "y"
# Create an empty ISAX yaml file and see what happens
isax_yaml = os.path.join(out_dir, "NO_ISAX.yaml")
with open(isax_yaml, 'w'):
pass
return mlir_paths, isax_yaml
def entry_point_has_coredsl(kconf_syms):
"""True iff the active entry point yields CoreDSL-dialect MLIR.
analyze-isax (which produces the ISAX analysis YAML) only accepts CoreDSL
MLIR. Only these entry points still hold it; the others start past the
CoreDSL stage and must carry the YAML as a companion artifact instead.
"""
return (kconf_syms["DEFAULT_ENTRY_POINT"].str_value == "y"
or kconf_syms["COREDSL_MLIR_ENTRY_POINT"].str_value == "y")
def resolve_analysis_yaml(kconf_syms):
"""Resolve the companion ISAX analysis YAML for skip-ahead entry points.
Resolution order:
1. explicit ISAX_ANALYSIS_YAML_PATH override
2. sibling 'isax_analysis.yaml' next to the entry-point artifact
(the layout a prior NailGun run produces)
3. None (caller decides whether that is fatal)
"""
override = kconf_syms["ISAX_ANALYSIS_YAML_PATH"].str_value
if override:
if not os.path.exists(override):
error.exit_error(
f"Could not find ISAX analysis YAML '{override}'. "
"Please check the ISAX_ANALYSIS_YAML_PATH setting!", error.USER_ERROR)
return os.path.abspath(override)
entry_artifact = (kconf_syms["MLIR_ENTRY_POINT_PATH"].str_value
or kconf_syms["SV_ENTRY_POINT_PATH"].str_value)
if entry_artifact:
sibling = os.path.join(os.path.dirname(os.path.abspath(entry_artifact)),
"isax_analysis.yaml")
if os.path.exists(sibling):
return sibling
return None