restored functionality of makeCoefTable()

This commit is contained in:
Madeleine Masser-Frye 2022-06-09 00:07:51 +00:00
parent a54837b102
commit f50b3837f5
2 changed files with 114 additions and 58 deletions

View File

@ -197,6 +197,8 @@ def oneMetricPlot(module, var, freq=None, ax=None, fits='clsgn', norm=True, colo
allMetrics = [] allMetrics = []
ale = (var != 'delay') # if not delay, must be area, leakage, or energy ale = (var != 'delay') # if not delay, must be area, leakage, or energy
modFit = fitDict[mod]
fits = modFit[ale]
for spec in techSpecs: for spec in techSpecs:
metric = getVals(spec.tech, module, var, freq=freq) metric = getVals(spec.tech, module, var, freq=freq)
@ -207,8 +209,8 @@ def oneMetricPlot(module, var, freq=None, ax=None, fits='clsgn', norm=True, colo
metric = [m/norm for m in metric] metric = [m/norm for m in metric]
if len(metric) == 5: # don't include the spec if we don't have points for all widths if len(metric) == 5: # don't include the spec if we don't have points for all widths
xp, pred, leg = regress(widths, metric, spec, fits, ale=ale) xp, pred, coefs, r2 = regress(widths, metric, fits)
fullLeg += leg fullLeg += genLegend(fits, coefs, r2, spec, ale=ale)
c = color if color else spec.color c = color if color else spec.color
ax.scatter(widths, metric, color=c, marker=spec.shape) ax.scatter(widths, metric, color=c, marker=spec.shape)
ax.plot(xp, pred, color=c) ax.plot(xp, pred, color=c)
@ -216,7 +218,8 @@ def oneMetricPlot(module, var, freq=None, ax=None, fits='clsgn', norm=True, colo
allMetrics += metric allMetrics += metric
combined = TechSpec('combined', 'red', '_', 0, 0, 0, 0) combined = TechSpec('combined', 'red', '_', 0, 0, 0, 0)
xp, pred, leg = regress(allWidths, allMetrics, combined, fits, ale=ale) xp, pred, coefs, r2 = regress(allWidths, allMetrics, fits)
leg = genLegend(fits, coefs, r2, combined, ale=ale)
fullLeg += leg fullLeg += leg
ax.plot(xp, pred, color='red') ax.plot(xp, pred, color='red')
@ -232,14 +235,17 @@ def oneMetricPlot(module, var, freq=None, ax=None, fits='clsgn', norm=True, colo
if (module in ['flop', 'csa']) & (var == 'delay'): if (module in ['flop', 'csa']) & (var == 'delay'):
ax.set_ylim(ymin=0) ax.set_ylim(ymin=0)
ytop = ax.get_ylim()[1]
ax.set_ylim(ymax=1.1*ytop)
if singlePlot: if singlePlot:
titleStr = " (target " + str(freq)+ "MHz)" if freq != None else " (best achievable delay)" titleStr = " (target " + str(freq)+ "MHz)" if freq != None else " (best achievable delay)"
ax.set_title(module + titleStr) ax.set_title(module + titleStr)
plt.savefig('./plots/PPA/'+ module + '_' + var + '.png') plt.savefig('./plots/PPA/'+ module + '_' + var + '.png')
# plt.show() # plt.show()
return fullLeg
def regress(widths, var, spec, fits='clsgn', ale=False): def regress(widths, var, fits='clsgn'):
''' fits a curve to the given points ''' fits a curve to the given points
returns lists of x and y values to plot that curve and legend elements with the equation returns lists of x and y values to plot that curve and legend elements with the equation
''' '''
@ -268,27 +274,40 @@ def regress(widths, var, spec, fits='clsgn', ale=False):
n = [func(x/normAddWidth) for func in funcArr] n = [func(x/normAddWidth) for func in funcArr]
pred += [sum(np.multiply(coefs, n))] pred += [sum(np.multiply(coefs, n))]
leg = genLegend(fits, coefs, r2, spec, ale=ale) return xp, pred, coefs, r2
return xp, pred, leg def makeCoefTable():
'''
def makeCoefTable(tech):
''' not currently in use, may salvage later
writes CSV with each line containing the coefficients for a regression fit writes CSV with each line containing the coefficients for a regression fit
to a particular combination of module, metric, and target frequency to a particular combination of module, metric (including both techs, normalized)
''' '''
file = open("ppaFitting.csv", "w") file = open("ppaFitting.csv", "w")
writer = csv.writer(file) writer = csv.writer(file)
writer.writerow(['Module', 'Metric', 'Freq', '1', 'N', 'N^2', 'log2(N)', 'Nlog2(N)', 'R^2']) writer.writerow(['Module', 'Metric', '1', 'N', 'N^2', 'log2(N)', 'Nlog2(N)', 'R^2'])
for mod in ['add', 'mult', 'comparator', 'shifter']: for module in modules:
for comb in [['delay', 5000], ['area', 5000], ['area', 10]]: for var in ['delay', 'area', 'lpower', 'denergy']:
var = comb[0] ale = (var != 'delay')
freq = comb[1] metL = []
metric = getVals(tech, mod, freq, var) modFit = fitDict[module]
global widths fits = modFit[ale]
coefs, r2, funcArr = regress(widths, metric)
row = [mod] + comb + np.ndarray.tolist(coefs) + [r2] for spec in techSpecs:
metric = getVals(spec.tech, module, var)
techdict = spec._asdict()
norm = techdict[var]
metL += [m/norm for m in metric]
xp, pred, coefs, r2 = regress(widths*2, metL, fits)
coefs = np.ndarray.tolist(coefs)
coefsToWrite = [None]*5
fitTerms = 'clsgn'
ind = 0
for i in range(len(fitTerms)):
if fitTerms[i] in fits:
coefsToWrite[i] = coefs[ind]
ind += 1
row = [module, var] + coefsToWrite + [r2]
writer.writerow(row) writer.writerow(row)
file.close() file.close()
@ -341,8 +360,8 @@ def freqPlot(tech, mod, width):
median = np.median(list(flatten(freqsL))) median = np.median(list(flatten(freqsL)))
f, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True) f, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
for ax in (ax1, ax2, ax3, ax4): for ax in (ax1, ax2): #, ax3, ax4):
ax.ticklabel_format(useOffset=False, style='plain') ax.ticklabel_format(useOffset=False, style='plain')
for ind in [0,1]: for ind in [0,1]:
@ -353,23 +372,23 @@ def freqPlot(tech, mod, width):
freqs, delays, areas = noOutliers(median, freqs, delays, areas) # comment out to see all syntheses freqs, delays, areas = noOutliers(median, freqs, delays, areas) # comment out to see all syntheses
c = 'blue' if ind else 'green' c = 'blue' if ind else 'green'
adprod = adprodpow(areas, delays, 1) # adprod = adprodpow(areas, delays, 1)
adpow = adprodpow(areas, delays, 2) # adpow = adprodpow(areas, delays, 2)
ax1.scatter(freqs, delays, color=c) ax1.scatter(freqs, delays, color=c)
ax2.scatter(freqs, areas, color=c) ax2.scatter(freqs, areas, color=c)
ax3.scatter(freqs, adprod, color=c) # ax3.scatter(freqs, adprod, color=c)
ax4.scatter(freqs, adpow, color=c) # ax4.scatter(freqs, adpow, color=c)
legend_elements = [lines.Line2D([0], [0], color='green', ls='', marker='o', label='timing achieved'), 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')] lines.Line2D([0], [0], color='blue', ls='', marker='o', label='slack violated')]
ax1.legend(handles=legend_elements) ax1.legend(handles=legend_elements)
ax4.set_xlabel("Target Freq (MHz)") ax2.set_xlabel("Target Freq (MHz)")
ax1.set_ylabel('Delay (ns)') ax1.set_ylabel('Delay (ns)')
ax2.set_ylabel('Area (sq microns)') ax2.set_ylabel('Area (sq microns)')
ax3.set_ylabel('Area * Delay') # ax3.set_ylabel('Area * Delay')
ax4.set_ylabel('Area * $Delay^2$') # ax4.set_ylabel('Area * $Delay^2$')
ax1.set_title(mod + '_' + str(width)) ax1.set_title(mod + '_' + str(width))
plt.savefig('./plots/freqBuckshot/' + tech + '/' + mod + '/' + str(width) + '.png') plt.savefig('./plots/freqBuckshot/' + tech + '/' + mod + '/' + str(width) + '.png')
# plt.show() # plt.show()
@ -464,23 +483,31 @@ def plotPPA(mod, freq=None, norm=True, aleOpt=False):
if no freq specified, uses the synthesis with best achievable delay for each width if no freq specified, uses the synthesis with best achievable delay for each width
overlays data from both techs overlays data from both techs
''' '''
plt.rcParams["figure.figsize"] = (12,8) plt.rcParams["figure.figsize"] = (10,7)
fig, axs = plt.subplots(2, 2) fig, axs = plt.subplots(2, 2)
modFit = fitDict[mod] # fig, axs = plt.subplots(4, 1)
# oneMetricPlot(mod, 'delay', ax=axs[0], fits=modFit[0], freq=freq, norm=norm)
# oneMetricPlot(mod, 'area', ax=axs[1], fits=modFit[1], freq=freq, norm=norm)
# oneMetricPlot(mod, 'lpower', ax=axs[2], fits=modFit[1], freq=freq, norm=norm)
# oneMetricPlot(mod, 'denergy', ax=axs[3], fits=modFit[1], freq=freq, norm=norm)
oneMetricPlot(mod, 'delay', ax=axs[0,0], freq=freq, norm=norm)
oneMetricPlot(mod, 'area', ax=axs[0,1], freq=freq, norm=norm)
oneMetricPlot(mod, 'lpower', ax=axs[1,0], freq=freq, norm=norm)
fullLeg = oneMetricPlot(mod, 'denergy', ax=axs[1,1], freq=freq, norm=norm)
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)
if aleOpt: if aleOpt:
oneMetricPlot(mod, 'area', ax=axs[0,1], fits=modFit[1], freq=10, norm=norm, color='black') oneMetricPlot(mod, 'area', ax=axs[0,1], freq=10, norm=norm, color='black')
oneMetricPlot(mod, 'lpower', ax=axs[1,0], fits=modFit[1], freq=10, norm=norm, color='black') oneMetricPlot(mod, 'lpower', ax=axs[1,0], freq=10, norm=norm, color='black')
oneMetricPlot(mod, 'denergy', ax=axs[1,1], fits=modFit[1], freq=10, norm=norm, color='black') oneMetricPlot(mod, 'denergy', ax=axs[1,1], freq=10, norm=norm, color='black')
titleStr = " (target " + str(freq)+ "MHz)" if freq != None else " (best achievable delay)" titleStr = " (target " + str(freq)+ "MHz)" if freq != None else " (best achievable delay)"
n = 'normalized' if norm else 'unnormalized' n = 'normalized' if norm else 'unnormalized'
saveStr = './plots/PPA/'+ n + '/' + mod + '.png' saveStr = './plots/PPA/'+ n + '/' + mod + '.png'
plt.suptitle(mod + titleStr) plt.suptitle(mod + titleStr)
# fig.legend(handles=fullLeg, ncol=3, loc='center', bbox_to_anchor=(0.3, 0.82, 0.4, 0.2))
if freq != 10: plt.savefig(saveStr) if freq != 10: plt.savefig(saveStr)
# plt.show() # plt.show()
@ -511,7 +538,7 @@ if __name__ == '__main__':
fitDict = {'add': ['cg', 'l', 'l'], 'mult': ['cg', 's', 'ls'], 'comparator': ['cg', 'l', 'l'], 'csa': ['c', 'l', 'l'], 'shiftleft': ['cg', 'l', 'ln'], 'flop': ['c', 'l', 'l'], 'priorityencoder': ['cg', 'l', 'l']} fitDict = {'add': ['cg', 'l', 'l'], 'mult': ['cg', 's', 'ls'], 'comparator': ['cg', 'l', 'l'], 'csa': ['c', 'l', 'l'], 'shiftleft': ['cg', 'l', 'ln'], 'flop': ['c', 'l', 'l'], 'priorityencoder': ['cg', 'l', 'l']}
fitDict.update(dict.fromkeys(['mux2', 'mux4', 'mux8'], ['cg', 'l', 'l'])) fitDict.update(dict.fromkeys(['mux2', 'mux4', 'mux8'], ['cg', 'l', 'l']))
leftblue = [['mux2', 'sky90', 32], ['mux2', 'sky90', 64], ['mux2', 'sky90', 128], ['mux2', 'tsmc28', 16], ['mux2', 'tsmc28', 8], ['mux8', 'sky90', 32]] leftblue = [['mux2', 'sky90', 32], ['mux2', 'sky90', 64], ['mux2', 'sky90', 128], ['mux8', 'sky90', 32], ['mux2', 'tsmc28', 8], ['mux2', 'tsmc28', 64]]
TechSpec = namedtuple("TechSpec", "tech color shape delay area lpower denergy") TechSpec = namedtuple("TechSpec", "tech color shape delay area lpower denergy")
techSpecs = [['sky90', 'green', 'o', 43.2e-3, 1330.84, 582.81, 520.66], ['tsmc28', 'blue', '^', 12.2e-3, 209.29, 1060, 81.43]] techSpecs = [['sky90', 'green', 'o', 43.2e-3, 1330.84, 582.81, 520.66], ['tsmc28', 'blue', '^', 12.2e-3, 209.29, 1060, 81.43]]
@ -529,12 +556,13 @@ if __name__ == '__main__':
# squareAreaDelay('sky90', 'add', 32) # squareAreaDelay('sky90', 'add', 32)
# oneMetricPlot('add', 'delay') # oneMetricPlot('add', 'delay')
# freqPlot('sky90', 'mux4', 16) # freqPlot('sky90', 'mux4', 16)
# makeCoefTable()
for mod in modules: for mod in ['mux2']: #modules:
# plotPPA(mod, norm=False) plotPPA(mod, norm=False)
plotPPA(mod, aleOpt=True) plotPPA(mod) #, aleOpt=True)
plotBestAreas(mod) # plotBestAreas(mod)
for w in [8, 16, 32, 64, 128]: # for w in [8, 16, 32, 64, 128]:
freqPlot('sky90', mod, w) # freqPlot('sky90', mod, w)
freqPlot('tsmc28', mod, w) # freqPlot('tsmc28', mod, w)
plt.close('all') plt.close('all')

View File

@ -1,13 +1,41 @@
Module,Metric,Freq,1,N,N^2,log2(N),Nlog2(N),R^2 Module,Metric,1,N,N^2,log2(N),Nlog2(N),R^2
add,delay,5000,-0.038978555556527635,-0.08911531250030817,-0.00012953428819478948,0.2083593333340971,0.013950093750045424,1.0 priorityencoder,delay,4.865032478368464,,,1.0346781590203091,,0.990533246983837
add,area,5000,-1913.1778463362505,-268.21377075092175,-0.4100347526051751,1046.9667200022955,47.59125331263557,1.0 priorityencoder,area,,0.3296349181169891,,,,0.9718942704677337
add,area,10,-13.720001333167332,14.700000312552621,1.3021426840869221e-09,-1.3062278840780171e-10,-9.375775472819561e-08,1.0 priorityencoder,lpower,,0.2508481588069769,,,,0.9418329012771585
mult,delay,5000,-0.2915958888891911,-0.02828693750009581,-3.445876736121953e-05,0.32169033333357117,0.0044735312500140964,1.0 priorityencoder,denergy,,0.09327161156406552,,,,0.8065924672945542
mult,area,5000,27780.605184113756,10418.196477973508,26.857274703166343,-24448.387256089416,-1468.2850310678027,1.0 add,delay,8.961254531683414,,,1.4310340215065527,,0.9564367595740637
mult,area,10,-6472.791005245042,-2075.5787013197305,8.20962684330778,5345.246556351299,313.5693677823146,1.0 add,area,,1.0710989265923485,,,,0.988580182173048
comparator,delay,5000,0.1903951111111219,0.000987500000002994,3.427951388890516e-06,3.333333324460974e-06,-0.00012593750000039925,1.0 add,lpower,,0.9470245397661955,,,,0.9951383820581323
comparator,area,5000,-508.51109056188875,-579.7924890645068,-1.0888888741341944,969.5466443383111,101.5524983752957,1.0 add,denergy,,0.9954952282287014,,,,0.9928308616130285
comparator,area,10,-155.6022268893253,-40.3637507501383,-0.07230902908001494,132.9533363336765,8.452500156270371,1.0 csa,delay,3.590384717869601,,,,,0.0
shifter,delay,5000,0.06953233333235516,-0.08957893750031035,-0.00015877864583368578,0.16727300000076853,0.014763625000045773,1.0 csa,area,,0.9312877569527923,,,,0.999393942859829
shifter,area,5000,-237.48663487568587,1208.7075255666841,1.5708073263938906,-1678.7400476770383,-166.69187856311666,1.0 csa,lpower,,1.5320774877598933,,,,0.9400384192534433
shifter,area,10,-1079.4155736731122,-591.3687615645423,-0.877491337241916,1211.9333560050677,103.11437703155087,1.0 csa,denergy,,1.1454135769936609,,,,0.9735205275004183
shiftleft,delay,8.66019468793489,,,1.6351711913499432,,0.9873681453602638
shiftleft,area,,1.9102134686740575,,,,0.9466461680123697
shiftleft,lpower,,2.277088275290811,,,,0.9624044038708768
shiftleft,denergy,,1.4931073444617051,,,,0.9454881696599784
comparator,delay,6.680678539086959,,,0.9397668550976327,,0.98789326603378
comparator,area,,0.6003877936704982,,,,0.9672416909621802
comparator,lpower,,0.46756802348373877,,,,0.8609362596824635
comparator,denergy,,0.3089180049610159,,,,0.8267293340232036
flop,delay,3.3270503187614153,,,,,0.0
flop,area,,0.34478305655859876,,,,0.9433629202566682
flop,lpower,,0.3707856336608904,,,,0.9170347531086821
flop,denergy,,0.0011765517257429892,,,,0.688648230209356
mux2,delay,4.732514086885074,,,0.38138175938205005,,0.5638177354804589
mux2,area,,0.19794547955000782,,,,0.9753613114571431
mux2,lpower,,0.1881638557015794,,,,0.7572248871637561
mux2,denergy,,0.16278100836605952,,,,0.9811112115671446
mux4,delay,5.67790744523475,,,0.5081925137582493,,0.8316415055210026
mux4,area,,0.35778033738856435,,,,0.9880049722019894
mux4,lpower,,0.32236674794207065,,,,0.8279138454959137
mux4,denergy,,0.28073375091037084,,,,0.9943662618662574
mux8,delay,7.252700330388384,,,0.45254210999717837,,0.8464368692304263
mux8,area,,0.7614128432326613,,,,0.9863118376555963
mux8,lpower,,0.6570734849206145,,,,0.9855956038468652
mux8,denergy,,0.4496346388149245,,,,0.9785597135426944
mult,delay,29.562138166420393,,,6.711916207386673,,0.9833266087176287
mult,area,,,13.838943348894976,,,0.9875861886135875
mult,lpower,,,14.380577146903335,,,0.9349609233308782
mult,denergy,,,36.51397409545879,,,0.9719012952478829

1 Module Metric Freq 1 N N^2 log2(N) Nlog2(N) R^2
2 add priorityencoder delay 5000 -0.038978555556527635 4.865032478368464 -0.08911531250030817 -0.00012953428819478948 0.2083593333340971 1.0346781590203091 0.013950093750045424 1.0 0.990533246983837
3 add priorityencoder area 5000 -1913.1778463362505 -268.21377075092175 0.3296349181169891 -0.4100347526051751 1046.9667200022955 47.59125331263557 1.0 0.9718942704677337
4 add priorityencoder area lpower 10 -13.720001333167332 14.700000312552621 0.2508481588069769 1.3021426840869221e-09 -1.3062278840780171e-10 -9.375775472819561e-08 1.0 0.9418329012771585
5 mult priorityencoder delay denergy 5000 -0.2915958888891911 -0.02828693750009581 0.09327161156406552 -3.445876736121953e-05 0.32169033333357117 0.0044735312500140964 1.0 0.8065924672945542
6 mult add area delay 5000 27780.605184113756 8.961254531683414 10418.196477973508 26.857274703166343 -24448.387256089416 1.4310340215065527 -1468.2850310678027 1.0 0.9564367595740637
7 mult add area 10 -6472.791005245042 -2075.5787013197305 1.0710989265923485 8.20962684330778 5345.246556351299 313.5693677823146 1.0 0.988580182173048
8 comparator add delay lpower 5000 0.1903951111111219 0.000987500000002994 0.9470245397661955 3.427951388890516e-06 3.333333324460974e-06 -0.00012593750000039925 1.0 0.9951383820581323
9 comparator add area denergy 5000 -508.51109056188875 -579.7924890645068 0.9954952282287014 -1.0888888741341944 969.5466443383111 101.5524983752957 1.0 0.9928308616130285
10 comparator csa area delay 10 -155.6022268893253 3.590384717869601 -40.3637507501383 -0.07230902908001494 132.9533363336765 8.452500156270371 1.0 0.0
11 shifter csa delay area 5000 0.06953233333235516 -0.08957893750031035 0.9312877569527923 -0.00015877864583368578 0.16727300000076853 0.014763625000045773 1.0 0.999393942859829
12 shifter csa area lpower 5000 -237.48663487568587 1208.7075255666841 1.5320774877598933 1.5708073263938906 -1678.7400476770383 -166.69187856311666 1.0 0.9400384192534433
13 shifter csa area denergy 10 -1079.4155736731122 -591.3687615645423 1.1454135769936609 -0.877491337241916 1211.9333560050677 103.11437703155087 1.0 0.9735205275004183
14 shiftleft delay 8.66019468793489 1.6351711913499432 0.9873681453602638
15 shiftleft area 1.9102134686740575 0.9466461680123697
16 shiftleft lpower 2.277088275290811 0.9624044038708768
17 shiftleft denergy 1.4931073444617051 0.9454881696599784
18 comparator delay 6.680678539086959 0.9397668550976327 0.98789326603378
19 comparator area 0.6003877936704982 0.9672416909621802
20 comparator lpower 0.46756802348373877 0.8609362596824635
21 comparator denergy 0.3089180049610159 0.8267293340232036
22 flop delay 3.3270503187614153 0.0
23 flop area 0.34478305655859876 0.9433629202566682
24 flop lpower 0.3707856336608904 0.9170347531086821
25 flop denergy 0.0011765517257429892 0.688648230209356
26 mux2 delay 4.732514086885074 0.38138175938205005 0.5638177354804589
27 mux2 area 0.19794547955000782 0.9753613114571431
28 mux2 lpower 0.1881638557015794 0.7572248871637561
29 mux2 denergy 0.16278100836605952 0.9811112115671446
30 mux4 delay 5.67790744523475 0.5081925137582493 0.8316415055210026
31 mux4 area 0.35778033738856435 0.9880049722019894
32 mux4 lpower 0.32236674794207065 0.8279138454959137
33 mux4 denergy 0.28073375091037084 0.9943662618662574
34 mux8 delay 7.252700330388384 0.45254210999717837 0.8464368692304263
35 mux8 area 0.7614128432326613 0.9863118376555963
36 mux8 lpower 0.6570734849206145 0.9855956038468652
37 mux8 denergy 0.4496346388149245 0.9785597135426944
38 mult delay 29.562138166420393 6.711916207386673 0.9833266087176287
39 mult area 13.838943348894976 0.9875861886135875
40 mult lpower 14.380577146903335 0.9349609233308782
41 mult denergy 36.51397409545879 0.9719012952478829