-
Notifications
You must be signed in to change notification settings - Fork 0
/
adaptive.py
84 lines (63 loc) · 2.16 KB
/
adaptive.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
#!/usr/bin/env python
#
# 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.
import sys
#sys.path.append('contrib/python-graph/core')
from pygraph.classes.digraph import digraph
import sched_adaptive
import overlay
import logging
class AdapativeTree(overlay.Overlay):
"""
Build a cluster topology for a model.
"""
supported_args = [ "shuffle", "sort", "mm" ]
def __init__(self, mod):
"""
"""
super(AdapativeTree, self).__init__(mod)
def get_name(self):
name = "adaptivetree"
for (key, value) in self.options.items() :
if value :
name = name + "-" + key
return name
def set_arguments(self, args):
for a in args:
if not a in self.supported_args:
raise Exception(('Onrecognized argument %s' % a))
else:
self.options[a] = True
super(AdapativeTree, self).set_arguments(args)
def get_scheduler(self, final_graph):
return sched_adaptive.SchedAdaptive(final_graph, self.mod, self)
def get_root_node(self):
_c_snd_cost = {}
cores = self.mod.get_cores(True)
for c in cores:
_sum = 0
for r in cores:
if (r!=c):
_sum += self.mod.get_send_cost(c, r, False, False)
_c_snd_cost[c] = _sum
logging.info(('%d: sum of send %d' % (c, _sum)))
c_snd_cost = sorted(_c_snd_cost.items(), key=lambda x: x[1])
(root, cost) = c_snd_cost[0]
print ('Choosing node %d as root with cost %d' % \
(root, cost))
return root
def _build_tree(self, g):
"""
Will return a empty broadcast tree that has to be build later
on. The tree being returned will have add one node per core,
but no edges.
"""
gout = digraph()
for n in g.nodes() :
gout.add_node(n)
return gout