diff --git a/plot-3d-slack.py b/plot-3d-slack.py index bad2dc9..83226fa 100755 --- a/plot-3d-slack.py +++ b/plot-3d-slack.py @@ -3,6 +3,7 @@ import numpy as np from scipy.interpolate import griddata import sys +import yaml def load_data(filename): @@ -11,20 +12,34 @@ def load_data(filename): slack = [] with open(filename, "r") as file: - for line in file: - parts = line.split() - if len(parts) == 5: - s = float(parts[2]) - slack.append(s * pow(10, 12)) - x.append(float(parts[3])) - y.append(float(parts[4])) + data = yaml.load(file, Loader=yaml.FullLoader) - return np.array(x), np.array(y), np.array(slack) + for line in data["stats"]: + parts = line.split() + if len(parts) == 5: + s = float(parts[2]) + slack.append(s * pow(10, 12)) + x.append(float(parts[3])) + y.append(float(parts[4])) + macros = {} -def plot_3d(x, y, z): + for line in data["masters"]: + parts = line.split() + if len(parts) == 5: + macros[parts[0]] = { + "minx": float(parts[1]), + "miny": float(parts[2]), + "maxx": float(parts[3]), + "maxy": float(parts[4]), + } + + return np.array(x), np.array(y), np.array(slack), macros + + +def plot_3d(x, y, z, macros): # Create grid data for surface plot - grid_x, grid_y = np.mgrid[0: 2000: 100j, 0: 2000: 100j] + grid_x, grid_y = np.mgrid[0:2000:100j, 0:2000:100j] grid_z = griddata((x, y), z, (grid_x, grid_y), method="linear") fig = plt.figure() @@ -36,10 +51,32 @@ def plot_3d(x, y, z): ax.set_zlabel("Skew") fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5) + for macro in macros: + minx = macros[macro]["minx"] + miny = macros[macro]["miny"] + maxx = macros[macro]["maxx"] + maxy = macros[macro]["maxy"] + + # Plot a solid rectangle + ax.bar3d(minx, miny, 0, maxx - minx, maxy - miny, 50, color="red", alpha=0.5) + + # # Add title text on the flat surface of the box + # ax.text( + # (minx + maxx) / 2, # x-coordinate of the text + # (miny + maxy) / 2, # y-coordinate of the text + # 0.5, # z-coordinate of the text (middle of the box height) + # macro, # text to display + # color='black', # text color + # ha='center', # horizontal alignment + # va='center', # vertical alignment + # fontsize=12, # font size + # bbox=dict(facecolor='white', alpha=0.5, edgecolor='none') # background box + # ) + plt.show() if __name__ == "__main__": filename = sys.argv[1] - x, y, z = load_data(filename) - plot_3d(x, y, z) + x, y, z, macros = load_data(filename) + plot_3d(x, y, z, macros) diff --git a/slack-positions.tcl b/slack-positions.tcl index 025426a..6d11eee 100644 --- a/slack-positions.tcl +++ b/slack-positions.tcl @@ -1,3 +1,5 @@ +# To test from ~/OpenROAD-flow-scripts, run: +# make RUN_SCRIPT=~/megaboom/slack-positions.tcl ODB_FILE=results/nangate45/gcd/base/4_cts.odb run OUTPUT=xxx.txt source $::env(SCRIPTS_DIR)/open.tcl set paths [find_timing_paths -path_group reg2reg -sort_by_slack -group_count 1000000] @@ -6,6 +8,7 @@ set db [::ord::get_db] set block [[$db getChip] getBlock] set fp [open $::env(OUTPUT) w] +puts $fp "stats:" foreach path $paths { set endpoint [get_property $path endpoint] set instance [sta::sta_to_db_inst [$endpoint instance]] @@ -23,6 +26,15 @@ foreach path $paths { set slack [get_property $path slack] set skew [$path clk_skew] set bbox [$obj getBBox] - puts $fp "$name $slack $skew [ord::dbu_to_microns [$bbox xMin]] [ord::dbu_to_microns [$bbox yMin]]" + puts $fp " - $name $slack $skew [ord::dbu_to_microns [$bbox xMin]] [ord::dbu_to_microns [$bbox yMin]]" } + +puts $fp "masters:" +foreach master [$block getInsts] { + if {[$master isBlock]} { + set bbox [$master getBBox] + puts $fp " - [$master getName] [ord::dbu_to_microns [$bbox xMin]] [ord::dbu_to_microns [$bbox yMin]] [ord::dbu_to_microns [$bbox xMax]] [ord::dbu_to_microns [$bbox yMax]]" + } +} + close $fp