forked from vtsynergy/OpenDwarfs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lud_tuner.py
73 lines (63 loc) · 2.91 KB
/
lud_tuner.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
import opentuner
from opentuner import ConfigurationManipulator
from opentuner import MeasurementInterface
from opentuner import IntegerParameter
from opentuner import Result
from opentuner.search.manipulator import PowerOfTwoParameter
from opentuner.search.objective import MinimizeTime
from pandas import read_csv
from os import remove
class WorkgroupSizeTuner(MeasurementInterface):
def manipulator(self):
manipulator = ConfigurationManipulator()
manipulator.add_parameter(PowerOfTwoParameter('local1D',1,64))
#manipulator.add_parameter(PowerOfTwoParameter('local2D_x',1,1024))
#manipulator.add_parameter(PowerOfTwoParameter('local2D_y',1,1024))
return manipulator
def get_kernel_time(self,file_name,kernel_name):
"""
measurement to collect a sum of all microseconds with the kernel name
"""
df = read_csv(file_name,sep='\s+',comment='#')
gross_time = int(sum(df[df['region']==kernel_name]['time']))
return gross_time
def get_kernel_cpu_energy(self,file_name,kernel_name):
"""
measurement to collect a sum of all cpu nanojoules with the kernel name
"""
df = read_csv(file_name,sep='\s+',comment='#')
gross_time = int(sum(df[df['region']==kernel_name]['rapl:::PP0_ENERGY:PACKAGE0']))
return gross_time
def get_kernel_gpu_energy(self,file_name,kernel_name):
"""
measurement to collect a sum of all gpu milliwatts with the kernel name
"""
df = read_csv(file_name,sep='\s+',comment='#')
gross_time = int(sum(df[df['region']==kernel_name]['nvml:::GeForce_GTX_1080:power']))
return gross_time
def lud_command(self, desired_result, cfg, input, limit):
cpu_cmd = './lud -p 0 -d 0 --type 0 -x {0} -- -s 4096'.format(cfg['local1D'])
gpu_cmd = './lud -p 1 -d 0 --type 1 -x {0} -- -s 4096'.format(cfg['local1D'])
try:
run_result = self.call_program(cpu_cmd)
finally:
assert run_result['returncode'] == 0
time = self.get_kernel_time('lsb.lud.r0','diagonal_kernel')
time += self.get_kernel_time('lsb.lud.r0','perimeter_kernel')
time += self.get_kernel_time('lsb.lud.r0','internal_kernel')
remove('lsb.lud.r0')
return Result(time=time)
def run(self, desired_result, input, limit, trials=1):
cfg = desired_result.configuration.data
total = 0.0
for _ in xrange(trials):
total += self.lud_command(desired_result, cfg, input, limit).time
return Result(time=total / trials)
def save_final_config(self, configuration):
self.manipulator().save_to_file(configuration.data,
'lud_config.json')
def objective(self):
return MinimizeTime()
if __name__ == '__main__':
argparser = opentuner.default_argparser()
WorkgroupSizeTuner.main(argparser.parse_args())