Skip to content

Commit 8e68713

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 8e68713

File tree

4 files changed

+115
-12
lines changed

4 files changed

+115
-12
lines changed

vtr_flow/scripts/python_libs/vtr/flow.py

Lines changed: 12 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,16 @@ 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+
180+
170181
# There are multiple potential paths for the netlist to reach a tool
171182
# We initialize it here to the user specified circuit and let downstream
172183
# stages update it
@@ -179,6 +190,7 @@ def run(
179190
vtr.odin.run(
180191
architecture_copy,
181192
next_stage_netlist,
193+
include_files,
182194
output_netlist=post_odin_netlist,
183195
command_runner=command_runner,
184196
temp_dir=temp_dir,

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

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,54 @@
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+
# initializing the raw odin config file
11+
def init_config_file (
12+
odin_config_full_path,
13+
circuit_list,
14+
architecture_file,
15+
output_netlist,
16+
memory_addr_width,
17+
min_hard_mult_size,
18+
min_hard_adder_size,
19+
):
20+
# Update the config file
21+
file_replace(
22+
odin_config_full_path,
23+
{
24+
"YYY": architecture_file,
25+
"ZZZ": output_netlist,
26+
"PPP": memory_addr_width,
27+
"MMM": min_hard_mult_size,
28+
"AAA": min_hard_adder_size,
29+
},
30+
)
31+
32+
33+
# loading the given config file
34+
config_file = ET.parse(odin_config_full_path)
35+
root = config_file.getroot()
36+
37+
# based on the base condfig file
38+
verilog_files_tag = root.find("verilog_files")
39+
#remove the template line XXX, verilog_files_tag [0] is a comment
40+
verilog_files_tag.remove(verilog_files_tag[0])
41+
for circuit in circuit_list:
42+
verilog_file = ET.SubElement(verilog_files_tag, "verilog_file")
43+
verilog_file.tail = "\n\n\t" if (circuit == circuit_list[-1]) else "\n\n\t\t"
44+
verilog_file.text = circuit
45+
46+
# update the config file with new values
47+
config_file.write(odin_config_full_path)
48+
949

1050
# pylint: disable=too-many-arguments, too-many-locals
1151
def run(
1252
architecture_file,
1353
circuit_file,
54+
include_files,
1455
output_netlist,
1556
command_runner=CommandRunner(),
1657
temp_dir=Path("."),
@@ -90,19 +131,28 @@ def run(
90131
odin_config_full_path = str(temp_dir / odin_config)
91132
shutil.copyfile(odin_base_config, odin_config_full_path)
92133

93-
# Update the config file
94-
file_replace(
134+
135+
circuit_list = []
136+
if include_files:
137+
# Extract includes path
138+
for include in include_files:
139+
include_paths = str(include).split(" ")
140+
for include_path in include_paths:
141+
include_file = verify_file(include_path, "Circuit")
142+
circuit_list.append(include_file.name)
143+
144+
# append the main circuit design as the last one
145+
circuit_list.append(circuit_file.name)
146+
147+
init_config_file(
95148
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-
},
149+
circuit_list,
150+
architecture_file.name,
151+
output_netlist.name,
152+
determine_memory_addr_width(str(architecture_file)),
153+
min_hard_mult_size,
154+
min_hard_adder_size,
104155
)
105-
106156
cmd = [odin_exec]
107157
use_odin_simulation = False
108158

vtr_flow/scripts/python_libs/vtr/task.py

Lines changed: 34 additions & 1 deletion
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
@@ -116,6 +122,12 @@ def circuit(self):
116122
return the circuit file name of the job
117123
"""
118124
return self._circuit
125+
126+
def include(self):
127+
"""
128+
return the include circuits file name of the job
129+
"""
130+
return self._include
119131

120132
def script_params(self):
121133
"""
@@ -174,6 +186,8 @@ def load_task_config(config_file):
174186
unique_keys = set(
175187
[
176188
"circuits_dir",
189+
"includes_dir",
190+
"include_list_add",
177191
"archs_dir",
178192
"additional_files",
179193
"parse_file",
@@ -207,7 +221,12 @@ def load_task_config(config_file):
207221
value = value.strip()
208222

209223
if key in unique_keys:
210-
if key not in key_values:
224+
if key == "include_list_add":
225+
if key not in key_values:
226+
key_values[key] = [value]
227+
else:
228+
key_values[key].append(value)
229+
elif key not in key_values:
211230
key_values[key] = value
212231
elif key == "parse_file":
213232
key_values["second_parse_file"] = value
@@ -316,6 +335,16 @@ def create_jobs(args, configs, after_run=False):
316335
# Collect any extra script params from the config file
317336
cmd = [abs_circuit_filepath, abs_arch_filepath]
318337

338+
includes = ""
339+
if config.includes:
340+
cmd += ["-include"]
341+
for include in config.includes:
342+
abs_include_filepath = resolve_vtr_source_file(config, include, config.include_dir)
343+
delimiter = " " if (include != config.includes[-1]) else ""
344+
includes = includes + abs_include_filepath + delimiter
345+
346+
cmd += [includes]
347+
319348
# Check if additional architectural data files are present
320349
if config.additional_files_list_add:
321350
for additional_file in config.additional_files_list_add:
@@ -401,6 +430,7 @@ def create_jobs(args, configs, after_run=False):
401430
args,
402431
config,
403432
circuit,
433+
includes,
404434
arch,
405435
value,
406436
cmd,
@@ -418,6 +448,7 @@ def create_jobs(args, configs, after_run=False):
418448
args,
419449
config,
420450
circuit,
451+
includes,
421452
arch,
422453
None,
423454
cmd,
@@ -437,6 +468,7 @@ def create_job(
437468
args,
438469
config,
439470
circuit,
471+
include,
440472
arch,
441473
param,
442474
cmd,
@@ -501,6 +533,7 @@ def create_job(
501533
config.task_name,
502534
arch,
503535
circuit,
536+
include,
504537
param_string,
505538
work_dir + "/" + param_string,
506539
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)