forked from hclhkbu/NV-DVFS-Benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpuPowerExtracter.py
85 lines (66 loc) · 2.73 KB
/
gpuPowerExtracter.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
import time
import datetime
import sys,urllib,urllib2
import csv
import os, glob, re
import cPickle as pickle
import numpy as np
import ConfigParser, argparse
import json
import pandas as pd
if not os.path.exists("csvs/raw"):
os.makedirs("csvs/raw")
logRoot = 'logs'
csvRoot = 'csvs/raw'
parser = argparse.ArgumentParser()
parser.add_argument('--benchmark-setting', type=str, help='gpu benchmark setting', default='gtx980-high-dvfs')
parser.add_argument('--kernel-setting', type=str, help='kernels of benchmark', default='real-small-workload')
opt = parser.parse_args()
print opt
logRoot = "%s/%s-%s" % (logRoot, opt.benchmark_setting, opt.kernel_setting)
power_filelist = glob.glob(r'%s/*power.log' % logRoot)
power_filelist.sort()
# Reading metrics list
cf_bs = ConfigParser.SafeConfigParser()
cf_bs.read("configs/benchmarks/%s.cfg" % (opt.benchmark_setting))
metrics = json.loads(cf_bs.get("profile_control", "metrics"))
coreBase = json.loads(cf_bs.get("dvfs_control", "coreBase"))
memBase = json.loads(cf_bs.get("dvfs_control", "memBase"))
powerState = json.loads(cf_bs.get("dvfs_control", "powerState"))
runState = json.loads(cf_bs.get("dvfs_control", "runState"))
dvfsEnv = json.loads(cf_bs.get("dvfs_control", "dvfsEnv"))
# Read GPU application settings
cf_ks = ConfigParser.SafeConfigParser()
cf_ks.read("configs/kernels/%s.cfg" % opt.kernel_setting)
benchmark_programs = cf_ks.sections()
head = ["appName", "coreF", "memF", "argNo", "kernel", "power/W"]
print head
# prepare csv file
csvfile = open('%s/%s-%s-Power.csv' % (csvRoot, opt.benchmark_setting, opt.kernel_setting), 'wb')
csvWriter = csv.writer(csvfile, dialect='excel')
# write table head
csvWriter.writerow(head)
for fp in power_filelist:
# print fp
baseInfo = fp.split('_')
appName = baseInfo[1]
coreF = int(baseInfo[2][4:]) + coreBase
memF = int(baseInfo[3][3:]) + memBase
argNo = baseInfo[4]
kernel = json.loads(cf_ks.get(appName, 'kernels'))[0]
rec = [appName, coreF, memF, argNo, kernel]
# neglect first two lines of device information and table header
f = open(fp, 'r')
content = f.readlines()[2:]
f.close()
if dvfsEnv == 'linux': # filter with frequency
print coreF
powerList = [float(line.split()[-1].strip()) / 1000.0 for line in content if int(line.split()[3]) == coreF]
else:
powerList = [float(line.split()[-1].strip()) / 1000.0 for line in content if int(line.split()[1]) == runState]
#powerList = powerList[len(powerList) / 10 * 5 :len(powerList) / 10 * 6] # filter out those power data of cooling down GPU
powerList.sort()
powerList = powerList[-100:] # filter out those power data of cooling down GPU
rec.append(np.mean(powerList))
print rec
csvWriter.writerow(rec[:len(head)])