[pypy-svn] r19236 - pypy/dist/pypy/translator/locality
tismer at codespeak.net
tismer at codespeak.net
Mon Oct 31 15:49:35 CET 2005
Author: tismer
Date: Mon Oct 31 15:49:34 2005
New Revision: 19236
Modified:
pypy/dist/pypy/translator/locality/calltree.py
pypy/dist/pypy/translator/locality/projection.py
pypy/dist/pypy/translator/locality/simulation.py
Log:
stopping this locality thing for a while, after it turned
out that the problem is not about the physical distance of code,
but we need to use coloring of cache lines, instead.
Modified: pypy/dist/pypy/translator/locality/calltree.py
==============================================================================
--- pypy/dist/pypy/translator/locality/calltree.py (original)
+++ pypy/dist/pypy/translator/locality/calltree.py Mon Oct 31 15:49:34 2005
@@ -86,10 +86,29 @@
return res
def simulate(self):
- log.calltree('building CallTree...')
+ log.simulate('building SimGraph for simulation...')
sim = SimGraph(self.nodes, FlowSimNode, self.calls)
- log.calltree('simulating...')
- sim.sim_all(0.9, 50)
- # here I'm still playing around with parameters.
- import pdb
- pdb.set_trace()
+ log.simulate('simulating...')
+ sim.sim_all(1.9, 50)
+ self.statgraph = sim
+
+ def optimize(self):
+ log.topology('building SpaceGraph for topological sort...')
+ sg = SpaceGraph(self.statgraph)
+ steps = 500
+ try:
+ for i in range(steps):
+ for k in range(10):
+ sg.do_correction()
+ sg.normalize()
+ s = "step %d of %d lonelyness = %g" % (i+1, steps, sg.lonelyness())
+ log.topology(s)
+ except KeyboardInterrupt:
+ log.topology("aborted after %d steps" % (i+1))
+ self.topology = sg
+ log.topology("done.")
+
+ def ordered_funcnodes(self):
+ nodes = self.topology.order()
+ ret = [node.func for node in nodes]
+ return ret
Modified: pypy/dist/pypy/translator/locality/projection.py
==============================================================================
--- pypy/dist/pypy/translator/locality/projection.py (original)
+++ pypy/dist/pypy/translator/locality/projection.py Mon Oct 31 15:49:34 2005
@@ -138,16 +138,12 @@
return Vector(lonely).norm2()
def forcevector(self):
- # weighted implementation of the "rubber2" algorithm,
- # from "PolyTop", (C) Christian Tismer / Gerhard G. Thomas 1992
vec = Vector()
+ k = sum(self.weights)
for w, rel in zip(self.weights, self.relations):
tmp = rel.position - self.position
- lng = tmp.norm2()
- tmp *= w * lng
+ tmp *= w
vec += tmp
- # this is a little faster than
- # vec += (rel.position - self.position) * w * self.distance(rel)
return vec
@@ -203,6 +199,11 @@
todo.append(rel)
self.subgraphs.append(todo)
+ def order_subgraphs(self):
+ sgs = [ (-len(sg), sg[0].name, sg) for sg in self.subgraphs]
+ sgs.sort()
+ self.subgraphs = [sg for lng, name, sg in sgs]
+
def normalize(self):
# identify disjoint subgraphs.
# for every subgraph:
@@ -211,6 +212,7 @@
# shift all graphs to be in disjoint intervals on the x-axis.
if not self.subgraphs:
self.compute_subgraphs()
+ self.order_subgraphs()
def distort(nodes):
# stretch collapsed x-axis
for i, node in enumerate(nodes):
@@ -221,8 +223,11 @@
xmin, xmax = self.xminmax(nodes)
xwidth = xmax - xmin
if not xwidth: # degenerated
- return norm_subgraph(distort(nodes))
- factor = (len(nodes) - 1) / xwidth
+ if len(nodes) > 1:
+ return norm_subgraph(distort(nodes), start)
+ factor = 1.0
+ else:
+ factor = (len(nodes) - 1) / xwidth
mean = Vector()
for node in nodes:
mean += node.position
@@ -244,16 +249,10 @@
start += len(nodes)
self.lastdim = dim
- def do_correction(self, korr=0.13):
+ def do_correction(self, korr=0.0002):
forcevecs = [node.forcevector() for node in self.nodes]
- corrx = [vec[0] for vec in forcevecs]
- maxcorr = abs(max(corrx))
- xmin, xmax = self.xminmax()
- xwidth = xmax - xmin
- scale = xwidth / maxcorr
- scale = scale * korr
for node, forcevec in zip(self.nodes, forcevecs):
- corrvec = forcevec * scale
+ corrvec = forcevec * korr
node.shift(corrvec)
def squeeze_dim(self):
@@ -273,16 +272,16 @@
return Vector(lonely).norm2()
def lonelyness(self):
- # square norm of lonelynesses
+ # sum norm of lonelynesses
lonely = 0.0
for node in self.nodes:
lonely += node.lonelyness()
return lonely / len(self.nodes)
def order(self):
- sorter = [(node.position[0], node) for node in self.nodes]
+ sorter = [(node.position[0], node.name, node) for node in self.nodes]
sorter.sort()
- return [node for x, node in sorter]
+ return [node for x, x, node in sorter]
def display(self):
for node in self.order():
@@ -297,9 +296,15 @@
def d(): e()
def e(): f()
def f(): a()
- sim = DemoSim([a, b, c, d, e, f])
+ sim = SimGraph([a, b, c, d, e, f])
+ sim.sim_all(0.9, 50)
+ return sim
+ def test_singleton():
+ def s(): pass
+ sim = SimGraph([s])
sim.sim_all(0.9, 50)
return sim
g = SpaceGraph(test())
g.addgraph(test())
g.addgraph(test())
+ g.addgraph(test_singleton())
Modified: pypy/dist/pypy/translator/locality/simulation.py
==============================================================================
--- pypy/dist/pypy/translator/locality/simulation.py (original)
+++ pypy/dist/pypy/translator/locality/simulation.py Mon Oct 31 15:49:34 2005
@@ -80,6 +80,9 @@
for node in self.callers:
freq = self.sim.transitions[ (node, self) ]
ret.append( (-freq, node) )
+ # if there is nothing, link it to itself
+ if not ret:
+ ret.append( (-1, self) )
ret.sort()
freqs, nodes = zip(*ret)
return nodes, [-freq for freq in freqs]
More information about the Pypy-commit
mailing list