blob: d6179c15978d65c515cab6788ed86b5ef1441f51 [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
Christophe Favergeon0adf05c2020-08-19 07:04:32 +0200831 if t < 0.0:
832 result.append("NA")
833 else:
834 result.append(("%.3f" % t))
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200835 else:
836 result.append(s)
837
838 return(result)
839
840def addRatioTable(cols,params,data,section,testNames,byd):
841 ref=pd.DataFrame(data,columns=cols)
842 toSort=["name"] + params
843 for param in PARAMS:
844 if param in ref.columns:
845 ref[param]=pd.to_numeric(ref[param])
846
847 #print(testNames)
848 for name in testNames:
849 testSection = Section(name)
850 section.addSection(testSection)
851
852 ratioSection = Section("Ratios")
853 testSection.addSection(ratioSection)
854
855 #print(toSort)
856 #print(ref)
857
858 if byd:
859 data=ref.pivot_table(index=toSort, columns=['type'],
Christophe Favergeon0adf05c2020-08-19 07:04:32 +0200860 values=["ratio"], aggfunc='first',fill_value=-1.0)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200861 else:
862 data=ref.pivot_table(index=toSort, columns=['core'],
863 values=["ratio"], aggfunc='first')
864
865 data=data.sort_values(toSort)
866
867 #print(data)
868 dataForFunc=data.loc[name]
869
870 cores = [c[1] for c in list(data.columns)]
871
872 dataTable=Table(params,cores)
873
Christophe Favergeon0adf05c2020-08-19 07:04:32 +0200874 if args.g:
875 if type(dataForFunc) is not pd.DataFrame:
876 sec=Section("Graph")
877 testSection.addSection(sec)
878
879 barChart=BarChart(zip(cores,dataForFunc))
880 sec.addContent(barChart)
881
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200882 ratioSection.addContent(Text("A bigger ratio means the reference core \"%s\" is better" % refCoreName))
883
884 ratioSection.addContent(dataTable)
885
886 if type(dataForFunc) is pd.DataFrame:
887 for row in dataForFunc.itertuples():
888 row=list(row)
889 if type(row[0]) is int:
890 row=[row[0]] + formatPerfRatio(row[1:])
891 else:
892 row=list(row[0]) + formatPerfRatio(row[1:])
893 dataTable.addRow(row)
894 else:
895 row=list(dataForFunc)
896 dataTable.addRow(formatPerfRatio(row))
897
898
899
900
901
902
Christophe Favergeon8cb37302020-05-13 13:06:58 +0200903# Add a report for each table
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200904def addReportFor(document,benchName):
Christophe Favergeone15894e2020-05-14 07:25:53 +0200905 nbElems = getNbElemsInBenchCmd(benchName)
906 if nbElems > 0:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +0200907 categoryName = getCategoryName(benchName)
Christophe Favergeon4fa1e232020-05-15 12:28:17 +0200908 benchSection = Section(categoryName)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +0200909 document.addSection(benchSection)
Christophe Favergeone15894e2020-05-14 07:25:53 +0200910 print("Process %s\n" % benchName)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200911 if args.byd:
912 allCores=getAllExistingCores(benchName)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200913 if args.ratio:
914 allCores.remove(referenceCoreID)
915 if args.keep:
916 allCores=[getCoreID(args.keep)]
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200917 for aCoreID in allCores:
918 nbElems = getNbElemsInBenchAndCoreCmd(benchName,aCoreID)
919 if nbElems > 0:
920 coreName=getCoreDesc(aCoreID)
921 coreSection = Section("%s" % coreName)
922 benchSection.addSection(coreSection)
923 allCompilers = getExistingCompilerForCore(benchName,aCoreID)
924 for compiler in allCompilers:
925 #print(compiler)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200926 if args.ratio:
927 cols,params,ratios,testNames=computeRatioTableForCore(benchName,referenceCoreID,aCoreID,compiler)
928 #print(cols)
929 #print(ratios)
930 #print(" ")
931 if len(ratios)>0:
932 compilerName,version=getCompilerDesc(compiler)
933 compilerSection = Section("%s (%s)" % (compilerName,version))
934 coreSection.addSection(compilerSection)
935 addRatioTable(cols,params,ratios,compilerSection,testNames,True)
936
937 else:
938 nbElems = getNbElemsInBenchAndCoreAndCompilerCmd(benchName,compiler,aCoreID)
939
940 # Print test results for table, type, compiler
941 if nbElems > 0:
942 compilerName,version=getCompilerDesc(compiler)
943 compilerSection = Section("%s (%s)" % (compilerName,version))
944 coreSection.addSection(compilerSection)
945 cols,vals=getColNamesAndDataForCoreCompiler(benchName,compiler,aCoreID)
946 desc=(benchName,compiler,aCoreID)
947 names=getTestNamesForCoreCompiler(benchName,compiler,aCoreID)
948
949 formatTableBy(desc,['type'],['core','version','compiler'],compilerSection,names,cols,vals)
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200950
951 else:
952 allTypes = getExistingTypes(benchName)
953 # Add report for each type
954 for aTypeID in allTypes:
955 nbElems = getNbElemsInBenchAndTypeCmd(benchName,aTypeID)
956 if nbElems > 0:
957 typeName = getTypeName(aTypeID)
958 typeSection = Section(typeName)
959 benchSection.addSection(typeSection)
960 if args.byc:
961 ## Add report for each core
962 allCores = getExistingCores(benchName,aTypeID)
963 for core in allCores:
964 #print(core)
965 nbElems = getNbElemsInBenchAndTypeAndCoreCmd(benchName,core,aTypeID)
966 # Print test results for table, type, compiler
967 if nbElems > 0:
968 coreName=getCoreDesc(core)
969 coreSection = Section("%s" % coreName)
970 typeSection.addSection(coreSection)
971 cols,vals=getColNamesAndDataForCore(benchName,core,aTypeID)
972 desc=(benchName,core,aTypeID)
973 names=getTestNamesForCore(benchName,core,aTypeID)
974 formatTableBy(desc,['compiler','version'],['core'],coreSection,names,cols,vals)
Christophe Favergeon1ff54582020-08-18 14:47:01 +0200975 elif args.ratio:
976 allCompilers = getExistingCompiler(benchName,aTypeID)
977 for compiler in allCompilers:
978 cols,params,ratios,testNames=computeRatioTable(benchName,referenceCoreID,aTypeID,compiler)
979 #print(cols)
980 #print(ratios)
981 #print(" ")
982 if len(ratios)>0:
983 compilerName,version=getCompilerDesc(compiler)
984 compilerSection = Section("%s (%s)" % (compilerName,version))
985 typeSection.addSection(compilerSection)
986 addRatioTable(cols,params,ratios,compilerSection,testNames,False)
987
Christophe Favergeonbb86f042020-08-17 14:58:47 +0200988 else:
989 ## Add report for each compiler
990 allCompilers = getExistingCompiler(benchName,aTypeID)
991 for compiler in allCompilers:
992 #print(compiler)
993 nbElems = getNbElemsInBenchAndTypeAndCompilerCmd(benchName,compiler,aTypeID)
994 # Print test results for table, type, compiler
995 if nbElems > 0:
996 compilerName,version=getCompilerDesc(compiler)
997 compilerSection = Section("%s (%s)" % (compilerName,version))
998 typeSection.addSection(compilerSection)
999 cols,vals=getColNamesAndDataForCompiler(benchName,compiler,aTypeID)
1000 desc=(benchName,compiler,aTypeID)
1001 names=getTestNamesForCompiler(benchName,compiler,aTypeID)
1002 formatTableBy(desc,['core'],['version','compiler'],compilerSection,names,cols,vals)
Christophe Favergeonfeb73932020-05-20 14:48:06 +02001003
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001004
1005
1006
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001007toc=[Hierarchy("BasicMathsBenchmarks"),
1008Hierarchy("ComplexMathsBenchmarks"),
1009Hierarchy("FastMath"),
1010Hierarchy("Filters",
1011 [Hierarchy("FIR"),
1012 Hierarchy("BIQUAD"),
1013 Hierarchy("DECIM"),
1014 Hierarchy("MISC")]),
1015
1016Hierarchy("Support Functions",
1017 [Hierarchy("Support"),
1018 Hierarchy("SupportBar")]),
1019
1020Hierarchy("Matrix Operations" ,
1021 [Hierarchy("Binary"),
1022 Hierarchy("Unary")]),
1023Hierarchy("Transform"),
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001024Hierarchy("Stats"),
1025Hierarchy("Classical ML",[
1026 Hierarchy("Bayes"),
1027 Hierarchy("SVM"),
1028 Hierarchy("Distance"),
1029 ]),
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001030
1031]
1032
1033processed=[]
1034
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001035def addComments(document):
1036 if os.path.exists(args.comments):
1037 section=Section("Measurement Context")
1038
1039 document.addSection(section)
1040 para=""
1041 with open(args.comments,"r") as r:
1042 for l in r:
1043 if l.strip():
1044 para += l
1045 else:
1046 section.addContent(Text(para))
1047 para=""
1048 if para:
1049 section.addContent(Text(para))
1050
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001051 if args.ratio:
1052 section.addContent(Text("Reference core for the ratio is %s" % refCoreName))
1053 section.addContent(Text("A bigger ratio means the reference code is better"))
1054
1055
1056
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001057def createDoc(document,sections,benchtables):
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001058 global processed,referenceCoreID
1059
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001060 for s in sections:
1061 if s.name in benchtables:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001062 addReportFor(document,s.name)
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001063 processed.append(s.name)
1064 else:
1065 section=Section(s.name)
1066 document.addSection(section)
1067 createDoc(section,s.sections,benchtables)
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001068
1069try:
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001070 benchtables=getBenchTables()
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001071 document = Document(runidHeader)
1072
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001073 if args.ratio:
1074 referenceCoreID= getCoreID(args.ref)
1075 refCoreName=getCoreDesc(referenceCoreID)
1076
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001077 addComments(document)
1078
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001079
1080
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001081 createDoc(document,toc,benchtables)
Christophe Favergeon66de4ac2020-07-31 13:38:09 +02001082
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001083 misc=Section("Miscellaneous")
1084 document.addSection(misc)
1085 remaining=diff(benchtables,processed)
1086 for bench in remaining:
Christophe Favergeon6ef1bb22020-08-14 12:07:47 +02001087 addReportFor(misc,bench)
Christophe Favergeoned0eab82020-05-18 08:43:38 +02001088
1089 #for bench in benchtables:
1090 # addReportFor(document,bench)
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001091 with open(args.o,"w") as output:
1092 if args.t=="md":
1093 document.accept(Markdown(output))
1094 if args.t=="html":
Christophe Favergeonbb86f042020-08-17 14:58:47 +02001095 reorder=NORMALFORMAT
Christophe Favergeonf1a87802020-08-17 07:36:05 +02001096 if args.byc:
Christophe Favergeonbb86f042020-08-17 14:58:47 +02001097 reorder=BYCFORMAT
1098 if args.byd:
1099 reorder=BYDFORMAT
Christophe Favergeon1ff54582020-08-18 14:47:01 +02001100 document.accept(HTML(output,args.r,args.ratio,reorder))
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001101
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001102finally:
1103 c.close()
1104
Christophe Favergeonc3f455c2020-05-14 09:24:07 +02001105
1106
Christophe Favergeon8cb37302020-05-13 13:06:58 +02001107