Skip to content

Commit 2d3e642

Browse files
Add include_temp to vtr task syntax
When I pass rr graph and router lookahead files to VPR, it throws an error. capnproto uses mmap to open these files. It seems that multiple processes can access a single file using mmap. However, I cannot trust capnproto. The changes in this commit enhace the vtr task syntax by allowing copying arbitrary files to the temporay directory. This way, I can copy rr graph file and prevent multiple processes accessing the same file.
1 parent 37426cb commit 2d3e642

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

vtr_flow/scripts/python_libs/vtr/flow.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Module to run the VTR flow. This module calls other modules that then access the tools like VPR.
33
"""
4+
import os
45
import shutil
56
from pathlib import Path
67
from collections import OrderedDict
@@ -36,6 +37,7 @@ def run(
3637
circuit_file,
3738
power_tech_file=None,
3839
include_files=None,
40+
include_temp_files=None,
3941
start_stage=VtrStage.PARMYS,
4042
end_stage=VtrStage.VPR,
4143
command_runner=vtr.CommandRunner(),
@@ -176,7 +178,7 @@ def run(
176178
shutil.copy(str(circuit_file), str(circuit_copy))
177179
shutil.copy(str(architecture_file), str(architecture_copy))
178180

179-
# Check whether any inclulde is specified
181+
# Check whether any include is specified
180182
if include_files:
181183
# Verify include files are Paths or convert them to Path + check that they exist
182184
# Copy include files to the run directory
@@ -185,6 +187,17 @@ def run(
185187
include_copy = temp_dir / include_file.name
186188
shutil.copy(str(include), str(include_copy))
187189

190+
191+
# Check whether any include is specified
192+
if include_temp_files:
193+
# Verify include files are Paths or convert them to Path + check that they exist
194+
# Copy temp include files to the run directory
195+
for include_temp in include_temp_files:
196+
include_temp_file = vtr.util.verify_file(include_temp, "Temporary Include")
197+
include_temp_copy = temp_dir / include_temp_file.name
198+
shutil.copy(str(include_temp), str(include_temp_copy))
199+
200+
188201
# There are multiple potential paths for the netlist to reach a tool
189202
# We initialize it here to the user specified circuit and let downstream
190203
# stages update it
@@ -384,6 +397,15 @@ def run(
384397
power_tech_file,
385398
)
386399

400+
# Check whether any temporary include is specified
401+
if include_temp_files:
402+
# Verify temp include files are Paths or convert them to Path + check that they exist
403+
# Then find
404+
for include_temp in include_temp_files:
405+
include_temp_file = vtr.util.verify_file(include_temp, "Temporary Include")
406+
include_temp_copy = temp_dir / include_temp_file.name
407+
os.remove(str(include_temp_copy))
408+
387409

388410
# pylint: enable=too-many-arguments, too-many-locals, too-many-branches, too-many-statements
389411

vtr_flow/scripts/python_libs/vtr/task.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def __init__(
3939
parse_file,
4040
includes_dir=None,
4141
include_list_add=None,
42+
include_temp_dir=None,
43+
include_temp_list_add=None,
4244
second_parse_file=None,
4345
script_path=None,
4446
script_params=None,
@@ -64,6 +66,8 @@ def __init__(
6466
self.archs = arch_list_add
6567
self.include_dir = includes_dir
6668
self.includes = include_list_add
69+
self.include_temp_dir = include_temp_dir
70+
self.include_temps = include_temp_list_add
6771
self.parse_file = parse_file
6872
self.second_parse_file = second_parse_file
6973
self.script_path = script_path
@@ -97,6 +101,7 @@ def __init__(
97101
arch,
98102
circuit,
99103
include,
104+
include_temp,
100105
script_params,
101106
work_dir,
102107
run_command,
@@ -108,6 +113,7 @@ def __init__(
108113
self._arch = arch
109114
self._circuit = circuit
110115
self._include = include
116+
self._include_temp = include_temp
111117
self._script_params = script_params
112118
self._run_command = run_command
113119
self._parse_command = parse_command
@@ -139,6 +145,12 @@ def include(self):
139145
"""
140146
return self._include
141147

