-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulation.py
112 lines (84 loc) · 3.18 KB
/
simulation.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python3
#
# Copyright (c) 2013-2016, ETH Zurich.
# All rights reserved.
#
# This file is distributed under the terms in the attached LICENSE file.
# If you do not find this file, copies can be found by writing to:
# ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
# Overlays
import hybrid_model
import hybrid
import config
import evaluate
import overlay
def _simulation_wrapper(ol, m, gr, multicast=False):
"""
Wrapper for simulationg machines
@param ol - Topology to Simulate
@param m - machine to run on
@return (r, evaluation, root, scheduler, instanceof(overlay))
"""
print ('Simulating machine [%s] with topology [%s] - multicast %d' % \
(m.get_name(), ol, multicast))
r = overlay.Overlay.get_overlay(ol, m)
root = r.get_root_node()
if multicast:
# Multicast, group membership given
n = config.get_mc_group()
nodes = [int(nd) for nd in n]
print ('Multicast with nodes: %s' % ('-'.join(map(str,n))))
hybmod_list = r.get_multicast_tree(nodes)
else:
print ('Getting broadcast tree for ', str(r))
hybmod_list = r.get_broadcast_tree()
assert isinstance(hybmod_list, list)
r_tmp = None
skip_mp = False
# If this is a hybrid, consider only the MP part for evaluation
if isinstance(r, hybrid.Hybrid):
r_tmp = r
r = r.mp_tree # Get the Overlay for the MP part of the evaluation
if not r:
skip_mp = True
print ('MP topology is', str(r))
if not skip_mp:
# XXX Special treatment of non-hybird models
mp_model = None
for tmp_model in hybmod_list:
if isinstance(tmp_model, hybrid_model.MPTree):
assert not mp_model # Otherwise, we found to MP trees in
# the hybrid model, which we don't
# support ATM
mp_model = tmp_model
final_graph = mp_model.graph
mp_ol = mp_model.mp_ol
print ('Getting scheduler for topology', str(r), \
'graph is', str(final_graph), \
'overlay is', str(mp_ol))
# XXX r here is a class, and not an instance of the class
sched = r.get_scheduler(final_graph)
if not mp_model:
raise Exception('XXX Do not know how to get scheduler for list of modules')
# Evaluate the MP part
if not (multicast and len(config.get_mc_group()) == 1):
ev = evaluate.Evaluate.evaluate_all(r, root, m, sched)
else:
from evaluate import Result
ev = []
tmp = Result(0,0,"SHM")
tmp.time = 0;
tmp.time_no_ab = 0;
tmp.last_node = 0;
ev.append(('dummy',tmp))
# Return result
if r_tmp:
r = r_tmp
return (r, ev, root, sched, r)
else:
from evaluate import Result
ev = Result(-1, m.get_cores()[-1], "SHM")
ev.time = -1
m.set_evaluation_result(ev)
import shm
return (r_tmp, ev, root, None, shm.Shm(m))