-
Notifications
You must be signed in to change notification settings - Fork 30
/
task_bench.py
75 lines (64 loc) · 2.37 KB
/
task_bench.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
#!/usr/bin/env python
#
# Copyright 2020 Stanford University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import absolute_import, division, print_function
import dask
import sys
import time
import task_bench_core as core
def execute_task_graph(graph):
graph_array = core.encode_task_graph(graph)
if graph.scratch_bytes_per_task > 0:
scratch = [
core.init_scratch_delayed(graph.scratch_bytes_per_task)
for _ in range(graph.max_width)
]
else:
scratch = [None for _ in range(graph.max_width)]
outputs = []
last_row = None
for timestep in range(0, graph.timesteps):
offset = core.c.task_graph_offset_at_timestep(graph, timestep)
width = core.c.task_graph_width_at_timestep(graph, timestep)
row = []
for point in range(0, offset):
row.append(None)
for point in range(offset, offset + width):
inputs = []
for dep in core.task_graph_dependencies(graph, timestep, point):
inputs.append(last_row[dep])
output, scratch[point] = core.execute_point_delayed(
graph_array, timestep, point, scratch[point], *inputs)
row.append(output)
outputs.append(output)
for point in range(offset + width, graph.max_width):
row.append(None)
assert len(row) == graph.max_width
last_row = row
return outputs
def execute_task_bench():
app = core.app_create(sys.argv)
task_graphs = core.app_task_graphs(app)
start_time = time.perf_counter()
results = []
for task_graph in task_graphs:
results.extend(execute_task_graph(task_graph))
core.join(*results).compute()
total_time = time.perf_counter() - start_time
core.c.app_report_timing(app, total_time)
if __name__ == "__main__":
client = core.init_client()
execute_task_bench()