blob: 5ab2ce9d73d9d263fee29c18462a8cdafaba2902 [file] [log] [blame]
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001import argparse
2import sqlite3
3import re
4import pandas as pd
5import numpy as np
Christophe Favergeoned0eab82020-05-18 08:43:38 +02006from TestScripts.doc.Structure import *
7from TestScripts.doc.Format import *
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02008import os.path
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02009
Christophe Favergeon1ff54582020-08-18 14:47:01 +020010refCoreName=""
11
Christophe Favergeon670b1672020-05-28 12:47:58 +020012runidCMD = "runid = ?"
Christophe Favergeonc3f455c2020-05-14 09:24:07 +020013
Christophe Favergeon8cb37302020-05-13 13:06:58 +020014# Command to get last runid
15lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1
16"""
17
Christophe Favergeone15894e2020-05-14 07:25:53 +020018# Command to get last runid and date
19lastIDAndDate="""SELECT date FROM RUN WHERE runid=?
20"""
21
Christophe Favergeonfe27d872020-07-31 07:20:18 +020022# Command to get last runid
23runIDDetails="""SELECT distinct core FROM %s
24INNER JOIN CORE USING(coreid)
25WHERE %s
26"""
27
Christophe Favergeon0e0449a2020-07-28 09:44:14 +020028def joinit(iterable, delimiter):
29 # Intersperse a delimiter between element of a list
30 it = iter(iterable)
31 yield next(it)
32 for x in it:
33 yield delimiter
34 yield x
35
36
Christophe Favergeon8cb37302020-05-13 13:06:58 +020037def getLastRunID():
38 r=c.execute(lastID)
39 return(int(r.fetchone()[0]))
40
Christophe Favergeone15894e2020-05-14 07:25:53 +020041def getrunIDDate(forID):
42 r=c.execute(lastIDAndDate,(forID,))
43 return(r.fetchone()[0])
Christophe Favergeon8cb37302020-05-13 13:06:58 +020044
Christophe Favergeonfe27d872020-07-31 07:20:18 +020045
46
Christophe Favergeon8cb37302020-05-13 13:06:58 +020047
48parser = argparse.ArgumentParser(description='Generate summary benchmarks')
49
Christophe Favergeonfeb73932020-05-20 14:48:06 +020050parser.add_argument('-b', nargs='?',type = str, default="bench.db", help="Database")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020051parser.add_argument('-o', nargs='?',type = str, default="full.md", help="Full summary")
52parser.add_argument('-r', action='store_true', help="Regression database")
Christophe Favergeonfe27d872020-07-31 07:20:18 +020053parser.add_argument('-t', nargs='?',type = str, default="md", help="type md or html")
54parser.add_argument('-byc', action='store_true', help="Result oganized by Compiler")
Christophe Favergeon670b1672020-05-28 12:47:58 +020055parser.add_argument('-g', action='store_true', help="Include graphs in regression report")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020056
Christophe Favergeonfe27d872020-07-31 07:20:18 +020057parser.add_argument('-details', action='store_true', help="Details about runids")
58parser.add_argument('-lastid', action='store_true', help="Get last ID")
Christophe Favergeon66de4ac2020-07-31 13:38:09 +020059parser.add_argument('-comments', nargs='?',type = str, default="comments.txt", help="Comment section")
Christophe Favergeonf1a87802020-08-17 07:36:05 +020060parser.add_argument('-byd', action='store_true', help="Result oganized by datatype")
Christophe Favergeon1ff54582020-08-18 14:47:01 +020061parser.add_argument('-ratio', action='store_true', help="Compute ratios for regression by core instead of cycles")
62parser.add_argument('-ref', nargs='?',type = str, default="M55", help="Reference COREDEF for ratio in db")
63parser.add_argument('-clampval', nargs='?',type = float, default=8.0, help="Clamp for ratio")
64parser.add_argument('-clamp', action='store_true', help="Clamp enabled for ratio")
65parser.add_argument('-keep', nargs='?',type = str, help="Core to keep for ratio")
Christophe Favergeonfe27d872020-07-31 07:20:18 +020066
Christophe Favergeon8cb37302020-05-13 13:06:58 +020067# For runid or runid range
Christophe Favergeon4fa1e232020-05-15 12:28:17 +020068parser.add_argument('others', nargs=argparse.REMAINDER,help="Run ID")
Christophe Favergeon8cb37302020-05-13 13:06:58 +020069
70args = parser.parse_args()
71
72c = sqlite3.connect(args.b)
73
74if args.others:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020075 vals=[]
76 runidCMD=[]
77 runidHeader=[]
Christophe Favergeon1ff54582020-08-18 14:47:01 +020078 runidVIEWcmd=[]
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020079 for t in args.others:
80 if re.search(r'-',t):
81 bounds=[int(x) for x in t.split("-")]
82 vals += bounds
83 runidHeader += ["%d <= runid <= %d" % tuple(bounds)]
84 runidCMD += ["(runid >= ? AND runid <= ?)"]
Christophe Favergeon1ff54582020-08-18 14:47:01 +020085 runidVIEWcmd += ["(runid >= %d AND runid <= %d) " % tuple(bounds)]
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020086 else:
87 theid=int(t)
88 runidHeader += ["runid == %d" % theid]
89 runidCMD += ["runid == ?"]
Christophe Favergeon1ff54582020-08-18 14:47:01 +020090 runidVIEWcmd += ["runid == %d" % theid]
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020091 vals.append(theid)
92
93 runidval = tuple(vals)
Christophe Favergeon1ff54582020-08-18 14:47:01 +020094 runidHeader = "(" + "".join(joinit(runidHeader," OR ")) + ")"
95 runidCMD = "(" + "".join(joinit(runidCMD," OR ")) + ")"
96 runidVIEWcmd = "(" + "".join(joinit(runidVIEWcmd," OR ")) + ")"
Christophe Favergeon8cb37302020-05-13 13:06:58 +020097else:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +020098 theid=getLastRunID()
99 print("Last run ID = %d\n" % theid)
100 runidval=(theid,)
101 runidHeader="%d" % theid
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200102 runidVIEWcmd="(runid = %d)" % theid
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200103
Christophe Favergeonfe27d872020-07-31 07:20:18 +0200104
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200105# We extract data only from data tables
106# Those tables below are used for descriptions
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200107REMOVETABLES=['TESTNAME','TESTDATE','RUN','CORE', 'PLATFORM', 'COMPILERKIND', 'COMPILER', 'TYPE', 'CATEGORY', 'CONFIG']
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200108
109# This is assuming the database is generated by the regression script
110# So platform is the same for all benchmarks.
111# Category and type is coming from the test name in the yaml
112# So no need to add this information here
113# Name is removed here because it is added at the beginning
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200114REMOVECOLUMNS=['runid','name','type','platform','category','coredef','OPTIMIZED','HARDFP','FASTMATH','NEON','HELIUM','UNROLL','ROUNDING','DATE','compilerkindid','date','categoryid', 'ID', 'platformid', 'coreid', 'compilerid', 'typeid']
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200115
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200116REMOVECOLUMNSFORHISTORY=['Regression','MAXREGCOEF','name','type','platform','category','coredef','OPTIMIZED','HARDFP','FASTMATH','NEON','HELIUM','UNROLL','ROUNDING','DATE','compilerkindid','date','categoryid', 'ID', 'platformid', 'coreid', 'compilerid', 'typeid']
117
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200118# Get existing benchmark tables
119def getBenchTables():
120 r=c.execute("SELECT name FROM sqlite_master WHERE type='table'")
121 benchtables=[]
122 for table in r:
123 if not table[0] in REMOVETABLES:
124 benchtables.append(table[0])
125 return(benchtables)
126
127# get existing types in a table
128def getExistingTypes(benchTable):
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200129 r=c.execute("select distinct typeid from %s WHERE %s order by typeid desc " % (benchTable,runidCMD),runidval).fetchall()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200130 result=[x[0] for x in r]
131 return(result)
132
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200133# Get existing cores in a table
134def getAllExistingCores(benchTable):
135 r=c.execute("select distinct coreid from %s WHERE %s order by coreid desc " % (benchTable,runidCMD),runidval).fetchall()
136 result=[x[0] for x in r]
137 return(result)
138
Christophe Favergeonfe27d872020-07-31 07:20:18 +0200139def getrunIDDetails():
140 tables=getBenchTables()
141 r=[]
142 for table in tables:
143 r += [x[0] for x in c.execute(runIDDetails % (table,runidCMD),runidval).fetchall()]
144 r=list(set(r))
145 print(r)
146
147if args.lastid:
148 quit()
149
150if args.details:
151 getrunIDDetails()
152 quit()
153
154
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200155# Get compilers from specific type and table
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200156allCompilers="""select distinct compilerid from %s WHERE typeid=?"""
157
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200158# Get compilers from specific type and table
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200159allCompilerForCore="""select distinct compilerid from %s WHERE coreid=?"""
160
161# Get compilers from specific type and table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200162allCores="""select distinct coreid from %s WHERE typeid=? AND (%s)"""
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200163
164
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200165compilerDesc="""select compiler,version from COMPILER
166 INNER JOIN COMPILERKIND USING(compilerkindid) WHERE compilerid=?"""
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200167
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200168coreDesc="""select core from CORE WHERE coreid=?"""
169
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200170# Get existing compiler in a table for a specific type
171# (In case report is structured by types)
172def getExistingCompiler(benchTable,typeid):
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200173 r=c.execute(allCompilers % benchTable,(typeid,)).fetchall()
174 return([x[0] for x in r])
175
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200176
177# Get existing compiler in a table for a specific core
178# (In case report is structured by core)
179def getExistingCompilerForCore(benchTable,coreid):
180 r=c.execute(allCompilerForCore % benchTable,(coreid,)).fetchall()
181 return([x[0] for x in r])
182
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200183def getExistingCores(benchTable,typeid):
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200184 vals = (typeid,) + runidval
185 r=c.execute(allCores % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200186 return([x[0] for x in r])
187
188
189
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200190def getCoreDesc(coreid):
191 r=c.execute(coreDesc,(coreid,)).fetchone()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200192 return(r)
193
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200194def getCompilerDesc(compilerid):
195 r=c.execute(compilerDesc,(compilerid,)).fetchone()
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200196 return(r)
197
198# Get type name from type id
199def getTypeName(typeid):
200 r=c.execute("select type from TYPE where typeid=?",(typeid,)).fetchone()
201 return(r[0])
202
203# Diff of 2 lists
204def diff(first, second):
205 second = set(second)
206 return [item for item in first if item not in second]
207
208
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200209# Command to get data for specific compiler
210# and type
211benchCmdForCoreCompiler="""select %s from %s
212 INNER JOIN CATEGORY USING(categoryid)
213 INNER JOIN PLATFORM USING(platformid)
214 INNER JOIN CORE USING(coreid)
215 INNER JOIN COMPILER USING(compilerid)
216 INNER JOIN COMPILERKIND USING(compilerkindid)
217 INNER JOIN TYPE USING(typeid)
218 INNER JOIN TESTNAME USING(testnameid)
219 WHERE coreid=? AND compilerid = ? AND (%s)
220 """
221
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200222# Command to get data for specific core
223# and type
224historyCmd="""select %s from %s
225 INNER JOIN CATEGORY USING(categoryid)
226 INNER JOIN PLATFORM USING(platformid)
227 INNER JOIN CORE USING(coreid)
228 INNER JOIN COMPILER USING(compilerid)
229 INNER JOIN COMPILERKIND USING(compilerkindid)
230 INNER JOIN TYPE USING(typeid)
231 INNER JOIN TESTNAME USING(testnameid)
232 WHERE compilerid=? AND coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
233 """
234
235compilersForHistory="""select distinct compilerid,compiler,version from %s
236 INNER JOIN COMPILER USING(compilerid)
237 INNER JOIN COMPILERKIND USING(compilerkindid)
238 WHERE coreid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
239 """
240
241# Command to get data for specific core
242# and type
243benchCmdForCore="""select %s from %s
244 INNER JOIN CATEGORY USING(categoryid)
245 INNER JOIN PLATFORM USING(platformid)
246 INNER JOIN CORE USING(coreid)
247 INNER JOIN COMPILER USING(compilerid)
248 INNER JOIN COMPILERKIND USING(compilerkindid)
249 INNER JOIN TYPE USING(typeid)
250 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200251 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200252 """
253
254coresForHistory="""select distinct coreid,core from %s
255 INNER JOIN CORE USING(coreid)
256 WHERE compilerid=? AND typeid = ? AND ID = ? AND runid > (? - 10)
257 """
258
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200259# Command to get data for specific compiler
260# and type
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200261benchCmdForCompiler="""select %s from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200262 INNER JOIN CATEGORY USING(categoryid)
263 INNER JOIN PLATFORM USING(platformid)
264 INNER JOIN CORE USING(coreid)
265 INNER JOIN COMPILER USING(compilerid)
266 INNER JOIN COMPILERKIND USING(compilerkindid)
267 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200268 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200269 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200270 """
271
272# Command to get test names for specific compiler
273# and type
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200274benchNamesForCore="""select distinct name from %s
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200275 INNER JOIN COMPILER USING(compilerid)
276 INNER JOIN COMPILERKIND USING(compilerkindid)
277 INNER JOIN TYPE USING(typeid)
278 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200279 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200280 """
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200281
282# Command to get test names for specific core
283# and compiler
284benchNamesForCoreCompiler="""select distinct name from %s
285 INNER JOIN COMPILER USING(compilerid)
286 INNER JOIN COMPILERKIND USING(compilerkindid)
287 INNER JOIN TYPE USING(typeid)
288 INNER JOIN TESTNAME USING(testnameid)
289 WHERE coreid=? AND compilerid = ? AND (%s)
290 """
291
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200292# Command to get test names for specific compiler
293# and type
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200294benchNamesForCompiler="""select distinct name from %s
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200295 INNER JOIN COMPILER USING(compilerid)
296 INNER JOIN COMPILERKIND USING(compilerkindid)
297 INNER JOIN TYPE USING(typeid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200298 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200299 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200300 """
301
302# Command to get columns for specific table
303benchCmdColumns="""select * from %s
304 INNER JOIN CATEGORY USING(categoryid)
305 INNER JOIN PLATFORM USING(platformid)
306 INNER JOIN CORE USING(coreid)
307 INNER JOIN COMPILER USING(compilerid)
308 INNER JOIN COMPILERKIND USING(compilerkindid)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200309 INNER JOIN TESTNAME USING(testnameid)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200310 INNER JOIN TYPE USING(typeid)
311 """
312
313def joinit(iterable, delimiter):
314 it = iter(iterable)
315 yield next(it)
316 for x in it:
317 yield delimiter
318 yield x
319
320# Is not a column name finishing by id
321# (often primary key for thetable)
322def isNotIDColumn(col):
323 if re.match(r'^.*id$',col):
324 return(False)
325 else:
326 return(True)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200327
328# Get test names
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200329# for specific core and compiler (for the data)
330def getTestNamesForCoreCompiler(benchTable,compilerid,core):
331 vals=(core,compilerid) + runidval
332 result=c.execute(benchNamesForCoreCompiler % (benchTable,runidCMD),vals).fetchall()
333 names=[x[0] for x in list(result)]
334 return(names)
335
336# Get test names
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200337# for specific typeid and core (for the data)
338def getTestNamesForCore(benchTable,core,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200339 vals=(core,typeid) + runidval
340 result=c.execute(benchNamesForCore % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200341 names=[x[0] for x in list(result)]
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200342 return(names)
343
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200344# Get test names
345# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200346def getTestNamesForCompiler(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200347 vals=(comp,typeid) + runidval
348 result=c.execute(benchNamesForCompiler % (benchTable,runidCMD),vals).fetchall()
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200349 names=[x[0] for x in list(result)]
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200350 return(names)
351
352# Command to get data for specific core
353# and type
354nbElemsInBenchAndTypeAndCoreCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200355 WHERE coreid=? AND typeid = ? AND (%s)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200356 """
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200357
Christophe Favergeone15894e2020-05-14 07:25:53 +0200358# Command to get data for specific compiler
359# and type
360nbElemsInBenchAndTypeAndCompilerCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200361 WHERE compilerid=? AND typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200362 """
363
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200364# Command to get data for specific compiler
365# and type
366nbElemsInBenchAndCoreAndCompilerCmd="""select count(*) from %s
367 WHERE compilerid=? AND coreid = ? AND (%s)
368 """
369
Christophe Favergeone15894e2020-05-14 07:25:53 +0200370nbElemsInBenchAndTypeCmd="""select count(*) from %s
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200371 WHERE typeid = ? AND (%s)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200372 """
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200373nbElemsInBenchAndCoreCmd="""select count(*) from %s
374 WHERE coreid = ? AND (%s)
375 """
Christophe Favergeone15894e2020-05-14 07:25:53 +0200376
377nbElemsInBenchCmd="""select count(*) from %s
Christophe Favergeon670b1672020-05-28 12:47:58 +0200378 WHERE %s
Christophe Favergeone15894e2020-05-14 07:25:53 +0200379 """
380
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200381categoryName="""select distinct category from %s
382 INNER JOIN CATEGORY USING(categoryid)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200383 WHERE %s
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200384 """
385
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200386def getCategoryName(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200387 result=c.execute(categoryName % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200388 return(result[0])
389
Christophe Favergeon4f750702020-05-13 15:56:15 +0200390# Get nb elems in a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200391def getNbElemsInBenchAndTypeAndCoreCmd(benchTable,coreid,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200392 vals=(coreid,typeid) + runidval
393 result=c.execute(nbElemsInBenchAndTypeAndCoreCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200394 return(result[0])
395
396# Get nb elems in a table
Christophe Favergeone15894e2020-05-14 07:25:53 +0200397def getNbElemsInBenchAndTypeAndCompilerCmd(benchTable,comp,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200398 vals=(comp,typeid) + runidval
399 result=c.execute(nbElemsInBenchAndTypeAndCompilerCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200400 return(result[0])
401
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200402# Get nb elems in a table
403def getNbElemsInBenchAndCoreAndCompilerCmd(benchTable,comp,coreid):
404 vals=(comp,coreid) + runidval
405 result=c.execute(nbElemsInBenchAndCoreAndCompilerCmd % (benchTable,runidCMD),vals).fetchone()
406 return(result[0])
407
Christophe Favergeone15894e2020-05-14 07:25:53 +0200408def getNbElemsInBenchAndTypeCmd(benchTable,typeid):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200409 vals=(typeid,) + runidval
410 result=c.execute(nbElemsInBenchAndTypeCmd % (benchTable,runidCMD),vals).fetchone()
Christophe Favergeone15894e2020-05-14 07:25:53 +0200411 return(result[0])
412
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200413def getNbElemsInBenchAndCoreCmd(benchTable,coreid):
414 vals=(coreid,) + runidval
415 result=c.execute(nbElemsInBenchAndCoreCmd % (benchTable,runidCMD),vals).fetchone()
416 return(result[0])
417
Christophe Favergeone15894e2020-05-14 07:25:53 +0200418def getNbElemsInBenchCmd(benchTable):
Christophe Favergeon670b1672020-05-28 12:47:58 +0200419 result=c.execute(nbElemsInBenchCmd % (benchTable,runidCMD),runidval).fetchone()
Christophe Favergeon4f750702020-05-13 15:56:15 +0200420 return(result[0])
421
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200422# Get names of columns and data for a table
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200423# for specific typeid and coreid (for the data)
424def getColNamesAndHistory(benchTable,compiler,core,typeid,testid):
425 cursor=c.cursor()
426 result=cursor.execute(benchCmdColumns % (benchTable))
427 cols= [member[0] for member in cursor.description]
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200428 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNSFORHISTORY) if isNotIDColumn(c)]
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200429 keepColsStr = "".join(joinit(keepCols,","))
430 vals=(compiler,core,typeid,testid,runid)
431 result=cursor.execute(historyCmd % (keepColsStr,benchTable),vals)
432 vals =np.array([list(x) for x in list(result)])
433 return(keepCols,vals)
434
435# Get names of columns and data for a table
436# for specific typeid and coreid (for the data)
437def getColNamesAndDataForCore(benchTable,core,typeid):
438 cursor=c.cursor()
439 result=cursor.execute(benchCmdColumns % (benchTable))
440 cols= [member[0] for member in cursor.description]
441 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
442 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200443 vals=(core,typeid) + runidval
444 result=cursor.execute(benchCmdForCore % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200445 vals =np.array([list(x) for x in list(result)])
446 return(keepCols,vals)
447
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200448# Get names of columns and data for a table
449# for specific coreid and compilerid (for the data)
450def getColNamesAndDataForCoreCompiler(benchTable,compilerid,core):
451 cursor=c.cursor()
452 result=cursor.execute(benchCmdColumns % (benchTable))
453 cols= [member[0] for member in cursor.description]
454 keepCols = ['name','type'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
455 keepColsStr = "".join(joinit(keepCols,","))
456 vals=(core,compilerid) + runidval
457 result=cursor.execute(benchCmdForCoreCompiler % (keepColsStr,benchTable,runidCMD),vals)
458 vals =np.array([list(x) for x in list(result)])
459 return(keepCols,vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200460
461# Get names of columns and data for a table
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200462# for specific typeid and compiler (for the data)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200463def getColNamesAndDataForCompiler(benchTable,comp,typeid):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200464 cursor=c.cursor()
465 result=cursor.execute(benchCmdColumns % (benchTable))
466 cols= [member[0] for member in cursor.description]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200467 keepCols = ['name'] + [c for c in diff(cols , REMOVECOLUMNS) if isNotIDColumn(c)]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200468 keepColsStr = "".join(joinit(keepCols,","))
Christophe Favergeon670b1672020-05-28 12:47:58 +0200469 vals=(comp,typeid) + runidval
470 result=cursor.execute(benchCmdForCompiler % (keepColsStr,benchTable,runidCMD),vals)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200471 vals =np.array([list(x) for x in list(result)])
472 return(keepCols,vals)
473
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200474
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200475
476PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
477
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200478def regressionTableFor(byname,name,section,ref,toSort,indexCols,field):
479 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200480 values=[field], aggfunc='first')
481
482 data=data.sort_values(toSort)
483
484 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200485 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200486
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200487 dataTable=Table(columns,cores)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200488 section.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200489
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200490 dataForFunc=data.loc[name]
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200491
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200492 if type(dataForFunc) is pd.DataFrame:
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200493 bars={'cols':columns,'cores':cores,'data':[]}
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200494 for row in dataForFunc.itertuples():
495 row=list(row)
496 if type(row[0]) is int:
497 row=[row[0]] + row[1:]
498 else:
499 row=list(row[0]) + row[1:]
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200500 if field=="MAXREGCOEF":
Christophe Favergeon670b1672020-05-28 12:47:58 +0200501 newrow = row
502 newrow[len(columns):] = [("%.3f" % x) for x in row[len(columns):]]
503 row=newrow
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200504 dataTable.addRow(row)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200505 bars['data'].append(row)
506 return(bars)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200507 else:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200508 if field=="MAXREGCOEF":
509 dataForFunc=[("%.3f" % x) for x in dataForFunc]
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200510 dataTable.addRow(dataForFunc)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200511 return(list(zip(cores,dataForFunc)))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200512
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200513def formatColumnName(c):
514 return("".join(joinit(c,":")))
515
516def getCoresForHistory(benchTable,compilerid,typeid,testid,runid):
517 vals=(compilerid,typeid,testid,runid)
518 result=c.execute(coresForHistory % benchTable,vals).fetchall()
519 ids=[(x[0],x[1]) for x in list(result)]
520 return(ids)
521
522def getCompilerForHistory(benchTable,coreid,typeid,testid,runid):
523 vals=(coreid,typeid,testid,runid)
524 result=c.execute(compilersForHistory % benchTable,vals).fetchall()
525 ids=[(x[0],x[1],x[2]) for x in list(result)]
526 return(ids)
527
528def getHistory(desc,testid,indexCols):
529 benchName,sectionID,typeid,runid = desc
530
531 #print(benchName)
532 #print(sectionID)
533 #print(typeid)
534 #print(testid)
535 columns = diff(indexCols,['name'])
536 #print(columns)
537 if args.byc:
538 coreid=sectionID
539 compilerids=getCompilerForHistory(benchName,coreid,typeid,testid,runid)
540 series={}
541 for compilerid,compilername,version in compilerids:
542 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
543 #print("%s:%s" % (compilername,version))
544 maxpos = result[0].index('MAX')
545 lrunid = result[0].index('runid')
546 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
547 series[corename]=r
548 hist=History(series,runid)
549 return(hist)
550 else:
551 compilerid=sectionID
552 coreids = getCoresForHistory(benchName,compilerid,typeid,testid,runid)
553 series={}
554 for coreid,corename in coreids:
555 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
556 #print(corename)
557 maxpos = result[0].index('MAX')
558 corepos = result[0].index('core')
559 lrunid = result[0].index('runid')
560 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
561 series[corename]=r
562 hist=History(series,runid)
563 return(hist)
564
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200565def convertRowToInt(r):
566 result=[]
567 for e in r:
568 if type(e) is float:
569 result.append(int(e))
570 else:
571 result.append(e)
572
573 return(result)
574
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200575def formatTableBy(desc,byname,section,typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200576 if vals.size != 0:
577 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200578 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200579
580 for param in PARAMS:
581 if param in ref.columns:
582 ref[param]=pd.to_numeric(ref[param])
583 toSort.append(param)
584 if args.r:
585 # Regression table
586 ref['MAX']=pd.to_numeric(ref['MAX'])
587 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
588
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200589 indexCols=diff(cols,byname + ['Regression','MAXREGCOEF','MAX'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200590 valList = ['Regression']
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200591
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200592 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200593 ref['CYCLES']=pd.to_numeric(ref['CYCLES']).round(decimals=0)
594
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200595 indexCols=diff(cols,byname + ['CYCLES'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200596 valList = ['CYCLES']
597
598
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200599 for name in testNames:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200600 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200601 testSection = Section(name)
602 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200603
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200604 maxCyclesSection = Section("Max cycles")
605 testSection.addSection(maxCyclesSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200606 theCycles=regressionTableFor(byname,name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon670b1672020-05-28 12:47:58 +0200607 if args.g:
608 if type(theCycles) is dict:
609 nbParams=len(theCycles['cols'])
610 for bar in theCycles['data']:
611 params=bar[0:nbParams]
612 values=bar[nbParams:]
613 title=[("%s=%s" % x) for x in list(zip(theCycles['cols'],params))]
614 title="".join(joinit(title," "))
615 sec=Section(title)
616 maxCyclesSection.addSection(sec)
617 values=list(zip(theCycles['cores'],values))
618 barChart=BarChart(values)
619 sec.addContent(barChart)
620 else:
621 #print(theCycles)
622 sec=Section("Graph")
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200623 maxCyclesSection.addSection(sec)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200624 barChart=BarChart(theCycles)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200625 sec.addContent(barChart)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200626
Christophe Favergeon670b1672020-05-28 12:47:58 +0200627 #history=getHistory(desc,testid,indexCols)
628 #testSection.addContent(history)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200629
630 regressionSection = Section("Regression")
631 testSection.addSection(regressionSection)
632 regressionTableFor(byname,name,regressionSection,ref,toSort,indexCols,'Regression')
633
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200634
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200635 maxRegCoefSection = Section("Max Reg Coef")
636 testSection.addSection(maxRegCoefSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200637 regressionTableFor(byname,name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200638
639 else:
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200640 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200641 values=valList, aggfunc='first')
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200642
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200643 data=data.sort_values(toSort)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200644
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200645 #print(list(data.columns))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200646
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200647 testSection = Section(name)
648 typeSection.addSection(testSection)
649
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200650 dataForFunc=data.loc[name]
651 dataForFunc = dataForFunc.dropna(axis=1)
652
653 columnsID = [formatColumnName(c[1:]) for c in list(dataForFunc.columns)]
654 columns = diff(indexCols,['name'])
655
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200656 dataTable=Table(columns,columnsID)
657 testSection.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200658
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200659
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200660 if type(dataForFunc) is pd.DataFrame:
661 for row in dataForFunc.itertuples():
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200662 if type(row[0]) is int:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200663 row=list([row[0]] + list(row[1:]))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200664 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200665 row=list(row[0]) + list(row[1:])
666 dataTable.addRow(convertRowToInt(row))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200667 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200668 dataTable.addRow(convertRowToInt(dataForFunc))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200669
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200670referenceCoreID = None
671
672
673
674coreidSQL="select distinct coreid from CORE where coredef==?"
675
676def getCoreID(corename):
677 r=c.execute(coreidSQL,(corename,))
678 t=r.fetchone()
679 if t is None:
680 print("Unrecognized reference core")
681 quit()
682 return(t[0])
683
684refCore="""CREATE TEMP VIEW if not exists refCore AS
685select * from %s where (coreid = %s) and (typeid = %s)
686 and %s
687 and compilerid = %s"""
688
689allOtherCores="""CREATE TEMP VIEW if not exists otherCore AS
690select * from %s where (coreid != %s) and (typeid = %s)
691 and %s
692 and compilerid = %s"""
693
694otherCore="""CREATE TEMP VIEW if not exists otherCore AS
695select * from %s where (coreid = %s) and (typeid = %s)
696 and %s
697 and compilerid = %s"""
698
699refCoreAllTypes="""CREATE TEMP VIEW if not exists refCore AS
700select * from %s where (coreid = %s)
701 and %s
702 and compilerid = %s"""
703
704otherCoreAllTypes="""CREATE TEMP VIEW if not exists otherCore AS
705select * from %s where (coreid = %s)
706 and %s
707 and compilerid = %s"""
708
709
710ratioSQL="""select name,otherCore.compilerid as compilerid,CORE.core as core,%s(CAST(otherCore.MAX as FLOAT) / CAST(refCore.MAX AS FLOAT)) AS RATIO
711 from otherCore
712 INNER JOIN refCore ON (refCore.categoryid = otherCore.categoryid
713 AND refCore.testnameid = otherCore.testnameid
714 AND refCore.typeid = otherCore.typeid
715 AND refCore.runid = otherCore.runid
716 AND refCore.compilerid = otherCore.compilerid
717 )
718 INNER JOIN TESTNAME ON TESTNAME.testnameid = refCore.testnameid
719 INNER JOIN CORE USING(coreid)
720 %s"""
721
722ratioSQLAllTypes="""select name,otherCore.compilerid as compilerid,TYPE.type as type,%s(CAST(otherCore.MAX as FLOAT) / CAST(refCore.MAX AS FLOAT)) AS RATIO
723 from otherCore
724 INNER JOIN refCore ON (refCore.categoryid = otherCore.categoryid
725 AND refCore.testnameid = otherCore.testnameid
726 AND refCore.typeid = otherCore.typeid
727 AND refCore.runid = otherCore.runid
728 AND refCore.compilerid = otherCore.compilerid
729 )
730 INNER JOIN TESTNAME ON TESTNAME.testnameid = refCore.testnameid
731 INNER JOIN TYPE USING(typeid)
732 %s"""
733
734ratioTestNamesSQL="""select distinct TESTNAME.name
735 from otherCore
736 INNER JOIN refCore ON (refCore.categoryid = otherCore.categoryid
737 AND refCore.testnameid = otherCore.testnameid
738 AND refCore.typeid = otherCore.typeid
739 AND refCore.runid = otherCore.runid
740 AND refCore.compilerid = otherCore.compilerid
741 )
742 INNER JOIN TESTNAME ON TESTNAME.testnameid = refCore.testnameid
743 INNER JOIN CORE USING(coreid)
744 %s"""
745
746
747dropViewsRef="""drop view refCore"""
748
749dropViewsOther="""drop view otherCore"""
750
751def getTableParams(benchTable):
752 cursor=c.cursor()
753 result=cursor.execute("select * from %s limit 1" % (benchTable))
754 cols= [member[0] for member in cursor.description]
755 params=[]
756 for x in cols:
757 if x in PARAMS:
758 params.append(x)
759 return(params)
760
761def computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,byd):
762 params = getTableParams(benchName)
763 cols=["ratio"]
764 paramscmd=""
765 paramscols=""
766 paramsnames = ["refCore.%s as %s" % (x,x) for x in params]
767 paramseq = ["refCore.%s = otherCore.%s" % (x,x) for x in params]
768 if len(params) > 0:
769 cols = ["%s" % x for x in params]
770 cols.append("ratio")
771 paramscols= ("".join(joinit(paramsnames," , ")) + ",")
772 paramscmd = "WHERE " + "".join(joinit(paramseq," AND "))
773 if byd:
774 ratioCmd = ratioSQLAllTypes % (paramscols,paramscmd)
775 else:
776 ratioCmd = ratioSQL % (paramscols,paramscmd)
777 ratioTestNames = ratioTestNamesSQL % (paramscmd)
778
779 #print(refMkViewCmd)
780 #print(otherMkViewCmd)
781 #
782 #print(ratioCmd)
783 #
784 #print(dropViewsRef)
785 #print(dropViewsOther)
786 #quit()
787
788 c.execute(refMkViewCmd)
789 c.execute(otherMkViewCmd)
790
791 ratio=c.execute(ratioCmd).fetchall()
792 testNames=c.execute(ratioTestNames).fetchall()
793 testNames=[x[0] for x in testNames]
794
795 c.execute(dropViewsRef)
796 c.execute(dropViewsOther)
797
798 #print(ratio)
799 #quit()
800 if byd:
801 return(['name','compilerid','type'] + cols,params,ratio,testNames)
802 else:
803 return(['name','compilerid','core'] + cols,params,ratio,testNames)
804
805# Compute for all core for a given type
806def computeRatioTable(benchName,referenceCore,typeID,compiler):
807 viewParams = (benchName,referenceCore,typeID,runidVIEWcmd,compiler)
808 refMkViewCmd = refCore % viewParams
809 otherMkViewCmd = allOtherCores % viewParams
810 if args.keep:
811 keepCoreID = getCoreID(args.keep)
812 otherParams = (benchName,keepCoreID,typeID,runidVIEWcmd,compiler)
813 otherMkViewCmd = otherCore % otherParams
814 return(computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,False))
815
816
817def computeRatioTableForCore(benchName,referenceCore,otherCoreID,compiler):
818 viewParams = (benchName,referenceCore,runidVIEWcmd,compiler)
819 refMkViewCmd = refCoreAllTypes % viewParams
820 otherParams = (benchName,otherCoreID,runidVIEWcmd,compiler)
821 otherMkViewCmd = otherCoreAllTypes % otherParams
822 return(computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,True))
823
824def formatPerfRatio(s):
825 result=[]
826 for t in s:
827 if type(t) is float:
828 if args.clamp:
829 if t > args.clampval:
830 t = args.clampval
831 result.append(("%.3f" % t))
832 else:
833 result.append(s)
834
835 return(result)
836
837def addRatioTable(cols,params,data,section,testNames,byd):
838 ref=pd.DataFrame(data,columns=cols)
839 toSort=["name"] + params
840 for param in PARAMS:
841 if param in ref.columns:
842 ref[param]=pd.to_numeric(ref[param])
843
844 #print(testNames)
845 for name in testNames:
846 testSection = Section(name)
847 section.addSection(testSection)
848
849 ratioSection = Section("Ratios")
850 testSection.addSection(ratioSection)
851
852 #print(toSort)
853 #print(ref)
854
855 if byd:
856 data=ref.pivot_table(index=toSort, columns=['type'],
857 values=["ratio"], aggfunc='first')
858 else:
859 data=ref.pivot_table(index=toSort, columns=['core'],
860 values=["ratio"], aggfunc='first')
861
862 data=data.sort_values(toSort)
863
864 #print(data)
865 dataForFunc=data.loc[name]
866
867 cores = [c[1] for c in list(data.columns)]
868
869 dataTable=Table(params,cores)
870
871 ratioSection.addContent(Text("A bigger ratio means the reference core \"%s\" is better" % refCoreName))
872
873 ratioSection.addContent(dataTable)
874
875 if type(dataForFunc) is pd.DataFrame:
876 for row in dataForFunc.itertuples():
877 row=list(row)
878 if type(row[0]) is int:
879 row=[row[0]] + formatPerfRatio(row[1:])
880 else:
881 row=list(row[0]) + formatPerfRatio(row[1:])
882 dataTable.addRow(row)
883 else:
884 row=list(dataForFunc)
885 dataTable.addRow(formatPerfRatio(row))
886
887
888
889
890
891
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200892# Add a report for each table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200893def addReportFor(document,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200894 nbElems = getNbElemsInBenchCmd(benchName)
895 if nbElems > 0:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200896 categoryName = getCategoryName(benchName)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200897 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200898 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200899 print("Process %s\n" % benchName)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200900 if args.byd:
901 allCores=getAllExistingCores(benchName)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200902 if args.ratio:
903 allCores.remove(referenceCoreID)
904 if args.keep:
905 allCores=[getCoreID(args.keep)]
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200906 for aCoreID in allCores:
907 nbElems = getNbElemsInBenchAndCoreCmd(benchName,aCoreID)
908 if nbElems > 0:
909 coreName=getCoreDesc(aCoreID)
910 coreSection = Section("%s" % coreName)
911 benchSection.addSection(coreSection)
912 allCompilers = getExistingCompilerForCore(benchName,aCoreID)
913 for compiler in allCompilers:
914 #print(compiler)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200915 if args.ratio:
916 cols,params,ratios,testNames=computeRatioTableForCore(benchName,referenceCoreID,aCoreID,compiler)
917 #print(cols)
918 #print(ratios)
919 #print(" ")
920 if len(ratios)>0:
921 compilerName,version=getCompilerDesc(compiler)
922 compilerSection = Section("%s (%s)" % (compilerName,version))
923 coreSection.addSection(compilerSection)
924 addRatioTable(cols,params,ratios,compilerSection,testNames,True)
925
926 else:
927 nbElems = getNbElemsInBenchAndCoreAndCompilerCmd(benchName,compiler,aCoreID)
928
929 # Print test results for table, type, compiler
930 if nbElems > 0:
931 compilerName,version=getCompilerDesc(compiler)
932 compilerSection = Section("%s (%s)" % (compilerName,version))
933 coreSection.addSection(compilerSection)
934 cols,vals=getColNamesAndDataForCoreCompiler(benchName,compiler,aCoreID)
935 desc=(benchName,compiler,aCoreID)
936 names=getTestNamesForCoreCompiler(benchName,compiler,aCoreID)
937
938 formatTableBy(desc,['type'],['core','version','compiler'],compilerSection,names,cols,vals)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200939
940 else:
941 allTypes = getExistingTypes(benchName)
942 # Add report for each type
943 for aTypeID in allTypes:
944 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
945 if nbElems > 0:
946 typeName = getTypeName(aTypeID)
947 typeSection = Section(typeName)
948 benchSection.addSection(typeSection)
949 if args.byc:
950 ## Add report for each core
951 allCores = getExistingCores(benchName,aTypeID)
952 for core in allCores:
953 #print(core)
954 nbElems = getNbElemsInBenchAndTypeAndCoreCmd(benchName,core,aTypeID)
955 # Print test results for table, type, compiler
956 if nbElems > 0:
957 coreName=getCoreDesc(core)
958 coreSection = Section("%s" % coreName)
959 typeSection.addSection(coreSection)
960 cols,vals=getColNamesAndDataForCore(benchName,core,aTypeID)
961 desc=(benchName,core,aTypeID)
962 names=getTestNamesForCore(benchName,core,aTypeID)
963 formatTableBy(desc,['compiler','version'],['core'],coreSection,names,cols,vals)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200964 elif args.ratio:
965 allCompilers = getExistingCompiler(benchName,aTypeID)
966 for compiler in allCompilers:
967 cols,params,ratios,testNames=computeRatioTable(benchName,referenceCoreID,aTypeID,compiler)
968 #print(cols)
969 #print(ratios)
970 #print(" ")
971 if len(ratios)>0:
972 compilerName,version=getCompilerDesc(compiler)
973 compilerSection = Section("%s (%s)" % (compilerName,version))
974 typeSection.addSection(compilerSection)
975 addRatioTable(cols,params,ratios,compilerSection,testNames,False)
976
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200977 else:
978 ## Add report for each compiler
979 allCompilers = getExistingCompiler(benchName,aTypeID)
980 for compiler in allCompilers:
981 #print(compiler)
982 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
983 # Print test results for table, type, compiler
984 if nbElems > 0:
985 compilerName,version=getCompilerDesc(compiler)
986 compilerSection = Section("%s (%s)" % (compilerName,version))
987 typeSection.addSection(compilerSection)
988 cols,vals=getColNamesAndDataForCompiler(benchName,compiler,aTypeID)
989 desc=(benchName,compiler,aTypeID)
990 names=getTestNamesForCompiler(benchName,compiler,aTypeID)
991 formatTableBy(desc,['core'],['version','compiler'],compilerSection,names,cols,vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200992
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200993
994
995
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200996toc=[Hierarchy("BasicMathsBenchmarks"),
997Hierarchy("ComplexMathsBenchmarks"),
998Hierarchy("FastMath"),
999Hierarchy("Filters",
1000 [Hierarchy("FIR"),
1001 Hierarchy("BIQUAD"),
1002 Hierarchy("DECIM"),
1003 Hierarchy("MISC")]),
1004
1005Hierarchy("Support Functions",
1006 [Hierarchy("Support"),
1007 Hierarchy("SupportBar")]),
1008
1009Hierarchy("Matrix Operations" ,
1010 [Hierarchy("Binary"),
1011 Hierarchy("Unary")]),
1012Hierarchy("Transform"),
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001013Hierarchy("Stats"),
1014Hierarchy("Classical ML",[
1015 Hierarchy("Bayes"),
1016 Hierarchy("SVM"),
1017 Hierarchy("Distance"),
1018 ]),
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001019
1020]
1021
1022processed=[]
1023
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001024def addComments(document):
1025 if os.path.exists(args.comments):
1026 section=Section("Measurement Context")
1027
1028 document.addSection(section)
1029 para=""
1030 with open(args.comments,"r") as r:
1031 for l in r:
1032 if l.strip():
1033 para += l
1034 else:
1035 section.addContent(Text(para))
1036 para=""
1037 if para:
1038 section.addContent(Text(para))
1039
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001040 if args.ratio:
1041 section.addContent(Text("Reference core for the ratio is %s" % refCoreName))
1042 section.addContent(Text("A bigger ratio means the reference code is better"))
1043
1044
1045
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001046def createDoc(document,sections,benchtables):
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001047 global processed,referenceCoreID
1048
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001049 for s in sections:
1050 if s.name in benchtables:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001051 addReportFor(document,s.name)
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001052 processed.append(s.name)
1053 else:
1054 section=Section(s.name)
1055 document.addSection(section)
1056 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001057
1058try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001059 benchtables=getBenchTables()
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001060 document = Document(runidHeader)
1061
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001062 if args.ratio:
1063 referenceCoreID= getCoreID(args.ref)
1064 refCoreName=getCoreDesc(referenceCoreID)
1065
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001066 addComments(document)
1067
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001068
1069
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001070 createDoc(document,toc,benchtables)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001071
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001072 misc=Section("Miscellaneous")
1073 document.addSection(misc)
1074 remaining=diff(benchtables,processed)
1075 for bench in remaining:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001076 addReportFor(misc,bench)
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001077
1078 #for bench in benchtables:
1079 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001080 with open(args.o,"w") as output:
1081 if args.t=="md":
1082 document.accept(Markdown(output))
1083 if args.t=="html":
Christophe Favergeonbb86f042020-08-17 14:58:47 +02001084 reorder=NORMALFORMAT
Christophe Favergeonf1a87802020-08-17 07:36:05 +02001085 if args.byc:
Christophe Favergeonbb86f042020-08-17 14:58:47 +02001086 reorder=BYCFORMAT
1087 if args.byd:
1088 reorder=BYDFORMAT
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001089 document.accept(HTML(output,args.r,args.ratio,reorder))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001090
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001091finally:
1092 c.close()
1093
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001094
1095
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001096