-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_avg.py
executable file
·104 lines (94 loc) · 3.57 KB
/
find_avg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
#######################################################
# Find the avg of Iterations+Concurrent instances #
# Step1: Find the average of Nxconcurrent instances #
# Step2: Find the average of Nxiterations #
# In case of cifar add the two times and then do 1,2 #
#######################################################
import optparse
import os
import fnmatch
from statistics import mean
# EG : ./find_avg.py -d 03_03_2022_jenna/ -b kernel_without_inout -c 1
# Arguments
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-d", "--directory", dest="dir", help="Provide directory (eg 02_24_2022_jenna/10epochs/mnist/)")
parser.add_option("-b", "--benchmark", dest="bench", help="Provide benchmark (eg mnist)")
parser.add_option("-c", "--concurrency", dest="concurrency", help="Provide concurrent instances (eg 2)")
parser.add_option("-m", "--mps", dest="mps", help="Provide if MPS is enabled")
(options, args) = parser.parse_args()
# Get the arguments
directory = options.dir
benchmark = options.bench
concurrent = options.concurrency
mps = options.mps
print("Directory of files: "+directory)
print("Concurrency: "+concurrent)
print("Benchmark: "+benchmark)
print("MPS: "+mps)
if (mps=="1"):
# Array with all files in a dir
files=[]
for file in os.listdir(directory+"MPS/"+benchmark):
#print(benchmark+'_stats_'+concurrent+'*.out')
if fnmatch.fnmatch(file, benchmark+'_stats_'+concurrent+'*.out'):
files.append(file)
#print(file)
#print(files)
#Open files and calculate the average of the concurrent instances
avg=[]
add=[]
for i in files:
#print(i)
# Open the first file
with open(directory+"MPS/"+benchmark+"/"+i, 'r') as f:
data = f.read().split()
floats = []
# Calculate the AVG
for elem in data:
try:
floats.append(float(elem))
except ValueError:
pass
#print("Float: "+str(floats)+" sum: "+str(add))
avg.append(mean(floats))
#print(avg)
#print(mean(avg))
avg=mean(avg)
with open("AVG_MPS_concurrency_"+concurrent+'.final', "a") as file_object:
file_object.write(benchmark+": "+str(avg)+"\n")
print("AVG MPS"+benchmark+" concurrency "+concurrent+": "+str(avg))
else:
print ("NAtive!!!")
# Array with all files in a dir
files=[]
for file in os.listdir(directory+"NATIVE/"+benchmark):
#print(benchmark+'_stats_'+concurrent+'*.out')
if fnmatch.fnmatch(file, benchmark+'_stats_'+concurrent+'*.out'):
files.append(file)
#print(file)
#print(files)
#Open files and calculate the average of the concurrent instances
avg=[]
add=[]
for i in files:
#print(i)
# Open the first file
with open(directory+"NATIVE/"+benchmark+"/"+i, 'r') as f:
data = f.read().split()
floats = []
# Calculate the AVG
for elem in data:
try:
floats.append(float(elem))
except ValueError:
pass
#print("Float: "+str(floats)+" sum: "+str(add))
avg.append(mean(floats))
#print(avg)
#print(mean(avg))
avg=mean(avg)
with open("AVG_NAT_concurrency_"+concurrent+'.final', "a") as file_object:
file_object.write(benchmark+": "+str(avg)+"\n")
print("AVG NATIVE "+benchmark+" concurrency "+concurrent+": "+str(avg))