diff --git a/vtr_flow/scripts/python_libs/vtr/__init__.py b/vtr_flow/scripts/python_libs/vtr/__init__.py index 92e661d2b48..e83c8966f08 100644 --- a/vtr_flow/scripts/python_libs/vtr/__init__.py +++ b/vtr_flow/scripts/python_libs/vtr/__init__.py @@ -3,7 +3,6 @@ """ from .util import ( load_config_lines, - find_vtr_file, CommandRunner, print_verbose, relax_w, @@ -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, diff --git a/vtr_flow/scripts/python_libs/vtr/abc/abc.py b/vtr_flow/scripts/python_libs/vtr/abc/abc.py index 777b7ae952f..976979081cd 100644 --- a/vtr_flow/scripts/python_libs/vtr/abc/abc.py +++ b/vtr_flow/scripts/python_libs/vtr/abc/abc.py @@ -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 @@ -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 @@ -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")) @@ -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( [ @@ -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) diff --git a/vtr_flow/scripts/python_libs/vtr/ace/ace.py b/vtr_flow/scripts/python_libs/vtr/ace/ace.py index cb3a075779b..7c5a274dc7e 100644 --- a/vtr_flow/scripts/python_libs/vtr/ace/ace.py +++ b/vtr_flow/scripts/python_libs/vtr/ace/ace.py @@ -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( @@ -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 ) @@ -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( diff --git a/vtr_flow/scripts/python_libs/vtr/flow.py b/vtr_flow/scripts/python_libs/vtr/flow.py index 89bf389a445..11f02827c9c 100644 --- a/vtr_flow/scripts/python_libs/vtr/flow.py +++ b/vtr_flow/scripts/python_libs/vtr/flow.py @@ -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 @@ -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( diff --git a/vtr_flow/scripts/python_libs/vtr/odin/odin.py b/vtr_flow/scripts/python_libs/vtr/odin/odin.py index 68c058e60e2..7698e5334f4 100644 --- a/vtr_flow/scripts/python_libs/vtr/odin/odin.py +++ b/vtr_flow/scripts/python_libs/vtr/odin/odin.py @@ -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( @@ -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" diff --git a/vtr_flow/scripts/python_libs/vtr/paths.py b/vtr_flow/scripts/python_libs/vtr/paths.py new file mode 100644 index 00000000000..77cf979f103 --- /dev/null +++ b/vtr_flow/scripts/python_libs/vtr/paths.py @@ -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" diff --git a/vtr_flow/scripts/python_libs/vtr/util.py b/vtr_flow/scripts/python_libs/vtr/util.py index d43c9a9987e..67f884db994 100644 --- a/vtr_flow/scripts/python_libs/vtr/util.py +++ b/vtr_flow/scripts/python_libs/vtr/util.py @@ -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) @@ -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", @@ -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_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. @@ -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: diff --git a/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py b/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py index bea9f009ac0..ba2c0f46ee6 100644 --- a/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py +++ b/vtr_flow/scripts/python_libs/vtr/vpr/vpr.py @@ -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 @@ -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, @@ -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") @@ -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( diff --git a/vtr_flow/scripts/run_vtr_flow.py b/vtr_flow/scripts/run_vtr_flow.py index 678d86bbfae..d8265967060 100755 --- a/vtr_flow/scripts/run_vtr_flow.py +++ b/vtr_flow/scripts/run_vtr_flow.py @@ -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: