@@ -16,40 +16,62 @@ class LayerInfo:
1616 bufferingMode : str
1717 ops : int
1818 totalKernelCycles : int
19- totalInputDmaCycles : int
20- totalOutputDmaCycles : int
19+ totalPreKernelCycles : int
20+ totalPostKernelCycles : int
21+ totalCycles : int
22+ opsperCycle : float
23+ tiles : int = 0
2124
2225
2326def layerInfoFromProfiling (name : str , profiling : LayerProfiling ) -> LayerInfo :
27+ totalKernelCycles = sum (profiling .kernelCycles )
28+ totalPreKernelCycles = sum (profiling .preKernelCycles )
29+ totalPostKernelCycles = sum (profiling .postKernelCycles )
30+ totalCycles = totalKernelCycles + totalPreKernelCycles + totalPostKernelCycles
31+ opsperCycle = profiling .ops / totalCycles if totalCycles > 0 else 0.0
2432 return LayerInfo (name = name ,
2533 bufferingMode = profiling .bufferingMode ,
2634 ops = profiling .ops ,
27- totalKernelCycles = sum (profiling .kernelCycles ),
28- totalInputDmaCycles = sum (profiling .inputDmaCycles ),
29- totalOutputDmaCycles = sum (profiling .outputDmaCycles ))
35+ totalKernelCycles = totalKernelCycles ,
36+ totalPreKernelCycles = totalPreKernelCycles ,
37+ totalPostKernelCycles = totalPostKernelCycles ,
38+ totalCycles = totalCycles ,
39+ opsperCycle = opsperCycle ,
40+ tiles = profiling .tiles )
3041
3142
3243if __name__ == "__main__" :
3344 parser = argparse .ArgumentParser (description = 'Parse and visualize profiling results' )
3445 parser .add_argument ('trace_path' , type = str , help = 'Path to the profiling trace file' )
35- parser .add_argument ('-o' ,
36- '--output_path' ,
37- type = str ,
38- default = "profile.csv" ,
39- help = 'Path to the output CSV file' )
46+ parser .add_argument ('-o' , '--output_path' , type = str , help = 'Path to the output CSV file' )
4047 parser .add_argument ('--table' ,
4148 action = 'store_true' ,
4249 default = False ,
4350 help = 'Print a table of the profiled results.' )
4451 args = parser .parse_args ()
4552
53+ if not args .output_path :
54+ args .output_path = args .trace_path .rsplit ('.' , 1 )[0 ] + '.csv'
55+
4656 profilingParser = ProfilingTraceParser ()
4757
4858 with open (args .trace_path , "r" ) as f :
4959 layerProfilings = profilingParser .parse (f .read ())
5060
5161 fieldnames = [field .name for field in dataclasses .fields (LayerInfo )]
5262 layerInfos = [layerInfoFromProfiling (name , profiling ) for name , profiling in layerProfilings .items ()]
63+ layerInfos += [
64+ LayerInfo (name = "Total" ,
65+ bufferingMode = "" ,
66+ ops = sum (info .ops for info in layerInfos ),
67+ totalKernelCycles = sum (info .totalKernelCycles for info in layerInfos ),
68+ totalPreKernelCycles = sum (info .totalPreKernelCycles for info in layerInfos ),
69+ totalPostKernelCycles = sum (info .totalPostKernelCycles for info in layerInfos ),
70+ totalCycles = sum (info .totalCycles for info in layerInfos ),
71+ opsperCycle = sum (info .ops for info in layerInfos ) /
72+ sum (info .totalCycles for info in layerInfos ) if sum (
73+ info .totalCycles for info in layerInfos ) > 0 else 0.0 )
74+ ]
5375
5476 with open (args .output_path , 'w' , newline = '' ) as csvfile :
5577 writer = csv .DictWriter (csvfile , fieldnames = fieldnames )
0 commit comments