Skip to content

run_vtr_flow.py: use VTR exe paths instead of searching on PATH #1532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions vtr_flow/scripts/python_libs/vtr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
from .util import (
load_config_lines,
find_vtr_file,
CommandRunner,
print_verbose,
relax_w,
Expand All @@ -13,7 +12,6 @@
format_elapsed_time,
write_tab_delimitted_csv,
load_list_file,
find_vtr_root,
argparse_str2bool,
get_next_run_dir,
get_latest_run_dir,
Expand Down
15 changes: 8 additions & 7 deletions vtr_flow/scripts/python_libs/vtr/abc/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import shutil
from collections import OrderedDict
from pathlib import Path
from vtr import find_vtr_file, determine_lut_size, verify_file, CommandRunner
from vtr import determine_lut_size, verify_file, CommandRunner
from vtr import paths
from vtr.error import InspectError

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

blackbox_latches_script = find_vtr_file("blackbox_latches.pl")
blackbox_latches_script = str(paths.blackbox_latches_script_path)
clk_list = []
#
# Parse arguments
Expand All @@ -95,8 +96,8 @@ def run(

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

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

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

Expand Down Expand Up @@ -225,9 +226,9 @@ def run(
)
else:
restore_multiclock_info_script = (
find_vtr_file("restore_multiclock_latch_information.pl")
str(paths.restore_multiclock_latch_old_script_path)
if use_old_latches_restoration_script
else find_vtr_file("restore_multiclock_latch.pl")
else str(paths.restore_multiclock_latch_script_path)
)
command_runner.run_system_command(
[
Expand Down Expand Up @@ -362,7 +363,7 @@ def run_lec(
temp_dir.mkdir(parents=True, exist_ok=True)

if abc_exec is None:
abc_exec = find_vtr_file("abc", is_executable=True)
abc_exec = str(paths.abc_exe_path)

abc_script = ("dsec {ref} {imp}".format(ref=reference_netlist, imp=implementation_netlist),)
abc_script = "; ".join(abc_script)
Expand Down
8 changes: 4 additions & 4 deletions vtr_flow/scripts/python_libs/vtr/ace/ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module to run ACE with its various options
"""
from pathlib import Path
from vtr import find_vtr_file, verify_file, CommandRunner
from vtr import verify_file, CommandRunner, paths

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

cmd = [find_vtr_file("extract_clk_from_blif.py"), ace_clk_file.name, circuit_file.name]
cmd = [str(paths.ace_extract_clk_from_blif_script_path), ace_clk_file.name, circuit_file.name]
command_runner.run_system_command(
cmd, temp_dir=temp_dir, log_filename="ace_clk_extraction.out", indent_depth=1
)
Expand All @@ -89,7 +89,7 @@ def run(
cmd, temp_dir=temp_dir, log_filename=log_filename, indent_depth=1
)

clock_script = find_vtr_file("restore_multiclock_latch.pl")
clock_script = str(paths.restore_multiclock_latch_script_path)

cmd = [clock_script, old_netlist.name, ace_raw.name, output_netlist.name]
command_runner.run_system_command(
Expand Down
42 changes: 21 additions & 21 deletions vtr_flow/scripts/python_libs/vtr/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ def __ge__(self, other):

# pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-statements
def run(
architecture_file,
circuit_file,
power_tech_file=None,
start_stage=VtrStage.odin,
end_stage=VtrStage.vpr,
command_runner=vtr.CommandRunner(),
temp_dir=Path("./temp"),
odin_args=None,
abc_args=None,
vpr_args=None,
keep_intermediate_files=True,
keep_result_files=True,
min_hard_mult_size=3,
min_hard_adder_size=1,
check_equivalent=False,
check_incremental_sta_consistency=False,
use_old_abc_script=False,
relax_w_factor=1.3,
check_route = False,
check_place = False,
architecture_file,
circuit_file,
power_tech_file=None,
start_stage=VtrStage.odin,
end_stage=VtrStage.vpr,
command_runner=vtr.CommandRunner(),
temp_dir=Path("./temp"),
odin_args=None,
abc_args=None,
vpr_args=None,
keep_intermediate_files=True,
keep_result_files=True,
min_hard_mult_size=3,
min_hard_adder_size=1,
check_equivalent=False,
check_incremental_sta_consistency=False,
use_old_abc_script=False,
relax_w_factor=1.3,
check_route=False,
check_place=False,
):
"""
Runs the VTR CAD flow to map the specified circuit_file onto the target architecture_file
Expand Down Expand Up @@ -252,7 +252,7 @@ def run(
do_second_run = False
second_run_args = vpr_args

if "write_rr_graph" in vpr_args or "analysis" in vpr_args or "route" in vpr_args:
if "write_rr_graph" in vpr_args or "analysis" in vpr_args or "route" in vpr_args:
do_second_run = True

vtr.vpr.run(
Expand Down
13 changes: 4 additions & 9 deletions vtr_flow/scripts/python_libs/vtr/odin/odin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
import shutil
from collections import OrderedDict
from pathlib import Path
from vtr import (
find_vtr_file,
file_replace,
determine_memory_addr_width,
verify_file,
CommandRunner,
)
from vtr import file_replace, determine_memory_addr_width, verify_file, CommandRunner, paths


# pylint: disable=too-many-arguments, too-many-locals
def run(
Expand Down Expand Up @@ -83,10 +78,10 @@ def run(
output_netlist = verify_file(output_netlist, "Output netlist", False)

if odin_exec is None:
odin_exec = find_vtr_file("odin_II", is_executable=True)
odin_exec = str(paths.odin_exe_path)

if odin_config is None:
odin_base_config = find_vtr_file("basic_odin_config_split.xml")
odin_base_config = str(paths.odin_cfg_path)

# Copy the config file
odin_config = "odin_config.xml"
Expand Down
37 changes: 37 additions & 0 deletions vtr_flow/scripts/python_libs/vtr/paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
""" Paths for different VTR flow executables and resources """

import pathlib

# Path to the root repository directory
root_path = pathlib.Path(__file__).absolute().parent.parent.parent.parent.parent

# VTR Paths
vtr_flow_path = root_path / "vtr_flow"
scripts_path = vtr_flow_path / "scripts"
build_path = root_path / "build"

# ODIN paths
odin_path = root_path / "ODIN_II"
odin_exe_path = odin_path / "odin_II"
odin_cfg_path = vtr_flow_path / "misc" / "basic_odin_config_split.xml"

# ABC paths
abc_path = root_path / "abc"
abc_exe_path = abc_path / "abc"
abc_rc_path = abc_path / "abc.rc"

# ACE paths
ace_path = root_path / "ace2"
ace_exe_path = ace_path / "ace"
ace_extract_clk_from_blif_script_path = ace_path / "scripts" / "extract_clk_from_blif.py"

# VPR paths
vpr_path = root_path / "vpr"
vpr_exe_path = vpr_path / "vpr"

# Other scripts
blackbox_latches_script_path = scripts_path / "blackbox_latches.pl"
restore_multiclock_latch_old_script_path = scripts_path / "restore_multiclock_latch_information.pl"
restore_multiclock_latch_script_path = scripts_path / "restore_multiclock_latch.pl"
valgrind_supp = vpr_path / "valgrind.supp"
lsan_supp = vpr_path / "lsan.supp"
95 changes: 4 additions & 91 deletions vtr_flow/scripts/python_libs/vtr/util.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
"""
Module to utilize many of the tools needed for VTR.
"""
import os
from pathlib import PurePath
from pathlib import Path
import sys
import re
import time
import subprocess
import distutils.spawn as distutils_spawn
import argparse
import csv
from collections import OrderedDict
import vtr.error
from vtr.error import VtrError, CommandError
from vtr.error import CommandError
from vtr import paths

VERBOSITY_CHOICES = range(5)

Expand Down Expand Up @@ -108,7 +107,7 @@ def run_system_command(
+ [
"valgrind",
"--leak-check=full",
"--suppressions={}".format(find_vtr_file("valgrind.supp")),
"--suppressions=" + str(paths.valgrind_supp),
"--error-exitcode=1",
"--errors-for-leak-kinds=none",
"--track-origins=yes",
Expand Down Expand Up @@ -293,90 +292,6 @@ def print_verbose(min_verbosity, curr_verbosity, string, endl=True):
print(string,)


def find_vtr_file(filename, is_executable=False):
"""
Attempts to find a VTR related file by searching the environment.

Checking the following places:
1) System path (if is_executable=True)
2) The inferred vtr root from environment variables or the script file location

"""
# We assume exectuables are specified in the unix style (no .exe),
# if it was specified with .exe, strip it off
file_path = PurePath(filename)
if file_path.suffix == ".exe":
filename = file_path.name

#
# Check if it is on the path (provided it is executable)
#
if is_executable:
# Search first for the non-exe version
result = distutils_spawn.find_executable(filename)
if result:
return result

# If not found try the .exe version
result = distutils_spawn.find_executable(filename + ".exe")
if result:
return result

vtr_root = find_vtr_root()

# Check the inferred VTR root
result = find_file_from_vtr_root(filename, vtr_root, is_executable=is_executable)
if result:
return result

# Since we stripped off the .exe, try looking for the .exe version
# as a last resort (i.e. on Windows/cygwin)
if is_executable:
result = find_file_from_vtr_root(filename + ".exe", vtr_root, is_executable=is_executable)
if result:
return result

raise ValueError(
"Could not find {type} {file}".format(
type="executable" if is_executable else "file", file=filename
)
)


def find_file_from_vtr_root(filename, vtr_root, is_executable=False):
"""
Given a vtr_root and a filename searches for the file recursively
under some common VTR directories
"""
for subdir in ["vpr", "abc", "abc_with_bb_support", "ODIN_II", "vtr_flow", "ace2"]:
directory_path = Path(vtr_root) / subdir
for file_path in directory_path.glob("**/*"):
if file_path.name == filename:
if file_path.is_file():
if is_executable and os.access(str(file_path), os.X_OK):
# Found an executable file as required
return str(file_path)
# Found a file as required
return str(file_path)
return None


def find_vtr_root():
"""
finds the root directory of VTR
"""
for env_var in ["VTR_ROOT"]:
if env_var in os.environ:
return os.environ[env_var]

# We assume that this file is in <vtr_root>/vtr_flow/python_libs/verilogtorouting
inferred_vtr_root = Path(__file__).parent.parent.parent.parent.parent

if inferred_vtr_root.is_dir():
return str(inferred_vtr_root)
raise VtrError("Could not find VTR root directory. Try setting VTR_ROOT environment variable.")


def file_replace(filename, search_replace_dict):
"""
searches file for specified values and replaces them with specified values.
Expand Down Expand Up @@ -462,9 +377,7 @@ def load_config_lines(filepath, allow_includes=True):
include_file_abs, allow_includes=allow_includes
)
else:
raise vtr.error.InspectError(
"@include not allowed in this file", filepath
)
raise vtr.error.InspectError("@include not allowed in this file", filepath)
else:
config_lines.append(line)
except IOError as error:
Expand Down
8 changes: 4 additions & 4 deletions vtr_flow/scripts/python_libs/vtr/vpr/vpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import OrderedDict
from pathlib import Path
from os import environ
from vtr import find_vtr_file, CommandRunner, relax_w, determine_min_w, verify_file
from vtr import CommandRunner, relax_w, determine_min_w, verify_file, paths
from vtr.error import InspectError

# pylint: disable=too-many-arguments
Expand Down Expand Up @@ -80,7 +80,7 @@ def run_relax_w(
del vpr_args["write_rr_graph"]

if vpr_exec is None:
vpr_exec = find_vtr_file("vpr", is_executable=True)
vpr_exec = str(paths.vpr_exe_path)

run(
architecture,
Expand Down Expand Up @@ -172,7 +172,7 @@ def run(
temp_dir.mkdir(parents=True, exist_ok=True)

if vpr_exec is None:
vpr_exec = find_vtr_file("vpr", is_executable=True)
vpr_exec = str(paths.vpr_exe_path)

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

environ["LSAN_OPTIONS"] = "suppressions={} exitcode=23 fast_unwind_on_malloc=0".format(
find_vtr_file("lsan.supp")
str(paths.lsan_supp)
)

command_runner.run_system_command(
Expand Down
4 changes: 2 additions & 2 deletions vtr_flow/scripts/run_vtr_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ def vtr_command_main(arg_list, prog=None):
check_incremental_sta_consistency=args.check_incremental_sta_consistency,
use_old_abc_script=args.use_old_abc_script,
relax_w_factor=args.relax_w_factor,
check_route = args.check_route,
check_place = args.check_place,
check_route=args.check_route,
check_place=args.check_place,
)
error_status = "OK"
except vtr.VtrError as error:
Expand Down