Cleanup globals.py

This commit is contained in:
Eren Dogan 2023-05-04 20:47:53 -07:00
parent 420ce01b46
commit f2235c2457
1 changed files with 27 additions and 40 deletions

View File

@ -31,26 +31,23 @@ OPTS = options.options()
def parse_args(): def parse_args():
""" Parse the optional arguments for OpenRAM """ """ Parse the optional arguments for OpenRAM. """
global OPTS global OPTS
option_list = { option_list = {
optparse.make_option("-b", optparse.make_option("-b", "--backannotated",
"--backannotated",
action="store_true", action="store_true",
dest="use_pex", dest="use_pex",
help="Back annotate simulation"), help="Back annotate simulation"),
optparse.make_option("-o", optparse.make_option("-o", "--output",
"--output",
dest="output_name", dest="output_name",
help="Base output file name(s) prefix", help="Base output file name(s) prefix",
metavar="FILE"), metavar="FILE"),
optparse.make_option("-p", "--outpath", optparse.make_option("-p", "--outpath",
dest="output_path", dest="output_path",
help="Output file(s) location"), help="Output file(s) location"),
optparse.make_option("-i", optparse.make_option("-i", "--inlinecheck",
"--inlinecheck",
action="store_true", action="store_true",
help="Enable inline LVS/DRC checks", help="Enable inline LVS/DRC checks",
dest="inline_lvsdrc"), dest="inline_lvsdrc"),
@ -68,36 +65,29 @@ def parse_args():
type="int", type="int",
help="Specify the number of spice simulation threads (default: 3)", help="Specify the number of spice simulation threads (default: 3)",
dest="num_sim_threads"), dest="num_sim_threads"),
optparse.make_option("-v", optparse.make_option("-v", "--verbose",
"--verbose",
action="count", action="count",
dest="verbose_level", dest="verbose_level",
help="Increase the verbosity level"), help="Increase the verbosity level"),
optparse.make_option("-t", optparse.make_option("-t", "--tech",
"--tech",
dest="tech_name", dest="tech_name",
help="Technology name"), help="Technology name"),
optparse.make_option("-s", optparse.make_option("-s", "--spice",
"--spice",
dest="spice_name", dest="spice_name",
help="Spice simulator executable name"), help="Spice simulator executable name"),
optparse.make_option("-r", optparse.make_option("-r", "--remove_netlist_trimming",
"--remove_netlist_trimming",
action="store_false", action="store_false",
dest="trim_netlist", dest="trim_netlist",
help="Disable removal of noncritical memory cells during characterization"), help="Disable removal of noncritical memory cells during characterization"),
optparse.make_option("-c", optparse.make_option("-c", "--characterize",
"--characterize",
action="store_false", action="store_false",
dest="analytical_delay", dest="analytical_delay",
help="Perform characterization to calculate delays (default is analytical models)"), help="Perform characterization to calculate delays (default is analytical models)"),
optparse.make_option("-k", optparse.make_option("-k", "--keeptemp",
"--keeptemp",
action="store_true", action="store_true",
dest="keep_temp", dest="keep_temp",
help="Keep the contents of the temp directory after a successful run"), help="Keep the contents of the temp directory after a successful run"),
optparse.make_option("-d", optparse.make_option("-d", "--debug",
"--debug",
action="store_true", action="store_true",
dest="debug", dest="debug",
help="Run in debug mode to drop to pdb on failure") help="Run in debug mode to drop to pdb on failure")
@ -125,7 +115,7 @@ def parse_args():
def print_banner(): def print_banner():
""" Conditionally print the banner to stdout """ """ Conditionally print the banner to stdout. """
global OPTS global OPTS
if OPTS.is_unit_test: if OPTS.is_unit_test:
return return
@ -160,8 +150,7 @@ def check_versions():
try: try:
subprocess.check_output(["git", "--version"]) subprocess.check_output(["git", "--version"])
except: except:
debug.error("Git is required. Please install git.") debug.error("Git is required. Please install git.", -1)
sys.exit(1)
# FIXME: Check versions of other tools here?? # FIXME: Check versions of other tools here??
# or, this could be done in each module (e.g. verify, characterizer, etc.) # or, this could be done in each module (e.g. verify, characterizer, etc.)
@ -280,18 +269,17 @@ def get_tool(tool_type, preferences, default_name=None):
2) 2)
else: else:
debug.info(1, "Using {0}: {1}".format(tool_type, exe_name)) debug.info(1, "Using {0}: {1}".format(tool_type, exe_name))
return(default_name, exe_name) return (default_name, exe_name)
else: else:
for name in preferences: for name in preferences:
exe_name = find_exe(name) exe_name = find_exe(name)
if exe_name != None: if exe_name != None:
debug.info(1, "Using {0}: {1}".format(tool_type, exe_name)) debug.info(1, "Using {0}: {1}".format(tool_type, exe_name))
return(name, exe_name) return (name, exe_name)
else: else:
debug.info(1, debug.info(1, "Could not find {0}, trying next {1} tool.".format(name, tool_type))
"Could not find {0}, trying next {1} tool.".format(name, tool_type))
else: else:
return(None, "") return (None, "")
def read_config(config_file, is_unit_test=False): def read_config(config_file, is_unit_test=False):
@ -381,7 +369,7 @@ def read_config(config_file, is_unit_test=False):
def end_openram(): def end_openram():
""" Clean up openram for a proper exit """ """ Clean up openram for a proper exit. """
cleanup_paths() cleanup_paths()
if OPTS.check_lvsdrc: if OPTS.check_lvsdrc:
@ -393,8 +381,7 @@ def end_openram():
def purge_temp(): def purge_temp():
""" Remove the temp directory. """ """ Remove the temp directory. """
debug.info(1, debug.info(1, "Purging temp directory: {}".format(OPTS.openram_temp))
"Purging temp directory: {}".format(OPTS.openram_temp))
#import inspect #import inspect
#s = inspect.stack() #s = inspect.stack()
#print("Purge {0} in dir {1}".format(s[3].filename, OPTS.openram_temp)) #print("Purge {0} in dir {1}".format(s[3].filename, OPTS.openram_temp))
@ -416,8 +403,7 @@ def cleanup_paths():
""" """
global OPTS global OPTS
if OPTS.keep_temp: if OPTS.keep_temp:
debug.info(0, debug.info(0, "Preserving temp directory: {}".format(OPTS.openram_temp))
"Preserving temp directory: {}".format(OPTS.openram_temp))
return return
elif os.path.exists(OPTS.openram_temp): elif os.path.exists(OPTS.openram_temp):
purge_temp() purge_temp()
@ -434,7 +420,6 @@ def setup_paths():
# Use a unique temp subdirectory if multithreaded # Use a unique temp subdirectory if multithreaded
if OPTS.num_threads > 1 or OPTS.openram_temp == "/tmp": if OPTS.num_threads > 1 or OPTS.openram_temp == "/tmp":
# Make a unique subdir # Make a unique subdir
tempdir = "/openram_{0}_{1}_temp".format(getpass.getuser(), tempdir = "/openram_{0}_{1}_temp".format(getpass.getuser(),
os.getpid()) os.getpid())
@ -449,14 +434,15 @@ def setup_paths():
def is_exe(fpath): def is_exe(fpath):
""" Return true if the given is an executable file that exists. """ """ Return true if the given is an executable file that exists. """
return os.path.exists(fpath) and os.access(fpath, os.X_OK) return os.path.exists(fpath) and os.access(fpath, os.X_OK)
def find_exe(check_exe): def find_exe(check_exe):
""" """
Check if the binary exists in any path dir Check if the binary exists in any path dir and return the full path.
and return the full path.
""" """
# Search for conda setup if used # Search for conda setup if used
if OPTS.use_conda: if OPTS.use_conda:
from openram import CONDA_HOME from openram import CONDA_HOME
@ -465,6 +451,7 @@ def find_exe(check_exe):
os.environ["PATH"]) os.environ["PATH"])
else: else:
search_path = os.environ["PATH"] search_path = os.environ["PATH"]
# Check if the preferred spice option exists in the path # Check if the preferred spice option exists in the path
for path in search_path.split(os.pathsep): for path in search_path.split(os.pathsep):
exe = os.path.join(path, check_exe) exe = os.path.join(path, check_exe)
@ -574,7 +561,7 @@ def import_tech():
# Add all of the paths # Add all of the paths
for tech_path in OPENRAM_TECH.split(":"): for tech_path in OPENRAM_TECH.split(":"):
debug.check(os.path.isdir(tech_path), debug.check(os.path.isdir(tech_path),
"$OPENRAM_TECH does not exist: {0}".format(tech_path)) "$OPENRAM_TECH does not exist: {}".format(tech_path))
sys.path.append(tech_path) sys.path.append(tech_path)
debug.info(1, "Adding technology path: {}".format(tech_path)) debug.info(1, "Adding technology path: {}".format(tech_path))
@ -582,7 +569,7 @@ def import_tech():
try: try:
tech_mod = __import__(OPTS.tech_name) tech_mod = __import__(OPTS.tech_name)
except ImportError: except ImportError:
debug.error("Nonexistent technology module: {0}".format(OPTS.tech_name), -1) debug.error("Nonexistent technology module: {}".format(OPTS.tech_name), -1)
OPTS.openram_tech = os.path.dirname(tech_mod.__file__) + "/" OPTS.openram_tech = os.path.dirname(tech_mod.__file__) + "/"
@ -651,7 +638,7 @@ def report_status():
total_size = OPTS.word_size*OPTS.num_words*OPTS.num_banks total_size = OPTS.word_size*OPTS.num_words*OPTS.num_banks
debug.print_raw("Total size: {} bits".format(total_size)) debug.print_raw("Total size: {} bits".format(total_size))
if total_size >= 2**14 and not OPTS.analytical_delay: if total_size >= 2**14 and not OPTS.analytical_delay:
debug.warning("Characterizing large memories ({0}) will have a large run-time. ".format(total_size)) debug.warning("Characterizing large memories ({0}) will have a large run-time.".format(total_size))
debug.print_raw("Word size: {0}\nWords: {1}\nBanks: {2}".format(OPTS.word_size, debug.print_raw("Word size: {0}\nWords: {1}\nBanks: {2}".format(OPTS.word_size,
OPTS.num_words, OPTS.num_words,
OPTS.num_banks)) OPTS.num_banks))