-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathmmm_tuner.py
More file actions
58 lines (45 loc) · 1.7 KB
/
mmm_tuner.py
File metadata and controls
58 lines (45 loc) · 1.7 KB
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
#!/usr/bin/env python
#
# Optimize blocksize of apps/mmm_block.cpp
#
# This is an extremely simplified version meant only for tutorials
#
from __future__ import print_function
import opentuner
from opentuner import ConfigurationManipulator
from opentuner import IntegerParameter
from opentuner import MeasurementInterface
from opentuner import Result
class GccFlagsTuner(MeasurementInterface):
def manipulator(self):
"""
Define the search space by creating a
ConfigurationManipulator
"""
manipulator = ConfigurationManipulator()
manipulator.add_parameter(
IntegerParameter('BLOCK_SIZE', 1, 10))
return manipulator
def run(self, desired_result, input, limit):
"""
Compile and run a given configuration then
return performance
"""
cfg = desired_result.configuration.data
gcc_cmd = 'g++ mmm_block.cpp '
gcc_cmd += ' -D{0}={1}'.format('BLOCK_SIZE', cfg['BLOCK_SIZE'])
gcc_cmd += ' -o ./tmp.bin'
compile_result = self.call_program(gcc_cmd)
assert compile_result['returncode'] == 0
run_cmd = './tmp.bin'
run_result = self.call_program(run_cmd)
assert run_result['returncode'] == 0
return Result(time=run_result['time'])
def save_final_config(self, configuration):
"""called at the end of tuning"""
print("Optimal block size written to mmm_final_config.json:", configuration.data)
self.manipulator().save_to_file(configuration.data,
'mmm_final_config.json')
if __name__ == '__main__':
argparser = opentuner.default_argparser()
GccFlagsTuner.main(argparser.parse_args())