mirror of
https://github.com/VLSIDA/OpenRAM.git
synced 2026-09-03 07:43:32 +02:00
Lots of PEP8 cleanup. Refactor path graph to simulation class.
This commit is contained in:
+22
-22
@@ -40,9 +40,9 @@ class timing_graph():
|
||||
"""Helper function to remove edges, useful for removing vdd/gnd"""
|
||||
|
||||
node = node.lower()
|
||||
self.graph[node] = set()
|
||||
self.graph[node] = set()
|
||||
|
||||
def get_all_paths(self, src_node, dest_node, remove_rail_nodes=True, reduce_paths=True):
|
||||
def get_all_paths(self, src_node, dest_node, remove_rail_nodes=True, reduce_paths=True):
|
||||
"""Traverse all paths from source to destination"""
|
||||
|
||||
src_node = src_node.lower()
|
||||
@@ -59,44 +59,44 @@ class timing_graph():
|
||||
visited = set()
|
||||
|
||||
# Create an array to store paths
|
||||
path = []
|
||||
path = []
|
||||
self.all_paths = []
|
||||
|
||||
# Call the recursive helper function to print all paths
|
||||
self.get_all_paths_util(src_node, dest_node, visited, path)
|
||||
self.get_all_paths_util(src_node, dest_node, visited, path)
|
||||
debug.info(2, "Paths found={}".format(len(self.all_paths)))
|
||||
|
||||
if reduce_paths:
|
||||
self.reduce_paths()
|
||||
|
||||
return self.all_paths
|
||||
return self.all_paths
|
||||
|
||||
def reduce_paths(self):
|
||||
""" Remove any path that is a subset of another path """
|
||||
|
||||
self.all_paths = [p1 for p1 in self.all_paths if not any(set(p1)<=set(p2) for p2 in self.all_paths if p1 is not p2)]
|
||||
|
||||
def get_all_paths_util(self, cur_node, dest_node, visited, path):
|
||||
def get_all_paths_util(self, cur_node, dest_node, visited, path):
|
||||
"""Recursive function to find all paths in a Depth First Search manner"""
|
||||
|
||||
# Mark the current node as visited and store in path
|
||||
visited.add(cur_node)
|
||||
path.append(cur_node)
|
||||
path.append(cur_node)
|
||||
|
||||
# If current vertex is same as destination, then print
|
||||
# current path[]
|
||||
if cur_node == dest_node:
|
||||
if cur_node == dest_node:
|
||||
self.all_paths.append(copy.deepcopy(path))
|
||||
else:
|
||||
else:
|
||||
# If current vertex is not destination
|
||||
# Recur for all the vertices adjacent to this vertex
|
||||
for node in self.graph[cur_node]:
|
||||
if node not in visited:
|
||||
self.get_all_paths_util(node, dest_node, visited, path)
|
||||
for node in self.graph[cur_node]:
|
||||
if node not in visited:
|
||||
self.get_all_paths_util(node, dest_node, visited, path)
|
||||
|
||||
# Remove current vertex from path[] and mark it as unvisited
|
||||
path.pop()
|
||||
visited.remove(cur_node)
|
||||
path.pop()
|
||||
visited.remove(cur_node)
|
||||
|
||||
def get_timing(self, path, corner, slew, load):
|
||||
"""Returns the analytical delays in the input path"""
|
||||
@@ -106,20 +106,20 @@ class timing_graph():
|
||||
|
||||
delays = []
|
||||
cur_slew = slew
|
||||
for i in range(len(path)-1):
|
||||
for i in range(len(path) - 1):
|
||||
|
||||
path_edge_mod = self.edge_mods[(path[i], path[i+1])]
|
||||
path_edge_mod = self.edge_mods[(path[i], path[i + 1])]
|
||||
|
||||
# On the output of the current stage, get COUT from all other mods connected
|
||||
cout = 0
|
||||
for node in self.graph[path[i+1]]:
|
||||
output_edge_mod = self.edge_mods[(path[i+1], node)]
|
||||
for node in self.graph[path[i + 1]]:
|
||||
output_edge_mod = self.edge_mods[(path[i + 1], node)]
|
||||
cout+=output_edge_mod.get_cin()
|
||||
# If at the last output, include the final output load
|
||||
if i == len(path)-2:
|
||||
cout+=load
|
||||
if i == len(path) - 2:
|
||||
cout += load
|
||||
|
||||
delays.append(path_edge_mod.analytical_delay(corner, slew, cout))
|
||||
delays.append(path_edge_mod.analytical_delay(corner, slew, cout))
|
||||
cur_slew = delays[-1].slew
|
||||
|
||||
return delays
|
||||
@@ -127,4 +127,4 @@ class timing_graph():
|
||||
def __str__(self):
|
||||
""" override print function output """
|
||||
|
||||
return "Nodes: {}\nEdges:{} ".format(list(self.graph), self.graph)
|
||||
return "Nodes: {}\nEdges:{} ".format(list(self.graph), self.graph)
|
||||
|
||||
@@ -12,6 +12,7 @@ import os
|
||||
from globals import OPTS
|
||||
import tech
|
||||
|
||||
|
||||
class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
|
||||
"""
|
||||
Design Class for all modules to inherit the base features.
|
||||
@@ -137,12 +138,16 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
|
||||
os.remove(tempgds)
|
||||
|
||||
def init_graph_params(self):
|
||||
"""Initializes parameters relevant to the graph creation"""
|
||||
"""
|
||||
Initializes parameters relevant to the graph creation
|
||||
"""
|
||||
# Only initializes a set for checking instances which should not be added
|
||||
self.graph_inst_exclude = set()
|
||||
|
||||
def build_graph(self, graph, inst_name, port_nets):
|
||||
"""Recursively create graph from instances in module."""
|
||||
"""
|
||||
Recursively create graph from instances in module.
|
||||
"""
|
||||
|
||||
# Translate port names to external nets
|
||||
if len(port_nets) != len(self.pins):
|
||||
@@ -159,7 +164,9 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
|
||||
subinst.mod.build_graph(graph, subinst_name, subinst_ports)
|
||||
|
||||
def build_names(self, name_dict, inst_name, port_nets):
|
||||
"""Collects all the nets and the parent inst of that net."""
|
||||
"""
|
||||
Collects all the nets and the parent inst of that net.
|
||||
"""
|
||||
# Translate port names to external nets
|
||||
if len(port_nets) != len(self.pins):
|
||||
debug.error("Port length mismatch:\nExt nets={}, Ports={}".format(port_nets,
|
||||
@@ -178,7 +185,9 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
|
||||
subinst.mod.build_names(name_dict, subinst_name, subinst_ports)
|
||||
|
||||
def translate_nets(self, subinst_ports, port_dict, inst_name):
|
||||
"""Converts connection names to their spice hierarchy equivalent"""
|
||||
"""
|
||||
Converts connection names to their spice hierarchy equivalent
|
||||
"""
|
||||
converted_conns = []
|
||||
for conn in subinst_ports:
|
||||
if conn in port_dict:
|
||||
@@ -188,8 +197,10 @@ class hierarchy_design(hierarchy_spice.spice, hierarchy_layout.layout):
|
||||
return converted_conns
|
||||
|
||||
def add_graph_edges(self, graph, port_nets):
|
||||
"""For every input, adds an edge to every output.
|
||||
Only intended to be used for gates and other simple modules."""
|
||||
"""
|
||||
For every input, adds an edge to every output.
|
||||
Only intended to be used for gates and other simple modules.
|
||||
"""
|
||||
# The final pin names will depend on the spice hierarchy, so
|
||||
# they are passed as an input.
|
||||
pin_dict = {pin: port for pin, port in zip(self.pins, port_nets)}
|
||||
|
||||
@@ -500,8 +500,9 @@ class spice():
|
||||
return power_data(dynamic, leakage)
|
||||
|
||||
def find_aliases(self, inst_name, port_nets, path_nets, alias, alias_mod, exclusion_set=None):
|
||||
"""Given a list of nets, will compare the internal alias of a mod to determine
|
||||
if the nets have a connection to this mod's net (but not inst).
|
||||
"""
|
||||
Given a list of nets, will compare the internal alias of a mod to determine
|
||||
if the nets have a connection to this mod's net (but not inst).
|
||||
"""
|
||||
if not exclusion_set:
|
||||
exclusion_set = set()
|
||||
@@ -520,7 +521,9 @@ class spice():
|
||||
return aliases
|
||||
|
||||
def is_net_alias(self, known_net, net_alias, mod, exclusion_set):
|
||||
"""Checks if the alias_net in input mod is the same as the input net for this mod (self)."""
|
||||
"""
|
||||
Checks if the alias_net in input mod is the same as the input net for this mod (self).
|
||||
"""
|
||||
if self in exclusion_set:
|
||||
return False
|
||||
# Check ports of this mod
|
||||
@@ -540,7 +543,9 @@ class spice():
|
||||
return False
|
||||
|
||||
def is_net_alias_name_check(self, parent_net, child_net, alias_net, mod):
|
||||
"""Utility function for checking single net alias."""
|
||||
"""
|
||||
Utility function for checking single net alias.
|
||||
"""
|
||||
return self == mod and \
|
||||
child_net.lower() == alias_net.lower() and \
|
||||
parent_net.lower() == alias_net.lower()
|
||||
|
||||
Reference in New Issue
Block a user