Skip to content

Commit 98810f8

Browse files
authored
Merge pull request #1532 from byuccl/abc_path_fix
run_vtr_flow.py: use VTR exe paths instead of searching on PATH
2 parents 776026f + 2b7daca commit 98810f8

File tree

9 files changed

+84
-140
lines changed

9 files changed

+84
-140
lines changed

vtr_flow/scripts/python_libs/vtr/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
from .util import (
55
load_config_lines,
6-
find_vtr_file,
76
CommandRunner,
87
print_verbose,
98
relax_w,
@@ -13,7 +12,6 @@
1312
format_elapsed_time,
1413
write_tab_delimitted_csv,
1514
load_list_file,
16-
find_vtr_root,
1715
argparse_str2bool,
1816
get_next_run_dir,
1917
get_latest_run_dir,

vtr_flow/scripts/python_libs/vtr/abc/abc.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import shutil
55
from collections import OrderedDict
66
from pathlib import Path
7-
from vtr import find_vtr_file, determine_lut_size, verify_file, CommandRunner
7+
from vtr import determine_lut_size, verify_file, CommandRunner
8+
from vtr import paths
89
from vtr.error import InspectError
910

1011
# pylint: disable=too-many-arguments, too-many-locals
@@ -78,7 +79,7 @@ def run(
7879
circuit_file = verify_file(circuit_file, "Circuit")
7980
output_netlist = verify_file(output_netlist, "Output netlist", should_exist=False)
8081

81-
blackbox_latches_script = find_vtr_file("blackbox_latches.pl")
82+
blackbox_latches_script = str(paths.blackbox_latches_script_path)
8283
clk_list = []
8384
#
8485
# Parse arguments
@@ -95,8 +96,8 @@ def run(
9596

9697
populate_clock_list(circuit_file, blackbox_latches_script, clk_list, command_runner, temp_dir)
9798

98-
abc_exec = find_vtr_file("abc", is_executable=True) if abc_exec is None else abc_exec
99-
abc_rc = Path(abc_exec).parent / "abc.rc" if abc_rc is None else abc_rc
99+
abc_exec = str(paths.abc_exe_path) if abc_exec is None else abc_exec
100+
abc_rc = str(paths.abc_rc_path) if abc_rc is None else abc_rc
100101

101102
shutil.copyfile(str(abc_rc), str(temp_dir / "abc.rc"))
102103

@@ -225,9 +226,9 @@ def run(
225226
)
226227
else:
227228
restore_multiclock_info_script = (
228-
find_vtr_file("restore_multiclock_latch_information.pl")
229+
str(paths.restore_multiclock_latch_old_script_path)
229230
if use_old_latches_restoration_script
230-
else find_vtr_file("restore_multiclock_latch.pl")
231+
else str(paths.restore_multiclock_latch_script_path)
231232
)
232233
command_runner.run_system_command(
233234
[
@@ -362,7 +363,7 @@ def run_lec(
362363
temp_dir.mkdir(parents=True, exist_ok=True)
363364

364365
if abc_exec is None:
365-
abc_exec = find_vtr_file("abc", is_executable=True)
366+
abc_exec = str(paths.abc_exe_path)
366367

367368
abc_script = ("dsec {ref} {imp}".format(ref=reference_netlist, imp=implementation_netlist),)
368369
abc_script = "; ".join(abc_script)

vtr_flow/scripts/python_libs/vtr/ace/ace.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Module to run ACE with its various options
33
"""
44
from pathlib import Path
5-
from vtr import find_vtr_file, verify_file, CommandRunner
5+
from vtr import verify_file, CommandRunner, paths
66

77
# pylint: disable=too-many-arguments
88
def run(
@@ -62,9 +62,9 @@ def run(
6262
ace_clk_file = temp_dir / "ace_clk.txt"
6363
ace_raw = temp_dir / (circuit_file.with_suffix("").stem + ".raw.ace.blif")
6464
if ace_exec is None:
65-
ace_exec = find_vtr_file("ace")
65+
ace_exec = str(paths.ace_exe_path)
6666

67-
cmd = [find_vtr_file("extract_clk_from_blif.py"), ace_clk_file.name, circuit_file.name]
67+
cmd = [str(paths.ace_extract_clk_from_blif_script_path), ace_clk_file.name, circuit_file.name]
6868
command_runner.run_system_command(
6969
cmd, temp_dir=temp_dir, log_filename="ace_clk_extraction.out", indent_depth=1
7070
)
@@ -89,7 +89,7 @@ def run(
8989
cmd, temp_dir=temp_dir, log_filename=log_filename, indent_depth=1
9090
)
9191

92-
clock_script = find_vtr_file("restore_multiclock_latch.pl")
92+
clock_script = str(paths.restore_multiclock_latch_script_path)
9393

9494
cmd = [clock_script, old_netlist.name, ace_raw.name, output_netlist.name]
9595
command_runner.run_system_command(

vtr_flow/scripts/python_libs/vtr/flow.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ def __ge__(self, other):
3131

3232
# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-statements
3333
def run(
34-
architecture_file,
35-
circuit_file,
36-
power_tech_file=None,
37-
start_stage=VtrStage.odin,
38-
end_stage=VtrStage.vpr,
39-
command_runner=vtr.CommandRunner(),
40-
temp_dir=Path("./temp"),
41-
odin_args=None,
42-
abc_args=None,
43-
vpr_args=None,
44-
keep_intermediate_files=True,
45-
keep_result_files=True,
46-
min_hard_mult_size=3,
47-
min_hard_adder_size=1,
48-
check_equivalent=False,
49-
check_incremental_sta_consistency=False,
50-
use_old_abc_script=False,
51-
relax_w_factor=1.3,
52-
check_route = False,
53-
check_place = False,
34+
architecture_file,
35+
circuit_file,
36+
power_tech_file=None,
37+
start_stage=VtrStage.odin,
38+
end_stage=VtrStage.vpr,
39+
command_runner=vtr.CommandRunner(),
40+
temp_dir=Path("./temp"),
41+
odin_args=None,
42+
abc_args=None,
43+
vpr_args=None,
44+
keep_intermediate_files=True,
45+
keep_result_files=True,
46+
min_hard_mult_size=3,
47+
min_hard_adder_size=1,
48+
check_equivalent=False,
49+
check_incremental_sta_consistency=False,
50+
use_old_abc_script=False,
51+
relax_w_factor=1.3,
52+
check_route=False,
53+
check_place=False,
5454
):
5555
"""
5656
Runs the VTR CAD flow to map the specified circuit_file onto the target architecture_file
@@ -252,7 +252,7 @@ def run(
252252
do_second_run = False
253253
second_run_args = vpr_args
254254

255-
if "write_rr_graph" in vpr_args or "analysis" in vpr_args or "route" in vpr_args:
255+
if "write_rr_graph" in vpr_args or "analysis" in vpr_args or "route" in vpr_args:
256256
do_second_run = True
257257

258258
vtr.vpr.run(

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
import shutil
55
from collections import OrderedDict
66
from pathlib import Path
7-
from vtr import (
8-
find_vtr_file,
9-
file_replace,
10-
determine_memory_addr_width,
11-
verify_file,
12-
CommandRunner,
13-
)
7+
from vtr import file_replace, determine_memory_addr_width, verify_file, CommandRunner, paths
8+
149

1510
# pylint: disable=too-many-arguments, too-many-locals
1611
def run(
@@ -83,10 +78,10 @@ def run(
8378
output_netlist = verify_file(output_netlist, "Output netlist", False)
8479

8580
if odin_exec is None:
86-
odin_exec = find_vtr_file("odin_II", is_executable=True)
81+
odin_exec = str(paths.odin_exe_path)
8782

8883
if odin_config is None:
89-
odin_base_config = find_vtr_file("basic_odin_config_split.xml")
84+
odin_base_config = str(paths.odin_cfg_path)
9085

9186
# Copy the config file
9287
odin_config = "odin_config.xml"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
""" Paths for different VTR flow executables and resources """
2+
3+
import pathlib
4+
5+
# Path to the root repository directory
6+
root_path = pathlib.Path(__file__).absolute().parent.parent.parent.parent.parent
7+
8+
# VTR Paths
9+
vtr_flow_path = root_path / "vtr_flow"
10+
scripts_path = vtr_flow_path / "scripts"
11+
build_path = root_path / "build"
12+
13+
# ODIN paths
14+
odin_path = root_path / "ODIN_II"
15+
odin_exe_path = odin_path / "odin_II"
16+
odin_cfg_path = vtr_flow_path / "misc" / "basic_odin_config_split.xml"
17+
18+
# ABC paths
19+
abc_path = root_path / "abc"
20+
abc_exe_path = abc_path / "abc"
21+
abc_rc_path = abc_path / "abc.rc"
22+
23+
# ACE paths
24+
ace_path = root_path / "ace2"
25+
ace_exe_path = ace_path / "ace"
26+
ace_extract_clk_from_blif_script_path = ace_path / "scripts" / "extract_clk_from_blif.py"
27+
28+
# VPR paths
29+
vpr_path = root_path / "vpr"
30+
vpr_exe_path = vpr_path / "vpr"
31+
32+
# Other scripts
33+
blackbox_latches_script_path = scripts_path / "blackbox_latches.pl"
34+
restore_multiclock_latch_old_script_path = scripts_path / "restore_multiclock_latch_information.pl"
35+
restore_multiclock_latch_script_path = scripts_path / "restore_multiclock_latch.pl"
36+
valgrind_supp = vpr_path / "valgrind.supp"
37+
lsan_supp = vpr_path / "lsan.supp"

vtr_flow/scripts/python_libs/vtr/util.py

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
"""
22
Module to utilize many of the tools needed for VTR.
33
"""
4-
import os
54
from pathlib import PurePath
65
from pathlib import Path
76
import sys
87
import re
98
import time
109
import subprocess
11-
import distutils.spawn as distutils_spawn
1210
import argparse
1311
import csv
1412
from collections import OrderedDict
1513
import vtr.error
16-
from vtr.error import VtrError, CommandError
14+
from vtr.error import CommandError
15+
from vtr import paths
1716

1817
VERBOSITY_CHOICES = range(5)
1918

@@ -108,7 +107,7 @@ def run_system_command(
108107
+ [
109108
"valgrind",
110109
"--leak-check=full",
111-
"--suppressions={}".format(find_vtr_file("valgrind.supp")),
110+
"--suppressions=" + str(paths.valgrind_supp),
112111
"--error-exitcode=1",
113112
"--errors-for-leak-kinds=none",
114113
"--track-origins=yes",
@@ -293,90 +292,6 @@ def print_verbose(min_verbosity, curr_verbosity, string, endl=True):
293292
print(string,)
294293

295294

296-
def find_vtr_file(filename, is_executable=False):
297-
"""
298-
Attempts to find a VTR related file by searching the environment.
299-
300-
Checking the following places:
301-
1) System path (if is_executable=True)
302-
2) The inferred vtr root from environment variables or the script file location
303-
304-
"""
305-
# We assume exectuables are specified in the unix style (no .exe),
306-
# if it was specified with .exe, strip it off
307-
file_path = PurePath(filename)
308-
if file_path.suffix == ".exe":
309-
filename = file_path.name
310-
311-
#
312-
# Check if it is on the path (provided it is executable)
313-
#
314-
if is_executable:
315-
# Search first for the non-exe version
316-
result = distutils_spawn.find_executable(filename)
317-
if result:
318-
return result
319-
320-
# If not found try the .exe version
321-
result = distutils_spawn.find_executable(filename + ".exe")
322-
if result:
323-
return result
324-
325-
vtr_root = find_vtr_root()
326-
327-
# Check the inferred VTR root
328-
result = find_file_from_vtr_root(filename, vtr_root, is_executable=is_executable)
329-
if result:
330-
return result
331-
332-
# Since we stripped off the .exe, try looking for the .exe version
333-
# as a last resort (i.e. on Windows/cygwin)
334-
if is_executable:
335-
result = find_file_from_vtr_root(filename + ".exe", vtr_root, is_executable=is_executable)
336-
if result:
337-
return result
338-
339-
raise ValueError(
340-
"Could not find {type} {file}".format(
341-
type="executable" if is_executable else "file", file=filename
342-
)
343-
)
344-
345-
346-
def find_file_from_vtr_root(filename, vtr_root, is_executable=False):
347-
"""
348-
Given a vtr_root and a filename searches for the file recursively
349-
under some common VTR directories
350-
"""
351-
for subdir in ["vpr", "abc", "abc_with_bb_support", "ODIN_II", "vtr_flow", "ace2"]:
352-
directory_path = Path(vtr_root) / subdir
353-
for file_path in directory_path.glob("**/*"):
354-
if file_path.name == filename:
355-
if file_path.is_file():
356-
if is_executable and os.access(str(file_path), os.X_OK):
357-
# Found an executable file as required
358-
return str(file_path)
359-
# Found a file as required
360-
return str(file_path)
361-
return None
362-
363-
364-
def find_vtr_root():
365-
"""
366-
finds the root directory of VTR
367-
"""
368-
for env_var in ["VTR_ROOT"]:
369-
if env_var in os.environ:
370-
return os.environ[env_var]
371-
372-
# We assume that this file is in <vtr_root>/vtr_flow/python_libs/verilogtorouting
373-
inferred_vtr_root = Path(__file__).parent.parent.parent.parent.parent
374-
375-
if inferred_vtr_root.is_dir():
376-
return str(inferred_vtr_root)
377-
raise VtrError("Could not find VTR root directory. Try setting VTR_ROOT environment variable.")
378-
379-
380295
def file_replace(filename, search_replace_dict):
381296
"""
382297
searches file for specified values and replaces them with specified values.
@@ -462,9 +377,7 @@ def load_config_lines(filepath, allow_includes=True):
462377
include_file_abs, allow_includes=allow_includes
463378
)
464379
else:
465-
raise vtr.error.InspectError(
466-
"@include not allowed in this file", filepath
467-
)
380+
raise vtr.error.InspectError("@include not allowed in this file", filepath)
468381
else:
469382
config_lines.append(line)
470383
except IOError as error:

vtr_flow/scripts/python_libs/vtr/vpr/vpr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from collections import OrderedDict
55
from pathlib import Path
66
from os import environ
7-
from vtr import find_vtr_file, CommandRunner, relax_w, determine_min_w, verify_file
7+
from vtr import CommandRunner, relax_w, determine_min_w, verify_file, paths
88
from vtr.error import InspectError
99

1010
# pylint: disable=too-many-arguments
@@ -80,7 +80,7 @@ def run_relax_w(
8080
del vpr_args["write_rr_graph"]
8181

8282
if vpr_exec is None:
83-
vpr_exec = find_vtr_file("vpr", is_executable=True)
83+
vpr_exec = str(paths.vpr_exe_path)
8484

8585
run(
8686
architecture,
@@ -172,7 +172,7 @@ def run(
172172
temp_dir.mkdir(parents=True, exist_ok=True)
173173

174174
if vpr_exec is None:
175-
vpr_exec = find_vtr_file("vpr", is_executable=True)
175+
vpr_exec = str(paths.vpr_exe_path)
176176

177177
# Verify that files are Paths or convert them to Paths and check that they exist
178178
architecture = verify_file(architecture, "Architecture")
@@ -212,7 +212,7 @@ def run(
212212
# 'fast_unwind_on_malloc=0' Provide more accurate leak stack traces
213213

214214
environ["LSAN_OPTIONS"] = "suppressions={} exitcode=23 fast_unwind_on_malloc=0".format(
215-
find_vtr_file("lsan.supp")
215+
str(paths.lsan_supp)
216216
)
217217

218218
command_runner.run_system_command(

vtr_flow/scripts/run_vtr_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ def vtr_command_main(arg_list, prog=None):
431431
check_incremental_sta_consistency=args.check_incremental_sta_consistency,
432432
use_old_abc_script=args.use_old_abc_script,
433433
relax_w_factor=args.relax_w_factor,
434-
check_route = args.check_route,
435-
check_place = args.check_place,
434+
check_route=args.check_route,
435+
check_place=args.check_place,
436436
)
437437
error_status = "OK"
438438
except vtr.VtrError as error:

0 commit comments

Comments
 (0)