OpenRAM/compiler/modules/sram.py

201 lines
8.1 KiB
Python
Raw Normal View History

# See LICENSE for licensing information.
#
2021-01-22 20:23:28 +01:00
# Copyright (c) 2016-2021 Regents of the University of California and The Board
2019-06-14 17:43:41 +02:00
# of Regents for the Oklahoma Agricultural and Mechanical College
# (acting for and on behalf of Oklahoma State University)
# All rights reserved.
#
import datetime
import os
2016-11-08 18:57:35 +01:00
import debug
from characterizer import functional
from base import timing_graph
2018-02-08 21:47:19 +01:00
from globals import OPTS, print_time
2021-06-23 01:13:33 +02:00
import shutil
2020-03-06 01:20:21 +01:00
class sram():
2016-11-08 18:57:35 +01:00
"""
This is not a design module, but contains an SRAM design instance.
It could later try options of number of banks and oganization to compare
results.
We can later add visualizer and other high-level functions as needed.
2016-11-08 18:57:35 +01:00
"""
def __init__(self, name, sram_config):
self.name = name
self.config = sram_config
2022-03-02 00:12:03 +01:00
sram_config.setup_multiport_constants()
sram_config.set_local_config(self)
2021-06-23 01:13:33 +02:00
self.sp_name = OPTS.output_path + self.name + ".sp"
self.lvs_name = OPTS.output_path + self.name + ".lvs.sp"
self.pex_name = OPTS.output_path + self.name + ".pex.sp"
self.gds_name = OPTS.output_path + self.name + ".gds"
self.lef_name = OPTS.output_path + self.name + ".lef"
self.v_name = OPTS.output_path + self.name + ".v"
# reset the static duplicate name checker for unit tests
# in case we create more than one SRAM
from base import design
design.name_map=[]
2016-11-08 18:57:35 +01:00
self.create()
def create(self):
2020-03-06 01:20:21 +01:00
debug.info(2, "create sram of size {0} with {1} num of words {2} banks".format(self.word_size,
self.num_words,
self.num_banks))
start_time = datetime.datetime.now()
2016-11-08 18:57:35 +01:00
if self.num_banks == 1:
from .sram_1bank import sram_1bank as sram
elif self.num_banks == 2:
from .sram_2bank import sram_2bank as sram
else:
2020-03-06 01:20:21 +01:00
debug.error("Invalid number of banks.", -1)
self.s = sram(name=self.name,
sram_config=self.config)
self.s.create_netlist()
if not OPTS.netlist_only:
self.s.create_layout()
2020-11-03 15:29:17 +01:00
if not OPTS.is_unit_test:
print_time("SRAM creation", datetime.datetime.now(), start_time)
2020-11-03 15:29:17 +01:00
def get_sp_name(self):
if OPTS.use_pex:
# Use the extracted spice file
return self.pex_name
else:
# Use generated spice file for characterization
return self.sp_name
def sp_write(self, name, lvs=False, trim=False):
self.s.sp_write(name, lvs, trim)
2020-11-03 15:29:17 +01:00
2020-03-06 01:20:21 +01:00
def lef_write(self, name):
self.s.lef_write(name)
2020-03-06 01:20:21 +01:00
def gds_write(self, name):
self.s.gds_write(name)
2016-11-08 18:57:35 +01:00
2020-03-06 01:20:21 +01:00
def verilog_write(self, name):
self.s.verilog_write(name)
def extended_config_write(self, name):
2020-11-03 15:29:17 +01:00
"""Dump config file with all options.
Include defaults and anything changed by input config."""
f = open(name, "w")
var_dict = dict((name, getattr(OPTS, name)) for name in dir(OPTS) if not name.startswith('__') and not callable(getattr(OPTS, name)))
for var_name, var_value in var_dict.items():
if isinstance(var_value, str):
f.write(str(var_name) + " = " + "\"" + str(var_value) + "\"\n")
else:
f.write(str(var_name) + " = " + str(var_value)+ "\n")
f.close()
2020-11-03 15:29:17 +01:00
def save(self):
2018-02-08 21:47:19 +01:00
""" Save all the output files while reporting time to do it as well. """
2022-07-22 18:52:38 +02:00
# Import this at the last minute so that the proper tech file
# is loaded and the right tools are selected
import verify
# Save the spice file
start_time = datetime.datetime.now()
debug.print_raw("SP: Writing to {0}".format(self.sp_name))
self.sp_write(self.sp_name)
2022-03-02 00:12:03 +01:00
# Save a functional simulation file with default period
functional(self.s,
os.path.basename(self.sp_name),
2021-06-23 01:13:33 +02:00
cycles=200,
output_path=OPTS.output_path)
print_time("Spice writing", datetime.datetime.now(), start_time)
if not OPTS.netlist_only:
# Write the layout
start_time = datetime.datetime.now()
debug.print_raw("GDS: Writing to {0}".format(self.gds_name))
self.gds_write(self.gds_name)
if OPTS.check_lvsdrc:
verify.write_drc_script(cell_name=self.s.name,
gds_name=os.path.basename(self.gds_name),
extract=True,
final_verification=True,
output_path=OPTS.output_path)
print_time("GDS", datetime.datetime.now(), start_time)
2020-10-07 01:27:02 +02:00
# Create a LEF physical model
start_time = datetime.datetime.now()
debug.print_raw("LEF: Writing to {0}".format(self.lef_name))
self.lef_write(self.lef_name)
2020-10-07 01:27:02 +02:00
print_time("LEF", datetime.datetime.now(), start_time)
# Save the LVS file
start_time = datetime.datetime.now()
debug.print_raw("LVS: Writing to {0}".format(self.lvs_name))
self.sp_write(self.lvs_name, lvs=True)
if not OPTS.netlist_only and OPTS.check_lvsdrc:
verify.write_lvs_script(cell_name=self.s.name,
gds_name=os.path.basename(self.gds_name),
sp_name=os.path.basename(self.lvs_name),
final_verification=True,
output_path=OPTS.output_path)
print_time("LVS writing", datetime.datetime.now(), start_time)
2020-11-03 15:29:17 +01:00
# Save the extracted spice file
2018-02-08 21:47:19 +01:00
if OPTS.use_pex:
start_time = datetime.datetime.now()
# Output the extracted design if requested
verify.run_pex(self.s.name, self.gds_name, self.sp_name, output=self.pex_name)
print_time("Extraction", datetime.datetime.now(), start_time)
2018-02-08 21:47:19 +01:00
# Characterize the design
start_time = datetime.datetime.now()
2018-02-08 21:47:19 +01:00
from characterizer import lib
2019-01-13 23:34:46 +01:00
debug.print_raw("LIB: Characterizing... ")
lib(out_dir=OPTS.output_path, sram=self.s, sp_file=self.get_sp_name())
print_time("Characterization", datetime.datetime.now(), start_time)
# Write the config file
start_time = datetime.datetime.now()
from shutil import copyfile
2019-11-16 23:22:30 +01:00
copyfile(OPTS.config_file, OPTS.output_path + OPTS.output_name + '.py')
2019-01-13 23:34:46 +01:00
debug.print_raw("Config: Writing to {0}".format(OPTS.output_path + OPTS.output_name + '.py'))
print_time("Config", datetime.datetime.now(), start_time)
# Write the datasheet
start_time = datetime.datetime.now()
from datasheet import datasheet_gen
dname = OPTS.output_path + self.s.name + ".html"
2019-01-13 23:34:46 +01:00
debug.print_raw("Datasheet: Writing to {0}".format(dname))
2021-06-16 21:36:00 +02:00
datasheet_gen.datasheet_write(dname)
print_time("Datasheet", datetime.datetime.now(), start_time)
2018-02-08 21:47:19 +01:00
# Write a verilog model
start_time = datetime.datetime.now()
debug.print_raw("Verilog: Writing to {0}".format(self.v_name))
self.verilog_write(self.v_name)
print_time("Verilog", datetime.datetime.now(), start_time)
# Write out options if specified
if OPTS.output_extended_config:
start_time = datetime.datetime.now()
oname = OPTS.output_path + OPTS.output_name + "_extended.py"
debug.print_raw("Extended Config: Writing to {0}".format(oname))
self.extended_config_write(oname)
print_time("Extended Config", datetime.datetime.now(), start_time)
# Write the graph if specified
if OPTS.write_graph:
start_time = datetime.datetime.now()
oname = OPTS.output_path + OPTS.output_name + "_graph.json"
debug.print_raw("Graph: Writing to {0}".format(oname))
graph = timing_graph()
self.s.build_graph(graph, self.name, self.s.pins)
graph.write(oname)
print_time("Graph", datetime.datetime.now(), start_time)