/
inputmanager.py
77 lines (56 loc) · 1.88 KB
/
inputmanager.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
from builtins import object
import abc
import opentuner
from opentuner.resultsdb.models import *
from future.utils import with_metaclass
class InputManager(with_metaclass(abc.ABCMeta, object)):
"""
abstract base class for compile and measurement
"""
def set_driver(self, measurement_driver):
self.driver = measurement_driver
self.session = measurement_driver.session
self.program = measurement_driver.tuning_run.program
@abc.abstractmethod
def select_input(self, desired_result):
"""
select the input to be used to test desired_result
"""
return opentuner.resultsdb.models.Input()
def before_run(self, desired_result, input):
"""hook called before an input is used"""
pass
def after_run(self, desired_result, input):
"""hook called after an input is used"""
pass
def get_input_class(self):
return None
class FixedInputManager(InputManager):
"""
an input manage that produces a single input for all tests
"""
def __init__(self,
input_class_name='fixed',
size=-1,
path=None,
extra=None):
self.input_class_name = input_class_name
self.size = size
self.path = path
self.extra = extra
self.the_input = None
super(FixedInputManager, self).__init__()
def get_input_class(self):
return InputClass.get(self.session,
program=self.program,
name=self.input_class_name,
size=self.size)
def create_input(self, desired_result):
"""create the fixed input database object, result will be cached"""
return Input(input_class=self.get_input_class(),
path=self.path,
extra=self.extra)
def select_input(self, desired_result):
if self.the_input is None:
self.the_input = self.create_input(desired_result)
return self.the_input