blob: 73b79a87f82c6f807d2dd06ed6a4bd4724bc3f66 [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 Favergeon8700f502020-09-18 14:14:27 +0200474def formatFloat(s):
475 result=[]
476 for t in s:
477 if type(t) is float:
478 result.append(("%.3f" % t))
479 else:
480 result.append(t)
481 return(result)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200482
483PARAMS=["NB","NumTaps", "NBA", "NBB", "Factor", "NumStages","VECDIM","NBR","NBC","NBI","IFFT", "BITREV"]
484
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200485def regressionTableFor(byname,name,section,ref,toSort,indexCols,field):
486 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8700f502020-09-18 14:14:27 +0200487 values=[field], aggfunc='first',fill_value="NA")
488
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200489 data=data.sort_values(toSort)
490
491 cores = [c[1] for c in list(data.columns)]
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200492 columns = diff(indexCols,['name'])
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200493
Christophe Favergeon34d313a2020-05-14 15:09:41 +0200494 dataTable=Table(columns,cores)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200495 section.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200496
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200497 dataForFunc=data.loc[name]
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200498
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200499 if type(dataForFunc) is pd.DataFrame:
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200500 bars={'cols':columns,'cores':cores,'data':[]}
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200501 for row in dataForFunc.itertuples():
502 row=list(row)
503 if type(row[0]) is int:
504 row=[row[0]] + row[1:]
505 else:
506 row=list(row[0]) + row[1:]
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200507 if field=="MAXREGCOEF":
Christophe Favergeon670b1672020-05-28 12:47:58 +0200508 newrow = row
Christophe Favergeon8700f502020-09-18 14:14:27 +0200509 newrow[len(columns):] = formatFloat(row[len(columns):])
Christophe Favergeon670b1672020-05-28 12:47:58 +0200510 row=newrow
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200511 dataTable.addRow(row)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200512 bars['data'].append(row)
513 return(bars)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200514 else:
Christophe Favergeoned0eab82020-05-18 08:43:38 +0200515 if field=="MAXREGCOEF":
Christophe Favergeon8700f502020-09-18 14:14:27 +0200516 dataForFunc=formatFloat(dataForFunc)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200517 dataTable.addRow(dataForFunc)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200518 return(list(zip(cores,dataForFunc)))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200519
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200520def formatColumnName(c):
521 return("".join(joinit(c,":")))
522
523def getCoresForHistory(benchTable,compilerid,typeid,testid,runid):
524 vals=(compilerid,typeid,testid,runid)
525 result=c.execute(coresForHistory % benchTable,vals).fetchall()
526 ids=[(x[0],x[1]) for x in list(result)]
527 return(ids)
528
529def getCompilerForHistory(benchTable,coreid,typeid,testid,runid):
530 vals=(coreid,typeid,testid,runid)
531 result=c.execute(compilersForHistory % benchTable,vals).fetchall()
532 ids=[(x[0],x[1],x[2]) for x in list(result)]
533 return(ids)
534
535def getHistory(desc,testid,indexCols):
536 benchName,sectionID,typeid,runid = desc
537
538 #print(benchName)
539 #print(sectionID)
540 #print(typeid)
541 #print(testid)
542 columns = diff(indexCols,['name'])
543 #print(columns)
544 if args.byc:
545 coreid=sectionID
546 compilerids=getCompilerForHistory(benchName,coreid,typeid,testid,runid)
547 series={}
548 for compilerid,compilername,version in compilerids:
549 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
550 #print("%s:%s" % (compilername,version))
551 maxpos = result[0].index('MAX')
552 lrunid = result[0].index('runid')
553 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
554 series[corename]=r
555 hist=History(series,runid)
556 return(hist)
557 else:
558 compilerid=sectionID
559 coreids = getCoresForHistory(benchName,compilerid,typeid,testid,runid)
560 series={}
561 for coreid,corename in coreids:
562 result=getColNamesAndHistory(benchName,compilerid,coreid,typeid,testid)
563 #print(corename)
564 maxpos = result[0].index('MAX')
565 corepos = result[0].index('core')
566 lrunid = result[0].index('runid')
567 r=[[int(x[lrunid]),int(x[maxpos])] for x in result[1:][0]]
568 series[corename]=r
569 hist=History(series,runid)
570 return(hist)
571
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200572def convertRowToInt(r):
573 result=[]
574 for e in r:
575 if type(e) is float:
576 result.append(int(e))
577 else:
578 result.append(e)
579
580 return(result)
581
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200582def formatTableBy(desc,byname,section,typeSection,testNames,cols,vals):
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200583 if vals.size != 0:
584 ref=pd.DataFrame(vals,columns=cols)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200585 toSort=["name"]
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200586
587 for param in PARAMS:
588 if param in ref.columns:
589 ref[param]=pd.to_numeric(ref[param])
590 toSort.append(param)
591 if args.r:
592 # Regression table
593 ref['MAX']=pd.to_numeric(ref['MAX'])
594 ref['MAXREGCOEF']=pd.to_numeric(ref['MAXREGCOEF'])
595
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200596 indexCols=diff(cols,byname + ['Regression','MAXREGCOEF','MAX'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200597 valList = ['Regression']
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200598
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200599 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200600 ref['CYCLES']=pd.to_numeric(ref['CYCLES']).round(decimals=0)
601
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200602 indexCols=diff(cols,byname + ['CYCLES'] + section)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200603 valList = ['CYCLES']
604
605
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200606 for name in testNames:
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200607 if args.r:
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200608 testSection = Section(name)
Christophe Favergeon8700f502020-09-18 14:14:27 +0200609 testSection.setTest()
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200610 typeSection.addSection(testSection)
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200611
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200612 maxCyclesSection = Section("Max cycles")
613 testSection.addSection(maxCyclesSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200614 theCycles=regressionTableFor(byname,name,maxCyclesSection,ref,toSort,indexCols,'MAX')
Christophe Favergeon670b1672020-05-28 12:47:58 +0200615 if args.g:
616 if type(theCycles) is dict:
617 nbParams=len(theCycles['cols'])
618 for bar in theCycles['data']:
619 params=bar[0:nbParams]
620 values=bar[nbParams:]
621 title=[("%s=%s" % x) for x in list(zip(theCycles['cols'],params))]
622 title="".join(joinit(title," "))
623 sec=Section(title)
624 maxCyclesSection.addSection(sec)
625 values=list(zip(theCycles['cores'],values))
626 barChart=BarChart(values)
627 sec.addContent(barChart)
628 else:
629 #print(theCycles)
630 sec=Section("Graph")
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200631 maxCyclesSection.addSection(sec)
Christophe Favergeon670b1672020-05-28 12:47:58 +0200632 barChart=BarChart(theCycles)
Christophe Favergeon0dcf9a12020-05-27 15:55:27 +0200633 sec.addContent(barChart)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200634
Christophe Favergeon670b1672020-05-28 12:47:58 +0200635 #history=getHistory(desc,testid,indexCols)
636 #testSection.addContent(history)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200637
638 regressionSection = Section("Regression")
639 testSection.addSection(regressionSection)
640 regressionTableFor(byname,name,regressionSection,ref,toSort,indexCols,'Regression')
641
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200642
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200643 maxRegCoefSection = Section("Max Reg Coef")
644 testSection.addSection(maxRegCoefSection)
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200645 regressionTableFor(byname,name,maxRegCoefSection,ref,toSort,indexCols,'MAXREGCOEF')
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200646
647 else:
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200648 data=ref.pivot_table(index=indexCols, columns=byname,
Christophe Favergeon8700f502020-09-18 14:14:27 +0200649 values=valList, aggfunc='first',fill_value="NA")
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200650
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200651 data=data.sort_values(toSort)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200652
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200653 #print(list(data.columns))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200654
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200655 testSection = Section(name)
Christophe Favergeon8700f502020-09-18 14:14:27 +0200656 testSection.setTest()
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200657 typeSection.addSection(testSection)
658
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200659 dataForFunc=data.loc[name]
660 dataForFunc = dataForFunc.dropna(axis=1)
661
662 columnsID = [formatColumnName(c[1:]) for c in list(dataForFunc.columns)]
663 columns = diff(indexCols,['name'])
664
Christophe Favergeonfeb73932020-05-20 14:48:06 +0200665 dataTable=Table(columns,columnsID)
666 testSection.addContent(dataTable)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200667
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200668
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200669 if type(dataForFunc) is pd.DataFrame:
670 for row in dataForFunc.itertuples():
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200671 if type(row[0]) is int:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200672 row=list([row[0]] + list(row[1:]))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200673 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200674 row=list(row[0]) + list(row[1:])
675 dataTable.addRow(convertRowToInt(row))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200676 else:
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200677 dataTable.addRow(convertRowToInt(dataForFunc))
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200678
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200679referenceCoreID = None
680
681
682
683coreidSQL="select distinct coreid from CORE where coredef==?"
684
685def getCoreID(corename):
686 r=c.execute(coreidSQL,(corename,))
687 t=r.fetchone()
688 if t is None:
689 print("Unrecognized reference core")
690 quit()
691 return(t[0])
692
693refCore="""CREATE TEMP VIEW if not exists refCore AS
694select * from %s where (coreid = %s) and (typeid = %s)
695 and %s
696 and compilerid = %s"""
697
698allOtherCores="""CREATE TEMP VIEW if not exists otherCore AS
699select * from %s where (coreid != %s) and (typeid = %s)
700 and %s
701 and compilerid = %s"""
702
703otherCore="""CREATE TEMP VIEW if not exists otherCore AS
704select * from %s where (coreid = %s) and (typeid = %s)
705 and %s
706 and compilerid = %s"""
707
708refCoreAllTypes="""CREATE TEMP VIEW if not exists refCore AS
709select * from %s where (coreid = %s)
710 and %s
711 and compilerid = %s"""
712
713otherCoreAllTypes="""CREATE TEMP VIEW if not exists otherCore AS
714select * from %s where (coreid = %s)
715 and %s
716 and compilerid = %s"""
717
718
719ratioSQL="""select name,otherCore.compilerid as compilerid,CORE.core as core,%s(CAST(otherCore.MAX as FLOAT) / CAST(refCore.MAX AS FLOAT)) AS RATIO
720 from otherCore
721 INNER JOIN refCore ON (refCore.categoryid = otherCore.categoryid
722 AND refCore.testnameid = otherCore.testnameid
723 AND refCore.typeid = otherCore.typeid
724 AND refCore.runid = otherCore.runid
725 AND refCore.compilerid = otherCore.compilerid
726 )
727 INNER JOIN TESTNAME ON TESTNAME.testnameid = refCore.testnameid
728 INNER JOIN CORE USING(coreid)
729 %s"""
730
731ratioSQLAllTypes="""select name,otherCore.compilerid as compilerid,TYPE.type as type,%s(CAST(otherCore.MAX as FLOAT) / CAST(refCore.MAX AS FLOAT)) AS RATIO
732 from otherCore
733 INNER JOIN refCore ON (refCore.categoryid = otherCore.categoryid
734 AND refCore.testnameid = otherCore.testnameid
735 AND refCore.typeid = otherCore.typeid
736 AND refCore.runid = otherCore.runid
737 AND refCore.compilerid = otherCore.compilerid
738 )
739 INNER JOIN TESTNAME ON TESTNAME.testnameid = refCore.testnameid
740 INNER JOIN TYPE USING(typeid)
741 %s"""
742
743ratioTestNamesSQL="""select distinct TESTNAME.name
744 from otherCore
745 INNER JOIN refCore ON (refCore.categoryid = otherCore.categoryid
746 AND refCore.testnameid = otherCore.testnameid
747 AND refCore.typeid = otherCore.typeid
748 AND refCore.runid = otherCore.runid
749 AND refCore.compilerid = otherCore.compilerid
750 )
751 INNER JOIN TESTNAME ON TESTNAME.testnameid = refCore.testnameid
752 INNER JOIN CORE USING(coreid)
753 %s"""
754
755
756dropViewsRef="""drop view refCore"""
757
758dropViewsOther="""drop view otherCore"""
759
760def getTableParams(benchTable):
761 cursor=c.cursor()
762 result=cursor.execute("select * from %s limit 1" % (benchTable))
763 cols= [member[0] for member in cursor.description]
764 params=[]
765 for x in cols:
766 if x in PARAMS:
767 params.append(x)
768 return(params)
769
770def computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,byd):
771 params = getTableParams(benchName)
772 cols=["ratio"]
773 paramscmd=""
774 paramscols=""
775 paramsnames = ["refCore.%s as %s" % (x,x) for x in params]
776 paramseq = ["refCore.%s = otherCore.%s" % (x,x) for x in params]
777 if len(params) > 0:
778 cols = ["%s" % x for x in params]
779 cols.append("ratio")
780 paramscols= ("".join(joinit(paramsnames," , ")) + ",")
781 paramscmd = "WHERE " + "".join(joinit(paramseq," AND "))
782 if byd:
783 ratioCmd = ratioSQLAllTypes % (paramscols,paramscmd)
784 else:
785 ratioCmd = ratioSQL % (paramscols,paramscmd)
786 ratioTestNames = ratioTestNamesSQL % (paramscmd)
787
788 #print(refMkViewCmd)
789 #print(otherMkViewCmd)
790 #
791 #print(ratioCmd)
792 #
793 #print(dropViewsRef)
794 #print(dropViewsOther)
795 #quit()
796
797 c.execute(refMkViewCmd)
798 c.execute(otherMkViewCmd)
799
800 ratio=c.execute(ratioCmd).fetchall()
801 testNames=c.execute(ratioTestNames).fetchall()
802 testNames=[x[0] for x in testNames]
803
804 c.execute(dropViewsRef)
805 c.execute(dropViewsOther)
806
807 #print(ratio)
808 #quit()
809 if byd:
810 return(['name','compilerid','type'] + cols,params,ratio,testNames)
811 else:
812 return(['name','compilerid','core'] + cols,params,ratio,testNames)
813
814# Compute for all core for a given type
815def computeRatioTable(benchName,referenceCore,typeID,compiler):
816 viewParams = (benchName,referenceCore,typeID,runidVIEWcmd,compiler)
817 refMkViewCmd = refCore % viewParams
818 otherMkViewCmd = allOtherCores % viewParams
819 if args.keep:
820 keepCoreID = getCoreID(args.keep)
821 otherParams = (benchName,keepCoreID,typeID,runidVIEWcmd,compiler)
822 otherMkViewCmd = otherCore % otherParams
823 return(computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,False))
824
825
826def computeRatioTableForCore(benchName,referenceCore,otherCoreID,compiler):
827 viewParams = (benchName,referenceCore,runidVIEWcmd,compiler)
828 refMkViewCmd = refCoreAllTypes % viewParams
829 otherParams = (benchName,otherCoreID,runidVIEWcmd,compiler)
830 otherMkViewCmd = otherCoreAllTypes % otherParams
831 return(computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,True))
832
833def formatPerfRatio(s):
834 result=[]
835 for t in s:
836 if type(t) is float:
837 if args.clamp:
838 if t > args.clampval:
839 t = args.clampval
Christophe Favergeon0adf05c2020-08-19 07:04:32 +0200840 if t < 0.0:
841 result.append("NA")
842 else:
843 result.append(("%.3f" % t))
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200844 else:
845 result.append(s)
846
847 return(result)
848
Christophe Favergeon8700f502020-09-18 14:14:27 +0200849
850
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200851def addRatioTable(cols,params,data,section,testNames,byd):
852 ref=pd.DataFrame(data,columns=cols)
853 toSort=["name"] + params
854 for param in PARAMS:
855 if param in ref.columns:
856 ref[param]=pd.to_numeric(ref[param])
857
858 #print(testNames)
859 for name in testNames:
860 testSection = Section(name)
Christophe Favergeon8700f502020-09-18 14:14:27 +0200861 testSection.setTest()
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200862 section.addSection(testSection)
863
864 ratioSection = Section("Ratios")
865 testSection.addSection(ratioSection)
866
867 #print(toSort)
868 #print(ref)
869
870 if byd:
871 data=ref.pivot_table(index=toSort, columns=['type'],
Christophe Favergeon0adf05c2020-08-19 07:04:32 +0200872 values=["ratio"], aggfunc='first',fill_value=-1.0)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200873 else:
874 data=ref.pivot_table(index=toSort, columns=['core'],
875 values=["ratio"], aggfunc='first')
876
877 data=data.sort_values(toSort)
878
879 #print(data)
880 dataForFunc=data.loc[name]
881
882 cores = [c[1] for c in list(data.columns)]
883
884 dataTable=Table(params,cores)
885
Christophe Favergeon0adf05c2020-08-19 07:04:32 +0200886 if args.g:
887 if type(dataForFunc) is not pd.DataFrame:
888 sec=Section("Graph")
889 testSection.addSection(sec)
890
891 barChart=BarChart(zip(cores,dataForFunc))
892 sec.addContent(barChart)
893
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200894 ratioSection.addContent(Text("A bigger ratio means the reference core \"%s\" is better" % refCoreName))
895
896 ratioSection.addContent(dataTable)
897
898 if type(dataForFunc) is pd.DataFrame:
899 for row in dataForFunc.itertuples():
900 row=list(row)
901 if type(row[0]) is int:
902 row=[row[0]] + formatPerfRatio(row[1:])
903 else:
904 row=list(row[0]) + formatPerfRatio(row[1:])
905 dataTable.addRow(row)
906 else:
907 row=list(dataForFunc)
908 dataTable.addRow(formatPerfRatio(row))
909
910
911
912
913
914
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200915# Add a report for each table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200916def addReportFor(document,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200917 nbElems = getNbElemsInBenchCmd(benchName)
918 if nbElems > 0:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200919 categoryName = getCategoryName(benchName)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200920 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200921 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200922 print("Process %s\n" % benchName)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200923 if args.byd:
924 allCores=getAllExistingCores(benchName)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200925 if args.ratio:
926 allCores.remove(referenceCoreID)
927 if args.keep:
928 allCores=[getCoreID(args.keep)]
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200929 for aCoreID in allCores:
930 nbElems = getNbElemsInBenchAndCoreCmd(benchName,aCoreID)
931 if nbElems > 0:
932 coreName=getCoreDesc(aCoreID)
933 coreSection = Section("%s" % coreName)
934 benchSection.addSection(coreSection)
935 allCompilers = getExistingCompilerForCore(benchName,aCoreID)
936 for compiler in allCompilers:
937 #print(compiler)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200938 if args.ratio:
939 cols,params,ratios,testNames=computeRatioTableForCore(benchName,referenceCoreID,aCoreID,compiler)
940 #print(cols)
941 #print(ratios)
942 #print(" ")
943 if len(ratios)>0:
944 compilerName,version=getCompilerDesc(compiler)
945 compilerSection = Section("%s (%s)" % (compilerName,version))
946 coreSection.addSection(compilerSection)
947 addRatioTable(cols,params,ratios,compilerSection,testNames,True)
948
949 else:
950 nbElems = getNbElemsInBenchAndCoreAndCompilerCmd(benchName,compiler,aCoreID)
951
952 # Print test results for table, type, compiler
953 if nbElems > 0:
954 compilerName,version=getCompilerDesc(compiler)
955 compilerSection = Section("%s (%s)" % (compilerName,version))
956 coreSection.addSection(compilerSection)
957 cols,vals=getColNamesAndDataForCoreCompiler(benchName,compiler,aCoreID)
958 desc=(benchName,compiler,aCoreID)
959 names=getTestNamesForCoreCompiler(benchName,compiler,aCoreID)
960
961 formatTableBy(desc,['type'],['core','version','compiler'],compilerSection,names,cols,vals)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200962
963 else:
964 allTypes = getExistingTypes(benchName)
965 # Add report for each type
966 for aTypeID in allTypes:
967 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
968 if nbElems > 0:
969 typeName = getTypeName(aTypeID)
970 typeSection = Section(typeName)
971 benchSection.addSection(typeSection)
972 if args.byc:
973 ## Add report for each core
974 allCores = getExistingCores(benchName,aTypeID)
975 for core in allCores:
976 #print(core)
977 nbElems = getNbElemsInBenchAndTypeAndCoreCmd(benchName,core,aTypeID)
978 # Print test results for table, type, compiler
979 if nbElems > 0:
980 coreName=getCoreDesc(core)
981 coreSection = Section("%s" % coreName)
982 typeSection.addSection(coreSection)
983 cols,vals=getColNamesAndDataForCore(benchName,core,aTypeID)
984 desc=(benchName,core,aTypeID)
985 names=getTestNamesForCore(benchName,core,aTypeID)
986 formatTableBy(desc,['compiler','version'],['core'],coreSection,names,cols,vals)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200987 elif args.ratio:
988 allCompilers = getExistingCompiler(benchName,aTypeID)
989 for compiler in allCompilers:
990 cols,params,ratios,testNames=computeRatioTable(benchName,referenceCoreID,aTypeID,compiler)
991 #print(cols)
992 #print(ratios)
993 #print(" ")
994 if len(ratios)>0:
995 compilerName,version=getCompilerDesc(compiler)
996 compilerSection = Section("%s (%s)" % (compilerName,version))
997 typeSection.addSection(compilerSection)
998 addRatioTable(cols,params,ratios,compilerSection,testNames,False)
999
Christophe Favergeonbb86f042020-08-17 14:58:47 +02001000 else:
1001 ## Add report for each compiler
1002 allCompilers = getExistingCompiler(benchName,aTypeID)
1003 for compiler in allCompilers:
1004 #print(compiler)
1005 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
1006 # Print test results for table, type, compiler
1007 if nbElems > 0:
1008 compilerName,version=getCompilerDesc(compiler)
1009 compilerSection = Section("%s (%s)" % (compilerName,version))
1010 typeSection.addSection(compilerSection)
1011 cols,vals=getColNamesAndDataForCompiler(benchName,compiler,aTypeID)
1012 desc=(benchName,compiler,aTypeID)
1013 names=getTestNamesForCompiler(benchName,compiler,aTypeID)
1014 formatTableBy(desc,['core'],['version','compiler'],compilerSection,names,cols,vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +02001015
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001016
1017
1018
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001019toc=[Hierarchy("BasicMathsBenchmarks"),
1020Hierarchy("ComplexMathsBenchmarks"),
1021Hierarchy("FastMath"),
1022Hierarchy("Filters",
1023 [Hierarchy("FIR"),
1024 Hierarchy("BIQUAD"),
1025 Hierarchy("DECIM"),
1026 Hierarchy("MISC")]),
1027
1028Hierarchy("Support Functions",
1029 [Hierarchy("Support"),
1030 Hierarchy("SupportBar")]),
1031
1032Hierarchy("Matrix Operations" ,
1033 [Hierarchy("Binary"),
1034 Hierarchy("Unary")]),
1035Hierarchy("Transform"),
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001036Hierarchy("Stats"),
1037Hierarchy("Classical ML",[
1038 Hierarchy("Bayes"),
1039 Hierarchy("SVM"),
1040 Hierarchy("Distance"),
1041 ]),
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001042
1043]
1044
1045processed=[]
1046
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001047def addComments(document):
1048 if os.path.exists(args.comments):
1049 section=Section("Measurement Context")
1050
1051 document.addSection(section)
1052 para=""
1053 with open(args.comments,"r") as r:
1054 for l in r:
1055 if l.strip():
1056 para += l
1057 else:
1058 section.addContent(Text(para))
1059 para=""
1060 if para:
1061 section.addContent(Text(para))
1062
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001063 if args.ratio:
1064 section.addContent(Text("Reference core for the ratio is %s" % refCoreName))
1065 section.addContent(Text("A bigger ratio means the reference code is better"))
1066
1067
1068
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001069def createDoc(document,sections,benchtables):
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001070 global processed,referenceCoreID
1071
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001072 for s in sections:
1073 if s.name in benchtables:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001074 addReportFor(document,s.name)
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001075 processed.append(s.name)
1076 else:
1077 section=Section(s.name)
1078 document.addSection(section)
1079 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001080
1081try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001082 benchtables=getBenchTables()
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001083 document = Document(runidHeader)
1084
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001085 if args.ratio:
1086 referenceCoreID= getCoreID(args.ref)
1087 refCoreName=getCoreDesc(referenceCoreID)
1088
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001089 addComments(document)
1090
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001091
1092
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001093 createDoc(document,toc,benchtables)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001094
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001095 misc=Section("Miscellaneous")
1096 document.addSection(misc)
1097 remaining=diff(benchtables,processed)
1098 for bench in remaining:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001099 addReportFor(misc,bench)
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001100
1101 #for bench in benchtables:
1102 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001103 with open(args.o,"w") as output:
1104 if args.t=="md":
1105 document.accept(Markdown(output))
1106 if args.t=="html":
Christophe Favergeonbb86f042020-08-17 14:58:47 +02001107 reorder=NORMALFORMAT
Christophe Favergeonf1a87802020-08-17 07:36:05 +02001108 if args.byc:
Christophe Favergeonbb86f042020-08-17 14:58:47 +02001109 reorder=BYCFORMAT
1110 if args.byd:
1111 reorder=BYDFORMAT
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001112 document.accept(HTML(output,args.r,args.ratio,reorder))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001113
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001114finally:
1115 c.close()
1116
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001117
1118
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001119