blob: 91dd92888fbfe646aaeaa00d074b946fe3ffe27a (
plain)
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
|
"""The Execution stage of the framework.
Execute the image against a set of benchmarks. This stage sets up a number of
processes, calls the actual execute method and caches the results.
"""
__author__ = 'yuhenglong@google.com (Yuheng Long)'
import multiprocessing
class Tester(object):
"""Execute the generated images against a set of benchmark applications."""
def __init__(self, numProcess, costs):
"""Set up the process pool and the results cached.
Args:
numProcess: Maximum number of execution to run in parallel
costs: Executions that have been benchmarked before
"""
self._pool = multiprocessing.Pool(numProcess)
self._costs = costs
def _set_cost(self, image, cost):
"""Record the execution result for the current image.
Args:
image: The input image for the execution
cost: the time it takes to execute the image
"""
pass
def _execute(self, task):
"""Execute the benchmarks on task.
The concrete subclass should implement the actual execution.
Args:
task: The input task for the execution
"""
# raise Exception('Must be implemented in child class')
pass
def _execute_task(self, task):
"""Execute the input task and record the cost.
Args:
task: The task to be compiled
"""
pass
def execute(self, generation):
"""Execute the image for all entities in a generation.
Call them in parallel in processes.
Args:
generation: A new generation to be executed.
"""
self._pool.map(self._execute_task, generation.task, 1)
|