From a89e68952028af318619f981cfbf62cb00d39538 Mon Sep 17 00:00:00 2001 From: Madeleine Masser-Frye <51804758+mmasserfrye@users.noreply.github.com> Date: Fri, 17 Jun 2022 19:36:32 +0000 Subject: [PATCH] error calculation function, fixed energy units --- synthDC/ppaAnalyze.py | 167 +++++++++++++++++++---------------------- synthDC/ppaFitting.csv | 122 ++++++++++++++++++++---------- 2 files changed, 158 insertions(+), 131 deletions(-) diff --git a/synthDC/ppaAnalyze.py b/synthDC/ppaAnalyze.py index 6205011d..db97d0f9 100755 --- a/synthDC/ppaAnalyze.py +++ b/synthDC/ppaAnalyze.py @@ -41,7 +41,7 @@ def synthsintocsv(): file = open("ppaData.csv", "w") writer = csv.writer(file) - writer.writerow(['Module', 'Tech', 'Width', 'Target Freq', 'Delay', 'Area', 'L Power (nW)', 'D energy (fJ)']) + writer.writerow(['Module', 'Tech', 'Width', 'Target Freq', 'Delay', 'Area', 'L Power (nW)', 'D energy (nJ)']) for oneSynth in allSynths: module, width, risc, tech, freq = specReg.findall(oneSynth)[2:7] @@ -60,7 +60,7 @@ def synthsintocsv(): delay = 1000/int(freq) - metrics[0] area = metrics[1] lpower = metrics[4] - denergy = (metrics[2] + metrics[3])/int(freq) # (switching + internal powers)*delay, more practical units for regression coefs + denergy = (metrics[2] + metrics[3])/int(freq)*1000 # (switching + internal powers)*delay, more practical units for regression coefs if ('flop' in module): # since two flops in each module [area, lpower, denergy] = [n/2 for n in [area, lpower, denergy]] @@ -85,7 +85,7 @@ def cleanup(): 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']]: + for phrase in [['Path Length', 'qor']]: bashCommand = 'grep "{}" '+ oneSynth[2:]+'/reports/*{}*' bashCommand = bashCommand.format(*phrase) try: output = subprocess.check_output(['bash','-c', bashCommand]) @@ -131,54 +131,18 @@ def csvOfBest(filename): for w in widths: m = np.Inf # large number to start best = None - if ([mod, tech, w] in leftblue): - for oneSynth in allSynths: # leftmost blue - if (oneSynth.width == w) & (oneSynth.tech == tech) & (oneSynth.module == mod): - if (oneSynth.freq < m) & (1000/oneSynth.delay < oneSynth.freq): - # if ([mod, tech, w] != ['mux2', 'sky90', 128]) or (oneSynth.area < 1100): - m = oneSynth.freq - best = oneSynth - else: - for oneSynth in allSynths: # best achievable, rightmost green - if (oneSynth.width == w) & (oneSynth.tech == tech) & (oneSynth.module == mod): - if (oneSynth.delay < m) & (1000/oneSynth.delay > oneSynth.freq): - m = oneSynth.delay - best = oneSynth - # contenders = [] - # delays = [] - # for oneSynth in allSynths: # choose synth w minimal delay - # if (oneSynth.width == w) & (oneSynth.tech == tech) & (oneSynth.module == mod): - # contenders += [oneSynth] - # delays += [oneSynth.delay] - # if oneSynth.delay < m: - # m = oneSynth.delay - # best = oneSynth - - # for oneSynth in contenders: # if m is min delay, choose best area within s as percent of m - # s = oneSynth.delay/m - 1 - # if s < 0.1: - # if oneSynth.area < best.area: - # best = oneSynth - - # bestval = 1.9 # score algorithm - # for oneSynth in contenders: - # delaydif = abs(1 - oneSynth.delay/best.delay) - # areadif = 1 - oneSynth.area/best.area - # try: val = areadif/delaydif - # except: val = 1 - # # if (oneSynth.width == 64) & (oneSynth.tech == 'sky90') & (oneSynth.module == 'comparator'): - # # print(oneSynth.freq, ' ', delaydif, ' ', areadif, ' ', val) - # if val > bestval: - # bestval = val - # best = oneSynth + for oneSynth in allSynths: # best achievable, rightmost green + if (oneSynth.width == w) & (oneSynth.tech == tech) & (oneSynth.module == mod): + if (oneSynth.delay < m) & (1000/oneSynth.delay > oneSynth.freq): + m = oneSynth.delay + best = oneSynth if (best != None) & (best not in bestSynths): bestSynths += [best] - file = open(filename, "w") writer = csv.writer(file) - writer.writerow(['Module', 'Tech', 'Width', 'Target Freq', 'Delay', 'Area', 'L Power (nW)', 'D energy (fJ)']) + writer.writerow(['Module', 'Tech', 'Width', 'Target Freq', 'Delay', 'Area', 'L Power (nW)', 'D energy (nJ)']) for synth in bestSynths: writer.writerow(list(synth)) file.close() @@ -265,7 +229,7 @@ def oneMetricPlot(module, var, freq=None, ax=None, fits='clsgn', norm=True, colo if norm: ylabeldic = {"lpower": "Leakage Power (add32)", "denergy": "Energy/Op (add32)", "area": "Area (add32)", "delay": "Delay (FO4)"} else: - ylabeldic = {"lpower": "Leakage Power (nW)", "denergy": "Dynamic Energy (fJ)", "area": "Area (sq microns)", "delay": "Delay (ns)"} + ylabeldic = {"lpower": "Leakage Power (nW)", "denergy": "Dynamic Energy (nJ)", "area": "Area (sq microns)", "delay": "Delay (ns)"} ax.set_ylabel(ylabeldic[var]) ax.set_xticks(widths) @@ -549,13 +513,12 @@ def squarify(fig): l = (1.-axs/h)/2 fig.subplots_adjust(bottom=l, top=1-l) - def plotPPA(mod, freq=None, norm=True, aleOpt=False): ''' for the module specified, plots width vs delay, area, leakage power, and dynamic energy with fits if no freq specified, uses the synthesis with best achievable delay for each width overlays data from both techs ''' - plt.rcParams["figure.figsize"] = (7,3.6) + plt.rcParams["figure.figsize"] = (7,3.46) fig, axs = plt.subplots(2, 2) arr = [['delay', 'area'], ['lpower', 'denergy']] @@ -591,13 +554,7 @@ def plotPPA(mod, freq=None, norm=True, aleOpt=False): plt.savefig(saveStr) # plt.show() -def plotBestAreas(mod): - fig, axs = plt.subplots(1, 1) - oneMetricPlot(mod, 'area', freq=10) - plt.title(mod + ' Optimized Areas (target freq 10MHz)') - plt.savefig('./plots/bestAreas/' + mod + '.png') - -def makeDaLegend(): +def makeLineLegend(): plt.rcParams["figure.figsize"] = (5.5,0.3) fig = plt.figure() fullLeg = [lines.Line2D([0], [0], color='black', label='fastest', linestyle='-')] @@ -609,25 +566,6 @@ def makeDaLegend(): saveStr = './plots/PPA/legend.png' plt.savefig(saveStr) -def calcAvgRsq(): - with open('ppaFitting.csv', newline='') as csvfile: - csvreader = csv.reader(csvfile) - allSynths = list(csvreader)[1:] - csvfile.close() - - others = [] - muxes = [] - - for synth in allSynths: - if ('easy' not in synth) or ('delay' not in synth): - if 'mux' in synth[0]: - muxes += [float(synth[8])] - elif '0.0' != synth[8]: - others += [float(synth[8])] - - print('Others: ', np.mean(others)) - print('Muxes: ', np.mean(muxes)) - def muxPlot(fits='clsgn', norm=True): ''' module: string module name freq: int freq (MHz) @@ -660,6 +598,7 @@ def muxPlot(fits='clsgn', norm=True): techdict = spec._asdict() norm = techdict['delay'] metric = [m/norm for m in metric] + # print(spec.tech, ' ', metric) if len(metric) == 3: # don't include the spec if we don't have points for all xp, pred, coefs, r2 = regress(inputs, metric, fits, ale=False) @@ -679,23 +618,71 @@ def muxPlot(fits='clsgn', norm=True): ax.legend(handles = fullLeg) plt.savefig('./plots/PPA/mux.png') +def stdDevError(): + for var in ['delay', 'area', 'lpower', 'denergy']: + errlist = [] + for module in modules: + ale = (var != 'delay') + metL = [] + modFit = fitDict[module] + fits = modFit[ale] + funcArr = genFuncs(fits) + + for spec in techSpecs: + metric = getVals(spec.tech, module, var) + techdict = spec._asdict() + norm = techdict[var] + metL += [m/norm for m in metric] + + if ale: + ws = [w/normAddWidth for w in widths] + else: + ws = widths + ws = ws*2 + mat = [] + for w in ws: + row = [] + for func in funcArr: + row += [func(w)] + mat += [row] + + y = np.array(metL, dtype=np.float) + coefs = opt.nnls(mat, y)[0] + + yp = [] + for w in ws: + n = [func(w) for func in funcArr] + yp += [sum(np.multiply(coefs, n))] + + if (var == 'delay') & (module == 'flop'): + pass + elif (module == 'mult') & ale: + pass + else: + for i in range(len(y)): + errlist += [abs(y[i]/yp[i]-1)] + # print(module, ' ', var, ' ', np.mean(errlist[-10:])) + + avgErr = np.mean(errlist) + stdv = np.std(errlist) + + print(var, ' ', avgErr, ' ', stdv) + if __name__ == '__main__': ############################## # set up stuff, global variables widths = [8, 16, 32, 64, 128] - modules = ['priorityencoder', 'add', 'csa', 'shiftleft', 'comparator', 'flop', 'mux2', 'mux4', 'mux8', 'mult'] # 'mux2d', 'mux4d', 'mux8d'] + modules = ['priorityencoder', 'add', 'csa', 'shiftleft', 'comparator', 'flop', 'mux2', 'mux4', 'mux8', 'mult'] #, 'mux2d', 'mux4d', 'mux8d'] normAddWidth = 32 # divisor to use with N since normalizing to add_32 - fitDict = {'add': ['cg', 'l', 'l'], 'mult': ['cg', 'ls', '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', 's'], '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'])) - leftblue = [] #[['mux2', 'tsmc28', 8], ['mux4', 'sky90', 16]] 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, 1440.600027, 714.057, 0.658022690438], ['tsmc28', 'blue', '^', 12.2e-3, 209.286002, 1060.0, .08153281695882594]] techSpecs = [TechSpec(*t) for t in techSpecs] combined = TechSpec('combined fit', 'red', '_', 0, 0, 0, 0) - # invz1arealeakage = [['sky90', 1.96, 1.98], ['gf32', .351, .3116], ['tsmc28', .252, 1.09]] #['gf32', 'purple', 's', 15e-3] ############################## # cleanup() # run to remove garbage synth runs @@ -704,21 +691,21 @@ if __name__ == '__main__': allSynths = synthsfromcsv('ppaData.csv') # your csv here! bestSynths = csvOfBest('bestSynths.csv') - # ### plotting examples + # ### function examples # squareAreaDelay('sky90', 'add', 32) - # oneMetricPlot('add', 'area') + # oneMetricPlot('mult', 'lpower') # freqPlot('sky90', 'mux4', 16) # plotBestAreas('add') # makeCoefTable() - # calcAvgRsq() # makeEqTable() - # makeDaLegend() + # makeLineLegend() # muxPlot() + # stdDevError() - # for mod in modules: - # # plotPPA(mod, norm=False) - # # plotPPA(mod, aleOpt=True) - # for w in widths: - # freqPlot('sky90', mod, w) - # freqPlot('tsmc28', mod, w) - # plt.close('all') \ No newline at end of file + for mod in modules: + plotPPA(mod, norm=False) + plotPPA(mod, aleOpt=True) + for w in widths: + freqPlot('sky90', mod, w) + freqPlot('tsmc28', mod, w) + plt.close('all') \ No newline at end of file diff --git a/synthDC/ppaFitting.csv b/synthDC/ppaFitting.csv index def67c07..ef4159ec 100644 --- a/synthDC/ppaFitting.csv +++ b/synthDC/ppaFitting.csv @@ -1,41 +1,81 @@ -Module,Metric,1,N,N^2,log2(N),Nlog2(N),R^2 -priorityencoder,delay,4.865032478368464,,,1.0346781590203091,,0.990533246983837 -priorityencoder,area,,0.3296349181169891,,,,0.9718942704677337 -priorityencoder,lpower,,0.2508481588069769,,,,0.9418329012771585 -priorityencoder,denergy,,0.09327161156406552,,,,0.8065924672945542 -add,delay,8.961254531683414,,,1.4310340215065527,,0.9564367595740637 -add,area,,1.0710989265923485,,,,0.988580182173048 -add,lpower,,0.9470245397661955,,,,0.9951383820581323 -add,denergy,,0.9954952282287014,,,,0.9928308616130285 -csa,delay,3.590384717869601,,,,,0.0 -csa,area,,0.9312877569527923,,,,0.999393942859829 -csa,lpower,,1.5320774877598933,,,,0.9400384192534433 -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 +Module,Metric,Target,1,N,N^2,log2(N),Nlog2(N),R^2 +priorityencoder,delay,easy,0.0,,,6.815655848737334,,0.5471505976585844 +priorityencoder,area,easy,,0.14996313076366272,,,,0.9751246139683207 +priorityencoder,lpower,easy,,0.04628232776780845,,,,0.6646449382421588 +priorityencoder,denergy,easy,,0.00046338953826781273,,,,0.8843605490100168 +priorityencoder,delay,hard,0.0,,,0.9775747670327015,,0.987274834491306 +priorityencoder,area,hard,,0.3296349181169891,,,,0.9718942704677337 +priorityencoder,lpower,hard,,0.2508481588069769,,,,0.9418329012771585 +priorityencoder,denergy,hard,,0.09327161156406552,,,,0.8065924672945542 +add,delay,easy,0.0,,,27.820556626526365,,0.5330240516496716 +add,area,easy,,0.33740563909904386,,,,0.9968636684818916 +add,lpower,easy,,0.1559461482654009,,,,0.7403794995975848 +add,denergy,easy,,0.025219887569037786,,,,0.6462978476180771 +add,delay,hard,1.8060844241506506,,,1.4310340215065525,,0.9564367595740637 +add,area,hard,,1.0710989265923485,,,,0.988580182173048 +add,lpower,hard,,0.9470245397661955,,,,0.9951383820581323 +add,denergy,hard,,0.9954952282287014,,,,0.9928308616130285 +csa,delay,easy,5.827386725865409,,,,,0.0 +csa,area,easy,,0.3404841239399024,,,,0.9966821820865757 +csa,lpower,easy,,0.1555300133584381,,,,0.7410756093594764 +csa,denergy,easy,,0.0005478126632729184,,,,0.5798854696439455 +csa,delay,hard,3.590384717869601,,,,,0.0 +csa,area,hard,,0.9312877569527923,,,,0.9993939428598292 +csa,lpower,hard,,1.5320774877598933,,,,0.9400384192534433 +csa,denergy,hard,,1.1454135769936609,,,,0.9735205275004183 +shiftleft,delay,easy,0.0,,,5.744537363106859,,0.7778961884907117 +shiftleft,area,easy,,0.8000093911038876,,,,0.9576897492378456 +shiftleft,lpower,easy,,0.28913702096331206,,,,0.623995386847899 +shiftleft,denergy,easy,,0.005924456057944899,,,,0.7200057939838627 +shiftleft,delay,hard,0.48433873118517795,,,1.635171191349943,,0.9873681453602638 +shiftleft,area,hard,,1.9102134686740575,,,,0.9466461680123697 +shiftleft,lpower,hard,,2.277088275290811,,,,0.9624044038708768 +shiftleft,denergy,hard,,1.4931073444617051,,,,0.9454881696599784 +comparator,delay,easy,0.0,,,4.706704191403,,0.5450694752498024 +comparator,area,easy,,0.3425601443761704,,,,0.978537426983507 +comparator,lpower,easy,,0.15525826941742596,,,,0.8078417286943447 +comparator,denergy,easy,,0.0008896717814426517,,,,0.9267090446396561 +comparator,delay,hard,1.9818442635987938,,,0.9397668550976329,,0.9878932660337799 +comparator,area,hard,,0.6003877936704982,,,,0.9672416909621802 +comparator,lpower,hard,,0.46756802348373877,,,,0.8609362596824635 +comparator,denergy,hard,,0.3089180049610159,,,,0.8267293340232036 +flop,delay,easy,3.3270503187614153,,,,,0.0 +flop,area,easy,,0.34478305655859876,,,,0.9433629202566682 +flop,lpower,easy,,0.3707856336608904,,,,0.9170347531086821 +flop,denergy,easy,,0.0011765517257429892,,,,0.688648230209356 +flop,delay,hard,3.3270503187614153,,,,,0.0 +flop,area,hard,,0.34478305655859876,,,,0.9433629202566682 +flop,lpower,hard,,0.3707856336608904,,,,0.9170347531086821 +flop,denergy,hard,,0.0011765517257429892,,,,0.688648230209356 +mux2,delay,easy,0.0,,,3.276654474184255,,0.7130397298335213 +mux2,area,easy,,0.15083561354737726,,,,0.976644158286422 +mux2,lpower,easy,,0.12067626255418841,,,,0.9344813545348312 +mux2,denergy,easy,,0.0011206170933885473,,,,0.5565267433319017 +mux2,delay,hard,2.539326242287272,,,0.4143154417811283,,0.550540330173853 +mux2,area,hard,,0.2261714754439734,,,,0.9792793539936671 +mux2,lpower,hard,,0.27830936017352714,,,,0.9042661125086188 +mux2,denergy,hard,,0.19333666277894856,,,,0.9525189311701613 +mux4,delay,easy,0.0,,,3.934462222278399,,0.5700865267151127 +mux4,area,easy,,0.2839183647889992,,,,0.9755791039549218 +mux4,lpower,easy,,0.11187597259171647,,,,0.5559362399863286 +mux4,denergy,easy,,0.0021483489610266407,,,,0.5348528431713737 +mux4,delay,hard,3.1369448764435073,,,0.5081925137582488,,0.8316415055210026 +mux4,area,hard,,0.35778033738856435,,,,0.9880049722019894 +mux4,lpower,hard,,0.32236674794207065,,,,0.8279138454959137 +mux4,denergy,hard,,0.28073375091037084,,,,0.9943662618662574 +mux8,delay,easy,0.0,,,4.439779694843578,,0.6601108415004824 +mux8,area,easy,,0.5486426664163658,,,,0.9756934275959698 +mux8,lpower,easy,,0.2380559585648822,,,,0.5468728724048277 +mux8,denergy,easy,,0.0029053391137917966,,,,0.5231276299250225 +mux8,delay,hard,4.9490961359025585,,,0.45254210999717775,,0.8846872287553096 +mux8,area,hard,,0.7645051946159651,,,,0.9834986761377894 +mux8,lpower,hard,,0.6697504633436362,,,,0.9599639296705227 +mux8,denergy,hard,,0.4542825975429124,,,,0.9698068520398291 +mult,delay,easy,0.0,,,61.777235436483835,,0.539191885251039 +mult,area,easy,,1.1322969325198273,7.852086512913157,,,0.997120506119588 +mult,lpower,easy,,1.0320514230056876,3.411671281132248,,,0.7465081509218953 +mult,denergy,easy,,0.0,2.146924193738219,,,0.8988257654810033 +mult,delay,hard,0.0,,,5.971649009143529,,0.9704083045351518 +mult,area,hard,,13.296909763669026,10.2773763878058,,,0.9969630019304513 +mult,lpower,hard,,26.397088944265164,7.310137358727654,,,0.9703772416232848 +mult,denergy,hard,,41.5120348723692,25.39500777044283,,,0.9849195751440497