Skip to content

Commit 101a839

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 101a839

File tree

4 files changed

+138
-13
lines changed

4 files changed

+138
-13
lines changed

vtr_flow/scripts/python_libs/vtr/flow.py

Lines changed: 11 additions & 1 deletion
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(),
@@ -134,7 +135,6 @@ def run(
134135
vpr_args = OrderedDict() if not vpr_args else vpr_args
135136
odin_args = OrderedDict() if not odin_args else odin_args
136137
abc_args = OrderedDict() if not abc_args else abc_args
137-
138138
# Verify that files are Paths or convert them to Paths and check that they exist
139139
architecture_file = vtr.util.verify_file(architecture_file, "Architecture")
140140
circuit_file = vtr.util.verify_file(circuit_file, "Circuit")
@@ -167,6 +167,15 @@ def run(
167167
shutil.copy(str(circuit_file), str(circuit_copy))
168168
shutil.copy(str(architecture_file), str(architecture_copy))
169169

170+
# Check whether any inclulde is specified
171+
if include_files:
172+
# Verify include files are Paths or convert them to Path + check that they exist
173+
# Copy include files to the run directory
174+
for include in include_files:
175+
include_file = vtr.util.verify_file(include, "Circuit")
176+
include_copy = temp_dir / include_file.name
177+
shutil.copy(str(include), str(include_copy))
178+
170179
# There are multiple potential paths for the netlist to reach a tool
171180
# We initialize it here to the user specified circuit and let downstream
172181
# stages update it
@@ -179,6 +188,7 @@ def run(
179188
vtr.odin.run(
180189
architecture_copy,
181190
next_stage_netlist,
191+
include_files,
182192
output_netlist=post_odin_netlist,
183193
command_runner=command_runner,
184194
temp_dir=temp_dir,

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

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,72 @@
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

910

11+
def create_circuits_list(main_circuit, include_files):
12+
"""Create a list of all (.v) and (.vh) files"""
13+
circuit_list = []
14+
# Check include files exist
15+
if include_files:
16+
# Verify that files are Paths or convert them to Paths + check that they exist
17+
for include in include_files:
18+
include_file = verify_file(include, "Circuit")
19+
circuit_list.append(include_file.name)
20+
21+
# Append the main circuit design as the last one
22+
circuit_list.append(main_circuit.name)
23+
24+
return circuit_list
25+
26+
27+
# pylint: disable=too-many-arguments, too-many-locals
28+
def init_config_file(
29+
odin_config_full_path,
30+
circuit_list,
31+
architecture_file,
32+
output_netlist,
33+
memory_addr_width,
34+
min_hard_mult_size,
35+
min_hard_adder_size,
36+
):
37+
38+
"""initializing the raw odin config file"""
39+
# Update the config file
40+
file_replace(
41+
odin_config_full_path,
42+
{
43+
"YYY": architecture_file,
44+
"ZZZ": output_netlist,
45+
"PPP": memory_addr_width,
46+
"MMM": min_hard_mult_size,
47+
"AAA": min_hard_adder_size,
48+
},
49+
)
50+
51+
# loading the given config file
52+
config_file = ET.parse(odin_config_full_path)
53+
root = config_file.getroot()
54+
55+
# based on the base condfig file
56+
verilog_files_tag = root.find("verilog_files")
57+
# remove the template line XXX, verilog_files_tag [0] is a comment
58+
verilog_files_tag.remove(verilog_files_tag[0])
59+
for circuit in circuit_list:
60+
verilog_file = ET.SubElement(verilog_files_tag, "verilog_file")
61+
verilog_file.tail = "\n\n\t" if (circuit == circuit_list[-1]) else "\n\n\t\t"
62+
verilog_file.text = circuit
63+
64+
# update the config file with new values
65+
config_file.write(odin_config_full_path)
66+
67+
1068
# pylint: disable=too-many-arguments, too-many-locals
1169
def run(
1270
architecture_file,
1371
circuit_file,
72+
include_files,
1473
output_netlist,
1574
command_runner=CommandRunner(),
1675
temp_dir=Path("."),
@@ -90,17 +149,17 @@ def run(
90149
odin_config_full_path = str(temp_dir / odin_config)
91150
shutil.copyfile(odin_base_config, odin_config_full_path)
92151

93-
# Update the config file
94-
file_replace(
152+
# Create a list showing all (.v) and (.vh) files
153+
circuit_list = create_circuits_list(circuit_file, include_files)
154+
155+
init_config_file(
95156
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-
},
157+
circuit_list,
158+
architecture_file.name,
159+
output_netlist.name,
160+
determine_memory_addr_width(str(architecture_file)),
161+
min_hard_mult_size,
162+
min_hard_adder_size,
104163
)
105164

106165
cmd = [odin_exec]
@@ -126,7 +185,7 @@ def run(
126185
"-a",
127186
architecture_file.name,
128187
"-V",
129-
circuit_file.name,
188+
circuit_list,
130189
"-o",
131190
output_netlist.name,
132191
]

vtr_flow/scripts/python_libs/vtr/task.py

Lines changed: 45 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 list of include files (.v/.vh) 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,20 @@ 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 was specified if some files to include
281+
in the designs (include_list_add) was specified.
282+
"""
283+
if "include_list_add" in key_values:
284+
if "includes_dir" not in key_values:
285+
raise VtrError(
286+
"Missing required key '{key}' in config file {file}".format(
287+
key="includes_dir", file=config_file
288+
)
289+
)
290+
291+
264292
def shorten_task_names(configs, common_task_prefix):
265293
"""
266294
Shorten the task names of the configs by remove the common task prefix.
@@ -316,6 +344,19 @@ def create_jobs(args, configs, after_run=False):
316344
# Collect any extra script params from the config file
317345
cmd = [abs_circuit_filepath, abs_arch_filepath]
318346

347+
# Resolve and collect all include paths in the config file
348+
# as -include ["include1", "include2", ..]
349+
includes = []
350+
if config.includes:
351+
cmd += ["-include"]
352+
for include in config.includes:
353+
abs_include_filepath = resolve_vtr_source_file(
354+
config, include, config.include_dir
355+
)
356+
includes.append(abs_include_filepath)
357+
358+
cmd += includes
359+
319360
# Check if additional architectural data files are present
320361
if config.additional_files_list_add:
321362
for additional_file in config.additional_files_list_add:
@@ -401,6 +442,7 @@ def create_jobs(args, configs, after_run=False):
401442
args,
402443
config,
403444
circuit,
445+
includes,
404446
arch,
405447
value,
406448
cmd,
@@ -418,6 +460,7 @@ def create_jobs(args, configs, after_run=False):
418460
args,
419461
config,
420462
circuit,
463+
includes,
421464
arch,
422465
None,
423466
cmd,
@@ -437,6 +480,7 @@ def create_job(
437480
args,
438481
config,
439482
circuit,
483+
include,
440484
arch,
441485
param,
442486
cmd,
@@ -501,6 +545,7 @@ def create_job(
501545
config.task_name,
502546
arch,
503547
circuit,
548+
include,
504549
param_string,
505550
work_dir + "/" + param_string,
506551
current_cmd,

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __call__(self, parser, namespace, value, option_string=None):
4242

4343
# pylint: enable=too-few-public-methods
4444

45-
45+
# pylint: disable=too-many-statements
4646
def vtr_command_argparser(prog=None):
4747
"""
4848
The VTR command arg parser
@@ -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 include files to a benchmark circuit(pass to Odin as a benchmark design set)",
331+
)
325332
#
326333
# VPR arguments
327334
#
@@ -382,6 +389,9 @@ def vtr_command_argparser(prog=None):
382389
return parser
383390

384391

392+
# pylint: enable=too-many-statements
393+
394+
385395
def vtr_command_main(arg_list, prog=None):
386396
"""
387397
Running VTR with the specified arguemnts.
@@ -423,6 +433,7 @@ def vtr_command_main(arg_list, prog=None):
423433
Path(args.architecture_file),
424434
Path(args.circuit_file),
425435
power_tech_file=args.power_tech,
436+
include_files=args.include_list_file,
426437
temp_dir=temp_dir,
427438
start_stage=args.start,
428439
end_stage=args.end,

0 commit comments

Comments
 (0)