148+
def include_temp(self):
149+
"""
150+
return the list of temporary include files of the job.
151+
"""
152+
return self._include_temp
153+
142154
def script_params(self):
143155
"""
144156
return the script parameter of the job
@@ -197,6 +209,7 @@ def load_task_config(config_file) -> TaskConfig:
197209
[
198210
"circuits_dir",
199211
"includes_dir",
212+
"include_temp_dir",
200213
"archs_dir",
201214
"additional_files",
202215
"parse_file",
@@ -264,6 +277,7 @@ def load_task_config(config_file) -> TaskConfig:
264277

265278
check_required_fields(config_file, required_keys, key_values)
266279
check_include_fields(config_file, key_values)
280+
check_include_temp_fields(config_file, key_values)
267281

268282
# Useful meta-data about the config
269283
config_dir = str(Path(config_file).parent)
@@ -300,6 +314,18 @@ def check_include_fields(config_file, key_values):
300314
)
301315
)
302316

317+
def check_include_temp_fields(config_file, key_values):
318+
"""
319+
Check that include_temp_dir was specified if some files to temporarily include
320+
in the designs (include_temp_list_add) was specified.
321+
"""
322+
if "include_temp_list_add" in key_values:
323+
if "include_temp_dir" not in key_values:
324+
raise VtrError(
325+
"Missing required key '{key}' in config file {file}".format(
326+
key="include_temp_dir", file=config_file
327+
)
328+
)
303329

304330
def shorten_task_names(configs, common_task_prefix):
305331
"""
@@ -377,6 +403,17 @@ def create_cmd(
377403

378404
cmd += includes
379405

406+
# Resolve and collect all include_temp paths in the config file
407+
# as -include_temp ["include_temp1", "include_temp2", ..]
408+
include_temps = []
409+
if config.include_temps:
410+
cmd += ["-include_temp"]
411+
for include_temp in config.include_temps:
412+
abs_include_filepath = resolve_vtr_source_file(config, include_temp, config.include_temp_dir)
413+
include_temps.append(abs_include_filepath)
414+
415+
cmd += include_temps
416+
380417
# Check if additional architectural data files are present
381418
if config.additional_files_list_add:
382419
for additional_file in config.additional_files_list_add:
@@ -466,7 +503,7 @@ def create_cmd(
466503
resolve_vtr_source_file(config, noc_traffic, config.noc_traffic_dir),
467504
]
468505

469-
return includes, parse_cmd, second_parse_cmd, qor_parse_command, cmd
506+
return includes, include_temps, parse_cmd, second_parse_cmd, qor_parse_command, cmd
470507

471508

472509
# pylint: disable=too-many-branches
@@ -509,7 +546,7 @@ def create_jobs(args, configs, after_run=False) -> List[Job]:
509546
)
510547
)
511548

512-
includes, parse_cmd, second_parse_cmd, qor_parse_command, cmd = create_cmd(
549+
includes, include_temps, parse_cmd, second_parse_cmd, qor_parse_command, cmd = create_cmd(
513550
abs_circuit_filepath, abs_arch_filepath, config, args, circuit, noc_traffic
514551
)
515552

@@ -521,6 +558,7 @@ def create_jobs(args, configs, after_run=False) -> List[Job]:
521558
config,
522559
circuit,
523560
includes,
561+
include_temps,
524562
arch,
525563
noc_traffic,
526564
value,
@@ -540,6 +578,7 @@ def create_jobs(args, configs, after_run=False) -> List[Job]:
540578
config,
541579
circuit,
542580
includes,
581+
include_temps,
543582
arch,
544583
noc_traffic,
545584
None,
@@ -561,6 +600,7 @@ def create_job(
561600
config,
562601
circuit,
563602
include,
603+
include_temp,
564604
arch,
565605
noc_flow,
566606
param,
@@ -658,6 +698,7 @@ def create_job(
658698
arch,
659699
circuit,
660700
include,
701+
include_temp,
661702
param_string,
662703
work_dir + "/" + param_string,
663704
current_cmd,

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ def vtr_command_argparser(prog=None):
155155
help="List of include files to a benchmark circuit (pass to VTR"
156156
+ " frontends as a benchmark design set)",
157157
)
158+
parser.add_argument(
159+
"-include_temp",
160+
nargs="*",
161+
default=None,
162+
dest="include_temp_list_file",
163+
help="List of include files to be copied to the working directory"
164+
+ " and be removed when the task is done)",
165+
)
158166

159167
#
160168
# Power arguments
@@ -561,6 +569,7 @@ def vtr_command_main(arg_list, prog=None):
561569
Path(args.circuit_file),
562570
power_tech_file=args.power_tech,
563571
include_files=args.include_list_file,
572+
include_temp_files=args.include_temp_list_file,
564573
temp_dir=temp_dir,
565574
start_stage=args.start,
566575
end_stage=args.end,

0 commit comments

Comments
 (0)