2022-05-17 18:29:38 +00:00
|
|
|
#!/usr/bin/python3
|
2022-05-21 09:53:26 +00:00
|
|
|
# Madeleine Masser-Frye mmasserfrye@hmc.edu 5/22
|
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
from operator import index
|
2022-05-17 18:29:38 +00:00
|
|
|
import subprocess
|
|
|
|
import csv
|
|
|
|
import re
|
2022-05-27 20:59:23 +00:00
|
|
|
from matplotlib.cbook import flatten
|
2022-05-17 18:29:38 +00:00
|
|
|
import matplotlib.pyplot as plt
|
2022-05-18 16:08:40 +00:00
|
|
|
import matplotlib.lines as lines
|
2022-05-26 22:24:39 +00:00
|
|
|
import matplotlib.axes as axes
|
2022-05-17 18:29:38 +00:00
|
|
|
import numpy as np
|
2022-05-25 20:37:54 +00:00
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
|
|
|
|
def synthsfromcsv(filename):
|
2022-05-28 04:57:18 +00:00
|
|
|
Synth = namedtuple("Synth", "module tech width freq delay area lpower denergy")
|
2022-05-25 20:37:54 +00:00
|
|
|
with open(filename, newline='') as csvfile:
|
|
|
|
csvreader = csv.reader(csvfile)
|
|
|
|
global allSynths
|
|
|
|
allSynths = list(csvreader)
|
|
|
|
for i in range(len(allSynths)):
|
|
|
|
for j in range(len(allSynths[0])):
|
|
|
|
try: allSynths[i][j] = int(allSynths[i][j])
|
|
|
|
except:
|
|
|
|
try: allSynths[i][j] = float(allSynths[i][j])
|
|
|
|
except: pass
|
|
|
|
allSynths[i] = Synth(*allSynths[i])
|
|
|
|
|
2022-05-26 20:51:00 +00:00
|
|
|
def synthsintocsv():
|
2022-05-25 20:37:54 +00:00
|
|
|
''' writes a CSV with one line for every available synthesis
|
|
|
|
each line contains the module, tech, width, target freq, and resulting metrics
|
2022-05-25 13:52:20 +00:00
|
|
|
'''
|
2022-05-27 20:59:23 +00:00
|
|
|
print("This takes a moment...")
|
2022-05-26 20:51:00 +00:00
|
|
|
bashCommand = "find . -path '*runs/ppa*rv32e*' -prune"
|
|
|
|
output = subprocess.check_output(['bash','-c', bashCommand])
|
|
|
|
allSynths = output.decode("utf-8").split('\n')[:-1]
|
|
|
|
|
|
|
|
specReg = re.compile('[a-zA-Z0-9]+')
|
|
|
|
metricReg = re.compile('\d+\.\d+[e]?[-+]?\d*')
|
2022-05-25 20:37:54 +00:00
|
|
|
|
|
|
|
file = open("ppaData.csv", "w")
|
|
|
|
writer = csv.writer(file)
|
|
|
|
writer.writerow(['Module', 'Tech', 'Width', 'Target Freq', 'Delay', 'Area', 'L Power (nW)', 'D energy (mJ)'])
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-26 20:51:00 +00:00
|
|
|
for oneSynth in allSynths:
|
|
|
|
module, width, risc, tech, freq = specReg.findall(oneSynth)[2:7]
|
|
|
|
tech = tech[:-2]
|
|
|
|
metrics = []
|
|
|
|
for phrase in [['Path Length', 'qor'], ['Design Area', 'qor'], ['100', 'power']]:
|
|
|
|
bashCommand = 'grep "{}" '+ oneSynth[2:]+'/reports/*{}*'
|
|
|
|
bashCommand = bashCommand.format(*phrase)
|
|
|
|
try: output = subprocess.check_output(['bash','-c', bashCommand])
|
|
|
|
except: print("At least one synth run doesn't have reports, try cleanup() first")
|
|
|
|
nums = metricReg.findall(str(output))
|
|
|
|
nums = [float(m) for m in nums]
|
|
|
|
metrics += nums
|
|
|
|
delay = metrics[0]
|
|
|
|
area = metrics[1]
|
|
|
|
lpower = metrics[4]
|
|
|
|
denergy = (metrics[2] + metrics[3])*delay # (switching + internal powers)*delay
|
|
|
|
|
|
|
|
writer.writerow([module, tech, width, freq, delay, area, lpower, denergy])
|
2022-05-25 20:37:54 +00:00
|
|
|
file.close()
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-26 20:51:00 +00:00
|
|
|
def cleanup():
|
|
|
|
''' removes runs that didn't work
|
|
|
|
'''
|
|
|
|
bashCommand = 'grep -r "Error" runs/ppa*/reports/*qor*'
|
|
|
|
try:
|
|
|
|
output = subprocess.check_output(['bash','-c', bashCommand])
|
|
|
|
allSynths = output.decode("utf-8").split('\n')[:-1]
|
|
|
|
for run in allSynths:
|
|
|
|
run = run.split('MHz')[0]
|
|
|
|
bc = 'rm -r '+ run + '*'
|
|
|
|
output = subprocess.check_output(['bash','-c', bc])
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
bashCommand = "find . -path '*runs/ppa*rv32e*' -prune"
|
|
|
|
output = subprocess.check_output(['bash','-c', bashCommand])
|
|
|
|
allSynths = output.decode("utf-8").split('\n')[:-1]
|
|
|
|
for oneSynth in allSynths:
|
|
|
|
for phrase in [['Path Length', 'qor'], ['Design Area', 'qor'], ['100', 'power']]:
|
|
|
|
bashCommand = 'grep "{}" '+ oneSynth[2:]+'/reports/*{}*'
|
|
|
|
bashCommand = bashCommand.format(*phrase)
|
|
|
|
try: output = subprocess.check_output(['bash','-c', bashCommand])
|
|
|
|
except:
|
|
|
|
bc = 'rm -r '+ oneSynth[2:]
|
|
|
|
try: output = subprocess.check_output(['bash','-c', bc])
|
|
|
|
except: pass
|
|
|
|
print("All cleaned up!")
|
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
def getVals(tech, module, var, freq=None):
|
|
|
|
''' for a specified tech, module, and variable/metric
|
2022-05-28 04:57:18 +00:00
|
|
|
returns a list of values for that metric in ascending width order
|
2022-05-27 20:59:23 +00:00
|
|
|
works at a specified target frequency or if none is given, uses the synthesis with the best achievable delay for each width
|
2022-05-25 13:52:20 +00:00
|
|
|
'''
|
2022-05-18 16:08:40 +00:00
|
|
|
|
2022-05-25 20:37:54 +00:00
|
|
|
global widths
|
2022-05-19 20:24:47 +00:00
|
|
|
metric = []
|
2022-05-25 20:37:54 +00:00
|
|
|
widthL = []
|
2022-05-27 20:59:23 +00:00
|
|
|
|
2022-05-21 09:53:26 +00:00
|
|
|
if (freq != None):
|
|
|
|
for oneSynth in allSynths:
|
2022-05-25 20:37:54 +00:00
|
|
|
if (oneSynth.freq == freq) & (oneSynth.tech == tech) & (oneSynth.module == module):
|
|
|
|
widthL += [oneSynth.width]
|
|
|
|
osdict = oneSynth._asdict()
|
|
|
|
metric += [osdict[var]]
|
|
|
|
metric = [x for _, x in sorted(zip(widthL, metric))] # ordering
|
2022-05-21 09:53:26 +00:00
|
|
|
else:
|
|
|
|
for w in widths:
|
2022-05-25 20:37:54 +00:00
|
|
|
m = 100000 # large number to start
|
2022-05-21 09:53:26 +00:00
|
|
|
for oneSynth in allSynths:
|
2022-05-25 20:37:54 +00:00
|
|
|
if (oneSynth.width == w) & (oneSynth.tech == tech) & (oneSynth.module == module):
|
2022-05-27 20:59:23 +00:00
|
|
|
if (oneSynth.delay < m) & (1000/oneSynth.delay > oneSynth.freq):
|
2022-05-25 20:37:54 +00:00
|
|
|
m = oneSynth.delay
|
|
|
|
osdict = oneSynth._asdict()
|
|
|
|
met = osdict[var]
|
2022-05-26 20:51:00 +00:00
|
|
|
try: metric += [met]
|
|
|
|
except: pass
|
2022-05-25 06:44:22 +00:00
|
|
|
|
|
|
|
if ('flop' in module) & (var == 'area'):
|
|
|
|
metric = [m/2 for m in metric] # since two flops in each module
|
2022-05-27 20:59:23 +00:00
|
|
|
if (var == 'denergy'):
|
|
|
|
metric = [m*1000 for m in metric] # more practical units for regression coefs
|
2022-05-25 13:52:20 +00:00
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
return metric
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
def genLegend(fits, coefs, r2, spec):
|
2022-05-25 13:52:20 +00:00
|
|
|
''' generates a list of two legend elements
|
|
|
|
labels line with fit equation and dots with tech and r squared of the fit
|
|
|
|
'''
|
2022-05-19 20:24:47 +00:00
|
|
|
|
|
|
|
coefsr = [str(round(c, 3)) for c in coefs]
|
|
|
|
|
|
|
|
eq = ''
|
|
|
|
ind = 0
|
|
|
|
if 'c' in fits:
|
|
|
|
eq += coefsr[ind]
|
|
|
|
ind += 1
|
|
|
|
if 'l' in fits:
|
|
|
|
eq += " + " + coefsr[ind] + "*N"
|
|
|
|
ind += 1
|
|
|
|
if 's' in fits:
|
|
|
|
eq += " + " + coefsr[ind] + "*N^2"
|
|
|
|
ind += 1
|
|
|
|
if 'g' in fits:
|
|
|
|
eq += " + " + coefsr[ind] + "*log2(N)"
|
|
|
|
ind += 1
|
|
|
|
if 'n' in fits:
|
|
|
|
eq += " + " + coefsr[ind] + "*Nlog2(N)"
|
|
|
|
ind += 1
|
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
legend_elements = [lines.Line2D([0], [0], color=spec.color, label=eq),
|
|
|
|
lines.Line2D([0], [0], color=spec.color, ls='', marker=spec.shape, label=spec.tech +' $R^2$='+ str(round(r2, 4)))]
|
2022-05-19 20:24:47 +00:00
|
|
|
return legend_elements
|
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
def oneMetricPlot(module, var, freq=None, ax=None, fits='clsgn', norm=True):
|
2022-05-25 13:52:20 +00:00
|
|
|
''' module: string module name
|
|
|
|
freq: int freq (MHz)
|
|
|
|
var: string delay, area, lpower, or denergy
|
|
|
|
fits: constant, linear, square, log2, Nlog2
|
|
|
|
plots given variable vs width for all matching syntheses with regression
|
2022-05-17 18:29:38 +00:00
|
|
|
'''
|
2022-05-19 20:24:47 +00:00
|
|
|
|
|
|
|
if ax is None:
|
|
|
|
singlePlot = True
|
|
|
|
ax = plt.gca()
|
|
|
|
else:
|
|
|
|
singlePlot = False
|
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
fullLeg = []
|
2022-05-28 04:57:18 +00:00
|
|
|
global techSpecs
|
2022-05-25 20:37:54 +00:00
|
|
|
global widths
|
2022-05-27 20:59:23 +00:00
|
|
|
|
|
|
|
global norms
|
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
for spec in techSpecs:
|
|
|
|
metric = getVals(spec.tech, module, var, freq=freq)
|
|
|
|
|
|
|
|
if norm:
|
|
|
|
techdict = spec._asdict()
|
|
|
|
norm = techdict[var]
|
|
|
|
metric = [m/norm for m in metric] # comment out to not normalize
|
2022-05-27 20:59:23 +00:00
|
|
|
|
2022-05-25 20:37:54 +00:00
|
|
|
if len(metric) == 5:
|
2022-05-28 04:57:18 +00:00
|
|
|
xp, pred, leg = regress(widths, metric, spec, fits)
|
2022-05-25 20:37:54 +00:00
|
|
|
fullLeg += leg
|
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
ax.scatter(widths, metric, color=spec.color, marker=spec.shape)
|
|
|
|
ax.plot(xp, pred, color=spec.color)
|
2022-05-19 20:24:47 +00:00
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
ax.legend(handles=fullLeg)
|
2022-05-19 20:24:47 +00:00
|
|
|
|
|
|
|
ax.set_xticks(widths)
|
|
|
|
ax.set_xlabel("Width (bits)")
|
2022-05-27 20:59:23 +00:00
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
if norm:
|
|
|
|
ylabeldic = {"lpower": "Normalized Leakage Power", "denergy": "Normalized Dynamic Energy", "area": "INVx1 Areas", "delay": "FO4 Delays"}
|
|
|
|
else:
|
|
|
|
ylabeldic = {"lpower": "Leakage Power (nW)", "denergy": "Dynamic Energy (nJ-CHECK)", "area": "Area (sq microns)", "delay": "Delay (ns)"}
|
2022-05-27 20:59:23 +00:00
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
ax.set_ylabel(ylabeldic[var])
|
2022-05-19 20:24:47 +00:00
|
|
|
|
|
|
|
if singlePlot:
|
2022-05-27 20:59:23 +00:00
|
|
|
titleStr = " (target " + str(freq)+ "MHz)" if freq != None else " (best achievable delay)"
|
2022-05-25 20:37:54 +00:00
|
|
|
ax.set_title(module + titleStr)
|
2022-05-19 20:24:47 +00:00
|
|
|
plt.show()
|
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
def regress(widths, var, spec, fits='clsgn'):
|
2022-05-25 13:52:20 +00:00
|
|
|
''' fits a curve to the given points
|
|
|
|
returns lists of x and y values to plot that curve and legend elements with the equation
|
|
|
|
'''
|
2022-05-18 16:08:40 +00:00
|
|
|
|
2022-05-19 20:24:47 +00:00
|
|
|
funcArr = genFuncs(fits)
|
2022-05-18 16:08:40 +00:00
|
|
|
|
|
|
|
mat = []
|
|
|
|
for w in widths:
|
2022-05-19 20:24:47 +00:00
|
|
|
row = []
|
|
|
|
for func in funcArr:
|
|
|
|
row += [func(w)]
|
2022-05-18 16:08:40 +00:00
|
|
|
mat += [row]
|
|
|
|
|
|
|
|
y = np.array(var, dtype=np.float)
|
|
|
|
coefsResid = np.linalg.lstsq(mat, y, rcond=None)
|
|
|
|
coefs = coefsResid[0]
|
2022-05-19 20:24:47 +00:00
|
|
|
try:
|
|
|
|
resid = coefsResid[1][0]
|
|
|
|
except:
|
|
|
|
resid = 0
|
2022-05-18 16:08:40 +00:00
|
|
|
r2 = 1 - resid / (y.size * y.var())
|
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
xp = np.linspace(8, 140, 200)
|
|
|
|
pred = []
|
|
|
|
for x in xp:
|
|
|
|
n = [func(x) for func in funcArr]
|
|
|
|
pred += [sum(np.multiply(coefs, n))]
|
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
leg = genLegend(fits, coefs, r2, spec)
|
2022-05-25 13:52:20 +00:00
|
|
|
|
|
|
|
return xp, pred, leg
|
|
|
|
|
|
|
|
def makeCoefTable(tech):
|
2022-05-25 20:37:54 +00:00
|
|
|
''' not currently in use, may salvage later
|
|
|
|
writes CSV with each line containing the coefficients for a regression fit
|
2022-05-25 13:52:20 +00:00
|
|
|
to a particular combination of module, metric, and target frequency
|
|
|
|
'''
|
2022-05-18 16:08:40 +00:00
|
|
|
file = open("ppaFitting.csv", "w")
|
|
|
|
writer = csv.writer(file)
|
2022-05-19 20:24:47 +00:00
|
|
|
writer.writerow(['Module', 'Metric', 'Freq', '1', 'N', 'N^2', 'log2(N)', 'Nlog2(N)', 'R^2'])
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-18 17:01:55 +00:00
|
|
|
for mod in ['add', 'mult', 'comparator', 'shifter']:
|
2022-05-18 16:08:40 +00:00
|
|
|
for comb in [['delay', 5000], ['area', 5000], ['area', 10]]:
|
|
|
|
var = comb[0]
|
|
|
|
freq = comb[1]
|
2022-05-28 04:57:18 +00:00
|
|
|
metric = getVals(tech, mod, freq, var)
|
2022-05-25 20:37:54 +00:00
|
|
|
global widths
|
2022-05-19 20:24:47 +00:00
|
|
|
coefs, r2, funcArr = regress(widths, metric)
|
|
|
|
row = [mod] + comb + np.ndarray.tolist(coefs) + [r2]
|
2022-05-18 16:08:40 +00:00
|
|
|
writer.writerow(row)
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-18 16:08:40 +00:00
|
|
|
file.close()
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-19 20:24:47 +00:00
|
|
|
def genFuncs(fits='clsgn'):
|
2022-05-25 13:52:20 +00:00
|
|
|
''' helper function for regress()
|
|
|
|
returns array of functions with one for each term desired in the regression fit
|
|
|
|
'''
|
2022-05-19 20:24:47 +00:00
|
|
|
funcArr = []
|
|
|
|
if 'c' in fits:
|
|
|
|
funcArr += [lambda x: 1]
|
|
|
|
if 'l' in fits:
|
|
|
|
funcArr += [lambda x: x]
|
|
|
|
if 's' in fits:
|
|
|
|
funcArr += [lambda x: x**2]
|
|
|
|
if 'g' in fits:
|
|
|
|
funcArr += [lambda x: np.log2(x)]
|
|
|
|
if 'n' in fits:
|
|
|
|
funcArr += [lambda x: x*np.log2(x)]
|
|
|
|
return funcArr
|
|
|
|
|
|
|
|
def noOutliers(freqs, delays, areas):
|
2022-05-25 13:52:20 +00:00
|
|
|
''' returns a pared down list of freqs, delays, and areas
|
|
|
|
cuts out any syntheses in which target freq isn't within 75% of the min delay target to focus on interesting area
|
|
|
|
helper function to freqPlot()
|
|
|
|
'''
|
2022-05-19 20:24:47 +00:00
|
|
|
f=[]
|
|
|
|
d=[]
|
|
|
|
a=[]
|
2022-05-26 20:51:00 +00:00
|
|
|
ind = delays.index(min(delays))
|
|
|
|
med = freqs[ind]
|
|
|
|
for i in range(len(freqs)):
|
|
|
|
norm = freqs[i]/med
|
|
|
|
if (norm > 0.25) & (norm<1.75):
|
|
|
|
f += [freqs[i]]
|
|
|
|
d += [delays[i]]
|
|
|
|
a += [areas[i]]
|
2022-05-21 09:53:26 +00:00
|
|
|
|
2022-05-19 20:24:47 +00:00
|
|
|
return f, d, a
|
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
def freqPlot(tech, mod, width):
|
|
|
|
''' plots delay, area, area*delay, and area*delay^2 for syntheses with specified tech, module, width
|
|
|
|
'''
|
2022-05-25 20:37:54 +00:00
|
|
|
global allSynths
|
2022-05-25 13:52:20 +00:00
|
|
|
freqsL, delaysL, areasL = ([[], []] for i in range(3))
|
2022-05-19 20:24:47 +00:00
|
|
|
for oneSynth in allSynths:
|
2022-05-25 20:37:54 +00:00
|
|
|
if (mod == oneSynth.module) & (width == oneSynth.width) & (tech == oneSynth.tech):
|
|
|
|
ind = (1000/oneSynth.delay < oneSynth.freq) # when delay is within target clock period
|
|
|
|
freqsL[ind] += [oneSynth.freq]
|
|
|
|
delaysL[ind] += [oneSynth.delay]
|
|
|
|
areasL[ind] += [oneSynth.area]
|
2022-05-25 13:52:20 +00:00
|
|
|
|
2022-05-26 20:51:00 +00:00
|
|
|
f, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True)
|
2022-05-25 13:52:20 +00:00
|
|
|
|
|
|
|
for ind in [0,1]:
|
|
|
|
areas = areasL[ind]
|
|
|
|
delays = delaysL[ind]
|
|
|
|
freqs = freqsL[ind]
|
|
|
|
|
|
|
|
if ('flop' in mod): areas = [m/2 for m in areas] # since two flops in each module
|
2022-05-26 20:51:00 +00:00
|
|
|
freqs, delays, areas = noOutliers(freqs, delays, areas) # comment out to see all syntheses
|
2022-05-25 13:52:20 +00:00
|
|
|
|
|
|
|
c = 'blue' if ind else 'green'
|
2022-05-26 20:51:00 +00:00
|
|
|
adprod = adprodpow(areas, delays, 1)
|
|
|
|
adpow = adprodpow(areas, delays, 2)
|
2022-05-25 13:52:20 +00:00
|
|
|
ax1.scatter(freqs, delays, color=c)
|
|
|
|
ax2.scatter(freqs, areas, color=c)
|
|
|
|
ax3.scatter(freqs, adprod, color=c)
|
|
|
|
ax4.scatter(freqs, adpow, color=c)
|
2022-05-21 09:53:26 +00:00
|
|
|
|
|
|
|
legend_elements = [lines.Line2D([0], [0], color='green', ls='', marker='o', label='timing achieved'),
|
|
|
|
lines.Line2D([0], [0], color='blue', ls='', marker='o', label='slack violated')]
|
2022-05-19 20:24:47 +00:00
|
|
|
|
2022-05-21 09:53:26 +00:00
|
|
|
ax1.legend(handles=legend_elements)
|
2022-05-25 13:52:20 +00:00
|
|
|
|
2022-05-21 09:53:26 +00:00
|
|
|
ax4.set_xlabel("Target Freq (MHz)")
|
2022-05-19 20:24:47 +00:00
|
|
|
ax1.set_ylabel('Delay (ns)')
|
|
|
|
ax2.set_ylabel('Area (sq microns)')
|
|
|
|
ax3.set_ylabel('Area * Delay')
|
2022-05-25 13:52:20 +00:00
|
|
|
ax4.set_ylabel('Area * $Delay^2$')
|
2022-05-19 20:24:47 +00:00
|
|
|
ax1.set_title(mod + '_' + str(width))
|
|
|
|
plt.show()
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-26 22:24:39 +00:00
|
|
|
def squareAreaDelay(tech, mod, width):
|
|
|
|
''' plots delay, area, area*delay, and area*delay^2 for syntheses with specified tech, module, width
|
|
|
|
'''
|
|
|
|
global allSynths
|
|
|
|
freqsL, delaysL, areasL = ([[], []] for i in range(3))
|
|
|
|
for oneSynth in allSynths:
|
|
|
|
if (mod == oneSynth.module) & (width == oneSynth.width) & (tech == oneSynth.tech):
|
|
|
|
ind = (1000/oneSynth.delay < oneSynth.freq) # when delay is within target clock period
|
|
|
|
freqsL[ind] += [oneSynth.freq]
|
|
|
|
delaysL[ind] += [oneSynth.delay]
|
|
|
|
areasL[ind] += [oneSynth.area]
|
|
|
|
|
2022-05-27 20:59:23 +00:00
|
|
|
f, (ax1) = plt.subplots(1, 1)
|
|
|
|
ax2 = ax1.twinx()
|
2022-05-26 22:24:39 +00:00
|
|
|
|
|
|
|
for ind in [0,1]:
|
|
|
|
areas = areasL[ind]
|
|
|
|
delays = delaysL[ind]
|
2022-05-27 20:59:23 +00:00
|
|
|
targets = freqsL[ind]
|
|
|
|
targets = [1000/f for f in targets]
|
|
|
|
|
2022-05-26 22:24:39 +00:00
|
|
|
if ('flop' in mod): areas = [m/2 for m in areas] # since two flops in each module
|
2022-05-27 20:59:23 +00:00
|
|
|
targets, delays, areas = noOutliers(targets, delays, areas) # comment out to see all
|
|
|
|
|
|
|
|
if not ind:
|
|
|
|
achievedDelays = delays
|
2022-05-26 22:24:39 +00:00
|
|
|
|
|
|
|
c = 'blue' if ind else 'green'
|
2022-05-27 20:59:23 +00:00
|
|
|
ax1.scatter(targets, delays, marker='^', color=c)
|
|
|
|
ax2.scatter(targets, areas, marker='s', color=c)
|
|
|
|
|
|
|
|
bestAchieved = min(achievedDelays)
|
|
|
|
|
|
|
|
legend_elements = [lines.Line2D([0], [0], color='green', ls='', marker='^', label='delay (timing achieved)'),
|
|
|
|
lines.Line2D([0], [0], color='green', ls='', marker='s', label='area (timing achieved)'),
|
|
|
|
lines.Line2D([0], [0], color='blue', ls='', marker='^', label='delay (timing violated)'),
|
|
|
|
lines.Line2D([0], [0], color='blue', ls='', marker='s', label='area (timing violated)')]
|
|
|
|
|
|
|
|
ax2.legend(handles=legend_elements, loc='upper left')
|
|
|
|
|
|
|
|
ax1.set_xlabel("Delay Targeted (ns)")
|
|
|
|
ax1.set_ylabel("Delay Achieved (ns)")
|
|
|
|
ax2.set_ylabel('Area (sq microns)')
|
|
|
|
ax1.set_title(mod + '_' + str(width))
|
2022-05-26 22:24:39 +00:00
|
|
|
|
2022-05-27 20:59:23 +00:00
|
|
|
squarify(f)
|
|
|
|
|
|
|
|
xvals = np.array(ax1.get_xlim())
|
|
|
|
frac = (min(flatten(delaysL))-xvals[0])/(xvals[1]-xvals[0])
|
|
|
|
areaLowerLim = min(flatten(areasL))-100
|
|
|
|
areaUpperLim = max(flatten(areasL))/frac + areaLowerLim
|
|
|
|
ax2.set_ylim([areaLowerLim, areaUpperLim])
|
|
|
|
ax1.plot(xvals, xvals, ls="--", c=".3")
|
|
|
|
ax1.hlines(y=bestAchieved, xmin=xvals[0], xmax=xvals[1], color="black", ls='--')
|
2022-05-26 22:24:39 +00:00
|
|
|
|
|
|
|
plt.show()
|
|
|
|
|
2022-05-27 20:59:23 +00:00
|
|
|
def squarify(fig):
|
|
|
|
''' helper function for squareAreaDelay()
|
|
|
|
forces matplotlib figure to be a square
|
|
|
|
'''
|
|
|
|
w, h = fig.get_size_inches()
|
|
|
|
if w > h:
|
|
|
|
t = fig.subplotpars.top
|
|
|
|
b = fig.subplotpars.bottom
|
|
|
|
axs = h*(t-b)
|
|
|
|
l = (1.-axs/w)/2
|
|
|
|
fig.subplots_adjust(left=l, right=1-l)
|
|
|
|
else:
|
|
|
|
t = fig.subplotpars.right
|
|
|
|
b = fig.subplotpars.left
|
|
|
|
axs = w*(t-b)
|
|
|
|
l = (1.-axs/h)/2
|
|
|
|
fig.subplots_adjust(bottom=l, top=1-l)
|
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
def adprodpow(areas, delays, pow):
|
|
|
|
''' for each value in [areas] returns area*delay^pow
|
|
|
|
helper function for freqPlot'''
|
|
|
|
result = []
|
2022-05-25 06:44:22 +00:00
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
for i in range(len(areas)):
|
|
|
|
result += [(areas[i])*(delays[i])**pow]
|
2022-05-25 06:44:22 +00:00
|
|
|
|
2022-05-25 13:52:20 +00:00
|
|
|
return result
|
2022-05-25 06:44:22 +00:00
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
def plotPPA(mod, freq=None, norm=True):
|
2022-05-25 13:52:20 +00:00
|
|
|
''' for the module specified, plots width vs delay, area, leakage power, and dynamic energy with fits
|
2022-05-27 20:59:23 +00:00
|
|
|
if no freq specified, uses the synthesis with best achievable delay for each width
|
2022-05-25 13:52:20 +00:00
|
|
|
overlays data from both techs
|
|
|
|
'''
|
2022-05-21 09:53:26 +00:00
|
|
|
fig, axs = plt.subplots(2, 2)
|
2022-05-28 04:57:18 +00:00
|
|
|
global fitDict
|
|
|
|
modFit = fitDict[mod]
|
|
|
|
oneMetricPlot(mod, 'delay', ax=axs[0,0], fits=modFit[0], freq=freq, norm=norm)
|
|
|
|
oneMetricPlot(mod, 'area', ax=axs[0,1], fits=modFit[1], freq=freq, norm=norm)
|
|
|
|
oneMetricPlot(mod, 'lpower', ax=axs[1,0], fits=modFit[1], freq=freq, norm=norm)
|
|
|
|
oneMetricPlot(mod, 'denergy', ax=axs[1,1], fits=modFit[1], freq=freq, norm=norm)
|
2022-05-27 20:59:23 +00:00
|
|
|
titleStr = " (target " + str(freq)+ "MHz)" if freq != None else " (best achievable delay)"
|
2022-05-21 09:53:26 +00:00
|
|
|
plt.suptitle(mod + titleStr)
|
|
|
|
plt.show()
|
2022-05-26 20:51:00 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2022-05-17 18:29:38 +00:00
|
|
|
|
2022-05-26 20:51:00 +00:00
|
|
|
# set up stuff, global variables
|
|
|
|
widths = [8, 16, 32, 64, 128]
|
2022-05-28 04:57:18 +00:00
|
|
|
# fitDict in progress
|
|
|
|
fitDict = {'add': ['cg', 'cl'], 'mult': ['clg', 's'], 'comparator': ['clsgn', 'clsgn'], 'csa': ['clsgn', 'clsgn'], 'shiftleft': ['clsgn', 'clsgn'], 'flop': ['cl', 'cl'], 'priorityencoder': ['clsgn', 'clsgn']}
|
|
|
|
TechSpec = namedtuple("TechSpec", "tech color shape delay area lpower denergy")
|
|
|
|
techSpecs = [['sky90', 'green', 'o', 43.2e-3, 1.96, 1.98, 1], ['gf32', 'purple', 's', 15e-3, .351, .3116, 1], ['tsmc28', 'blue', '^', 12.2e-3, .252, 1.09, 1]]
|
|
|
|
techSpecs = [TechSpec(*t) for t in techSpecs]
|
2022-05-25 06:44:22 +00:00
|
|
|
|
2022-05-28 04:57:18 +00:00
|
|
|
# cleanup()
|
2022-05-26 20:51:00 +00:00
|
|
|
# synthsintocsv() # slow, run only when new synth runs to add to csv
|
|
|
|
|
|
|
|
synthsfromcsv('ppaData.csv') # your csv here!
|
2022-05-18 16:08:40 +00:00
|
|
|
|
2022-05-26 20:51:00 +00:00
|
|
|
### examples
|
2022-05-28 04:57:18 +00:00
|
|
|
# for mod in ['comparator', 'priorityencoder', 'shiftleft']:
|
|
|
|
# for w in [16, 32]:
|
|
|
|
# freqPlot('sky90', mod, w) # the weird ones
|
|
|
|
# squareAreaDelay('sky90', 'add', 32)
|
|
|
|
# oneMetricPlot('add', 'delay')
|
|
|
|
for mod in ['add', 'csa', 'mult', 'comparator', 'priorityencoder', 'shiftleft', 'flop']:
|
|
|
|
plotPPA(mod, norm=False) # no norm input now defaults to normalized
|