Skip to content

Commit 890fb59

Browse files
committed
[Infra]: Adding include_list_add and include_dir (both optional) to task config file
Signed-off-by: Seyed Alireza Damghani <[email protected]>
1 parent bbe0b3d commit 890fb59

File tree

4 files changed

+128
-11
lines changed

4 files changed

+128
-11
lines changed

vtr_flow/scripts/python_libs/vtr/flow.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def run(
3434
architecture_file,
3535
circuit_file,
3636
power_tech_file=None,
37+
include_files=None,
3738
start_stage=VtrStage.ODIN,
3839
end_stage=VtrStage.VPR,
3940
command_runner=vtr.CommandRunner(),
@@ -167,6 +168,15 @@ def run(
167168
shutil.copy(str(circuit_file), str(circuit_copy))
168169
shutil.copy(str(architecture_file), str(architecture_copy))
169170

171+
# Extract includes path
172+
for include in include_files:
173+
include_paths = str(include).split(" ")
174+
# Copy given additional Verilog files
175+
for include_path in include_paths:
176+
include_file = vtr.util.verify_file(include_path, "Circuit")
177+
include_copy = temp_dir / include_file.name
178+
shutil.copy(str(include_path), str(include_copy))
179+
170180
# There are multiple potential paths for the netlist to reach a tool
171181
# We initialize it here to the user specified circuit and let downstream
172182
# stages update it
@@ -179,6 +189,7 @@ def run(
179189
vtr.odin.run(
180190
architecture_copy,
181191
next_stage_netlist,
192+
include_files,
182193
output_netlist=post_odin_netlist,
183194
command_runner=command_runner,
184195
temp_dir=temp_dir,

vtr_flow/scripts/python_libs/vtr/odin/odin.py

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,70 @@
44
import shutil
55
from collections import OrderedDict
66
from pathlib import Path
7+
import xml.etree.ElementTree as ET
78
from vtr import file_replace, determine_memory_addr_width, verify_file, CommandRunner, paths
89

10+
# pylint: disable=too-many-arguments, too-many-locals
11+
def init_config_file(
12+
odin_config_full_path,
13+
include_files,
14+
circuit_file,
15+
architecture_file,
16+
output_netlist,
17+
memory_addr_width,
18+
min_hard_mult_size,
19+
min_hard_adder_size,
20+
):
21+
22+
"""initializing the raw odin config file"""
23+
# Update the config file
24+
file_replace(
25+
odin_config_full_path,
26+
{
27+
"YYY": architecture_file,
28+
"ZZZ": output_netlist,
29+
"PPP": memory_addr_width,
30+
"MMM": min_hard_mult_size,
31+
"AAA": min_hard_adder_size,
32+
},
33+
)
34+
35+
circuit_list = []
36+
if include_files:
37+
# Extract includes path
38+
for include in include_files:
39+
include_paths = str(include).split(" ")
40+
for include_path in include_paths:
41+
include_file = verify_file(include_path, "Circuit")
42+
circuit_list.append(include_file.name)
43+
44+
# append the main circuit design as the last one
45+
circuit_list.append(circuit_file.name)
46+
47+
# loading the given config file
48+
config_file = ET.parse(odin_config_full_path)
49+
root = config_file.getroot()
50+
51+
# based on the base condfig file
52+
verilog_files_tag = root.find("verilog_files")
53+
# remove the template line XXX, verilog_files_tag [0] is a comment
54+
verilog_files_tag.remove(verilog_files_tag[0])
55+
for circuit in circuit_list:
56+
verilog_file = ET.SubElement(verilog_files_tag, "verilog_file")
57+
verilog_file.tail = "\n\n\t" if (circuit == circuit_list[-1]) else "\n\n\t\t"
58+
verilog_file.text = circuit
59+
60+
# update the config file with new values
61+
config_file.write(odin_config_full_path)
62+
63+
return circuit_list
64+
965

1066
# pylint: disable=too-many-arguments, too-many-locals
1167
def run(
1268
architecture_file,
1369
circuit_file,
70+
include_files,
1471
output_netlist,
1572
command_runner=CommandRunner(),
1673
temp_dir=Path("."),
@@ -90,17 +147,15 @@ def run(
90147
odin_config_full_path = str(temp_dir / odin_config)
91148
shutil.copyfile(odin_base_config, odin_config_full_path)
92149

93-
# Update the config file
94-
file_replace(
150+
circuit_list = init_config_file(
95151
odin_config_full_path,
96-
{
97-
"XXX": circuit_file.name,
98-
"YYY": architecture_file.name,
99-
"ZZZ": output_netlist.name,
100-
"PPP": determine_memory_addr_width(str(architecture_file)),
101-
"MMM": min_hard_mult_size,
102-
"AAA": min_hard_adder_size,
103-
},
152+
include_files,
153+
circuit_file,
154+
architecture_file.name,
155+
output_netlist.name,
156+
determine_memory_addr_width(str(architecture_file)),
157+
min_hard_mult_size,
158+
min_hard_adder_size,
104159
)
105160

106161
cmd = [odin_exec]
@@ -126,7 +181,7 @@ def run(
126181
"-a",
127182
architecture_file.name,
128183
"-V",
129-
circuit_file.name,
184+
circuit_list,
130185
"-o",
131186
output_netlist.name,
132187
]

vtr_flow/scripts/python_libs/vtr/task.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def __init__(
3333
circuit_list_add,
3434
arch_list_add,
3535
parse_file,
36+
includes_dir=None,
37+
include_list_add=None,
3638
second_parse_file=None,
3739
script_path=None,
3840
script_params=None,
@@ -53,6 +55,8 @@ def __init__(
5355
self.arch_dir = archs_dir
5456
self.circuits = circuit_list_add
5557
self.archs = arch_list_add
58+
self.include_dir = includes_dir
59+
self.includes = include_list_add
5660
self.parse_file = parse_file
5761
self.second_parse_file = second_parse_file
5862
self.script_path = script_path
@@ -82,6 +86,7 @@ def __init__(
8286
task_name,
8387
arch,
8488
circuit,
89+
include,
8590
script_params,
8691
work_dir,
8792
run_command,
@@ -92,6 +97,7 @@ def __init__(
9297
self._task_name = task_name
9398
self._arch = arch
9499
self._circuit = circuit
100+
self._include = include
95101
self._script_params = script_params
96102
self._run_command = run_command
97103
self._parse_command = parse_command
@@ -117,6 +123,12 @@ def circuit(self):
117123
"""
118124
return self._circuit
119125

126+
def include(self):
127+
"""
128+
return the include circuits file name of the job
129+
"""
130+
return self._include
131+
120132
def script_params(self):
121133
"""
122134
return the script parameter of the job
@@ -174,6 +186,7 @@ def load_task_config(config_file):
174186
unique_keys = set(
175187
[
176188
"circuits_dir",
189+
"includes_dir",
177190
"archs_dir",
178191
"additional_files",
179192
"parse_file",
@@ -238,6 +251,7 @@ def load_task_config(config_file):
238251
key_values["script_params_common"] = split(key_values["script_params_common"])
239252

240253
check_required_fields(config_file, required_keys, key_values)
254+
check_include_fields(config_file, key_values)
241255

242256
# Useful meta-data about the config
243257
config_dir = str(Path(config_file).parent)
@@ -261,6 +275,19 @@ def check_required_fields(config_file, required_keys, key_values):
261275
)
262276

263277

278+
def check_include_fields(config_file, key_values):
279+
"""
280+
Check that includes_dir exist in case of specified include_list_add
281+
"""
282+
if "include_list_add" in key_values:
283+
if "includes_dir" not in key_values:
284+
raise VtrError(
285+
"Missing required key '{key}' in config file {file}".format(
286+
key="includes_dir", file=config_file
287+
)
288+
)
289+
290+
264291
def shorten_task_names(configs, common_task_prefix):
265292
"""
266293
Shorten the task names of the configs by remove the common task prefix.
@@ -316,6 +343,18 @@ def create_jobs(args, configs, after_run=False):
316343
# Collect any extra script params from the config file
317344
cmd = [abs_circuit_filepath, abs_arch_filepath]
318345

346+
includes = ""
347+
if config.includes:
348+
cmd += ["-include"]
349+
for include in config.includes:
350+
abs_include_filepath = resolve_vtr_source_file(
351+
config, include, config.include_dir
352+
)
353+
delimiter = " " if (include != config.includes[-1]) else ""
354+
includes = includes + abs_include_filepath + delimiter
355+
356+
cmd += [includes]
357+
319358
# Check if additional architectural data files are present
320359
if config.additional_files_list_add:
321360
for additional_file in config.additional_files_list_add:
@@ -401,6 +440,7 @@ def create_jobs(args, configs, after_run=False):
401440
args,
402441
config,
403442
circuit,
443+
includes,
404444
arch,
405445
value,
406446
cmd,
@@ -418,6 +458,7 @@ def create_jobs(args, configs, after_run=False):
418458
args,
419459
config,
420460
circuit,
461+
includes,
421462
arch,
422463
None,
423464
cmd,
@@ -437,6 +478,7 @@ def create_job(
437478
args,
438479
config,
439480
circuit,
481+
include,
440482
arch,
441483
param,
442484
cmd,
@@ -501,6 +543,7 @@ def create_job(
501543
config.task_name,
502544
arch,
503545
circuit,
546+
include,
504547
param_string,
505548
work_dir + "/" + param_string,
506549
current_cmd,

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ def vtr_command_argparser(prog=None):
322322
dest="odin_config",
323323
help="Supplies Odin with a custom config file for optimizations.",
324324
)
325+
odin.add_argument(
326+
"-include",
327+
nargs="*",
328+
default=None,
329+
dest="include_list_file",
330+
help="List of additional Verilog files to each circuit.",
331+
)
325332
#
326333
# VPR arguments
327334
#
@@ -423,6 +430,7 @@ def vtr_command_main(arg_list, prog=None):
423430
Path(args.architecture_file),
424431
Path(args.circuit_file),
425432
power_tech_file=args.power_tech,
433+
include_files=args.include_list_file,
426434
temp_dir=temp_dir,
427435
start_stage=args.start,
428436
end_stage=args.end,

0 commit comments

Comments
 (0)