Mercurial > cgi-bin > hgwebdir.cgi > VMS > 2__runs_and_data
changeset 18:c946cba3fda0
column view
author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
---|---|
date | Thu, 08 Mar 2012 18:52:19 +0100 |
parents | 2021f42cc672 |
children | b77d4ace3619 |
files | scripts/ucc_and_loop_graph_treatment/column_view.py scripts/ucc_and_loop_graph_treatment/parse_loop_graph.py |
diffstat | 2 files changed, 241 insertions(+), 39 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/scripts/ucc_and_loop_graph_treatment/column_view.py Thu Mar 08 18:52:19 2012 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +#!/usr/bin/python 1.5 + 1.6 +import svgfig as sf 1.7 + 1.8 +__column_width = 100 1.9 + 1.10 + 1.11 + 1.12 +def fig_from_node(graph,node,positioning=None): 1.13 + """Build globally positioned node representation.""" 1.14 + core = graph.node[node]['core'] 1.15 + if positioning==None: 1.16 + x1 = core * 3 * __column_width + __column_width 1.17 + else: 1.18 + x1 = core * 3 * __column_width + 2 * __column_width 1.19 + x2 = x1 + __column_width 1.20 + if positioning != None: 1.21 + y1 = positioning[node] - graph.node[node]['weight'] 1.22 + elif graph.node[node].has_key('AssignerInvocation_start'): 1.23 + y1 = graph.node[node]['AssignerInvocation_start'] - graph.node['start']['starttimes'][core] 1.24 + elif graph.node[node].has_key('Assigner_start'): 1.25 + y1 = graph.node[node]['Assigner_start'] - graph.node['start']['starttimes'][core] 1.26 + elif graph.node[node].has_key('Work_start'): 1.27 + y1 = graph.node[node]['Work_start'] - graph.node['start']['starttimes'][core] 1.28 + elif graph.node[node].has_key('AppResponderInvocation_start'): 1.29 + y1 = graph.node[node]['AppResponderInvocation_start'] - graph.node['start']['starttimes'][core] 1.30 + elif graph.node[node].has_key('AppResponder_start'): 1.31 + y1 = graph.node[node]['AppResponder_start'] - graph.node['start']['starttimes'][core] 1.32 + else: 1.33 + raise NameError('Node insufficiently annotated') 1.34 + y2 = y1 + graph.node[node]['weight'] 1.35 + if positioning != None and node[0]>7: 1.36 + f='blue' 1.37 + elif node[0]>7: 1.38 + f='red' 1.39 + else: 1.40 + f='gray' 1.41 + r = sf.Rect(x1,y1,x2,y2,fill=f) 1.42 + s = sf.Text((x1+x2)/2 , (y1+y2)/2 ,str(node),text_anchor="middle") 1.43 + if graph.node[node].has_key('AssignerInvocation_start') and graph.node[node].has_key('Assigner_start'): 1.44 + h = graph.node[node]['Assigner_start'] - graph.node[node]['AssignerInvocation_start'] 1.45 + r1 = sf.Rect(x1,y1,x2,y1+h,fill='green',fill_opacity="70%") 1.46 + return sf.Fig(r,r1,s) 1.47 + return sf.Fig(r,s) 1.48 + 1.49 +def tsc_fig_from_node(graph,node,maxh): 1.50 + tscstarttime = graph.node['start']['tscstarttime'] 1.51 + core = graph.node[node]['core'] 1.52 + x1 = 3 * core * __column_width 1.53 + x2 = x1 + __column_width 1.54 + y1 = graph.node[node]['Timestamp_start'] - tscstarttime 1.55 + if graph.node[node].has_key('Timestamp_end'): 1.56 + y2 = graph.node[node]['Timestamp_end'] - tscstarttime 1.57 + else: 1.58 + y2 = y1 + graph.node[node]['weight'] 1.59 + if node[0]>7: 1.60 + f='yellow' 1.61 + else: 1.62 + f='gray' 1.63 + r = sf.Rect(x1,y1,x2,y2,fill=f) 1.64 + s = sf.Text((x1+x2)/2 , (y1+y2)/2 ,str(node),text_anchor="middle") 1.65 + try: 1.66 + if maxh < y2: 1.67 + maxh = y2 1.68 + except: 1.69 + pass 1.70 + return sf.Fig(r,s),maxh 1.71 + 1.72 +def fig_nodes(graph,vertical_scale_factor,positioning=None): 1.73 + """Build all nodes.""" 1.74 + nodes = [] 1.75 + for node in graph: 1.76 + if node != 'start' and node != 'end': 1.77 + try: 1.78 + nodes.append(fig_from_node(graph,node,positioning=positioning)) 1.79 + except Exception as e: 1.80 + print node,e 1.81 + return sf.Fig(*nodes,trans="x,{}*y".format(vertical_scale_factor)) 1.82 + 1.83 +def save_column_view(graph,num_cores,total_height,positioning=None): 1.84 + vertical_scale_factor = 10000.0/float(total_height) 1.85 + f = sf.Fig(fig_nodes(graph,vertical_scale_factor,positioning=positioning)) 1.86 + f.d.append(get_tsc_scale(graph,num_cores,total_height)) 1.87 + if positioning!=None: 1.88 + f.d.append(fig_nodes(graph,vertical_scale_factor)) 1.89 + w = 3*__column_width*num_cores 1.90 + c = sf.canvas(f.SVG(),width="{}px".format(w),height="10000px",viewBox='0 0 {} 10000'.format(w)) 1.91 + c.save() 1.92 + 1.93 +def get_tsc_scale(graph,num_cores,total_height): 1.94 + nodes=sf.Fig() 1.95 + maxh = 0 1.96 + for node in graph: 1.97 + if node != 'start' and node != 'end': 1.98 + try: 1.99 + n , maxh = tsc_fig_from_node(graph,node,maxh) 1.100 + nodes.d.append(n) 1.101 + except Exception as e: 1.102 + print node,e 1.103 + nodes.trans = "x,{}*y".format(10000.0/float(total_height)) 1.104 + return nodes 1.105 + 1.106 +def save_tsc_scale(graph,num_cores,total_height): 1.107 + nodes = get_tsc_scale(graph,num_cores,total_height) 1.108 + w = 3*__column_width*num_cores 1.109 + #h = maxh 1.110 + c = sf.canvas(nodes.SVG(),width="{}px".format(w),height="{}px".format(10000),viewBox='0 0 {} {}'.format(w,10000)) 1.111 + c.save('tsc.svg')
2.1 --- a/scripts/ucc_and_loop_graph_treatment/parse_loop_graph.py Fri Feb 10 16:15:55 2012 +0100 2.2 +++ b/scripts/ucc_and_loop_graph_treatment/parse_loop_graph.py Thu Mar 08 18:52:19 2012 +0100 2.3 @@ -4,6 +4,7 @@ 2.4 import csv 2.5 import networkx as nx 2.6 import matplotlib.pyplot as plt 2.7 +import column_view 2.8 2.9 def read_from_file(filename): 2.10 d = {} 2.11 @@ -35,33 +36,6 @@ 2.12 continue 2.13 return d 2.14 2.15 -def add_attributes_to_nodes_from_file(g,filename): 2.16 - counterreader = (csv.reader)(filename,skipinitialspace=True) 2.17 - for row in counterreader: 2.18 - if row[0] == "event": 2.19 - n = (int(row[2]),int(row[3])) 2.20 - g.node[n][row[1]] = int(row[4]) 2.21 - g.node["start"]['weight'] = 0 2.22 - g.node["end"]['weight'] = 0 2.23 - for n in g: 2.24 - try: 2.25 - if n!="start" and n!="end": 2.26 - g.node[n]['weight'] = g.node[n]['CoreLoop_afterWork'] - g.node[n]['CoreLoop_beforeWork'] + g.node[n]['MasterLoop_afterReqHdlr'] - g.node[n]['MasterLoop_beforeReqHdlr'] + g.node[n]['MasterLoop_afterAssign'] - g.node[n]['MasterLoop_beforeAssign'] 2.27 - except KeyError as e: 2.28 - print e,n 2.29 - 2.30 - 2.31 -# counterreader = (csv.reader)(filename) 2.32 -# for row in counterreader: 2.33 -# n = (int(row[0]),int(row[1])) 2.34 -# g.node[n]['suspend_point'] = row[2] 2.35 -# g.node[n]['schedule_check_cycles'] = int(row[4])-int(row[19]) 2.36 -# g.node[n]['sync_cycles'] = int(row[25])-int(row[24]) 2.37 -# g.node[n]['assign_cycles'] = int(row[10])-int(row[7]) 2.38 -# g.node[n]['work_comm_cycles'] = int(row[16])-int(row[13]) 2.39 -# g.node[n]['status_cycles'] = int(row[22])-int(row[16]) 2.40 -# g.node[n]['weight'] = g.node[n]['schedule_check_cycles'] + g.node[n]['sync_cycles'] + g.node[n]['assign_cycles'] + g.node[n]['work_comm_cycles'] + g.node[n]['status_cycles'] 2.41 - 2.42 def loopgraph_from_dict(d): 2.43 g = nx.DiGraph() 2.44 g.add_node("start") 2.45 @@ -84,8 +58,60 @@ 2.46 g.add_edge(node,"end") 2.47 return g 2.48 2.49 +def add_attributes_to_nodes_from_file(g,filename): 2.50 + counterreader = (csv.reader)(filename,skipinitialspace=True) 2.51 + for row in counterreader: 2.52 + if row[0] == "event": 2.53 + n = (int(row[2]),int(row[3])) 2.54 + g.node[n][row[1]] = int(row[4]) 2.55 + g.node[n]['core'] = int(row[6]) 2.56 + g.node["start"]['weight'] = 0 2.57 + g.node["end"]['weight'] = 0 2.58 + starttimes = {} 2.59 + tscstarttimes = {} 2.60 + tscendtimes = {} 2.61 + for n in g: 2.62 + try: 2.63 + if n!="start" and n!="end": 2.64 + weight = 0 2.65 + if g.node[n].has_key('Assigner_start') and g.node[n].has_key('AssignerInvocation_start'): 2.66 + weight += g.node[n]['Assigner_start'] - g.node[n]['AssignerInvocation_start'] 2.67 + if g.node[n].has_key('Assigner_end') and g.node[n].has_key('Assigner_start'): 2.68 + weight += g.node[n]['Assigner_end'] - g.node[n]['Assigner_start'] 2.69 + if g.node[n].has_key('Work_start') and g.node[n].has_key('Assigner_end'): 2.70 + weight += g.node[n]['Work_start'] - g.node[n]['Assigner_end'] 2.71 + if g.node[n].has_key('Work_end') and g.node[n].has_key('Work_start'): 2.72 + weight += g.node[n]['Work_end'] - g.node[n]['Work_start'] 2.73 + if g.node[n].has_key('AppResponderInvocation_start') and g.node[n].has_key('Work_end'): 2.74 + weight += g.node[n]['AppResponderInvocation_start'] - g.node[n]['Work_end'] 2.75 + if g.node[n].has_key('AppResponder_start') and g.node[n].has_key('AppResponderInvocation_start'): 2.76 + weight += g.node[n]['AppResponder_start'] - g.node[n]['AppResponderInvocation_start'] 2.77 + if g.node[n].has_key('AppResponder_end') and g.node[n].has_key('AppResponder_start'): 2.78 + weight += g.node[n]['AppResponder_end'] - g.node[n]['AppResponder_start'] 2.79 + if g.node[n].has_key('NextAssigner_start') and g.node[n].has_key('AppResponder_end'): 2.80 + weight += g.node[n]['NextAssigner_start'] - g.node[n]['AppResponder_end'] 2.81 + assert weight > 0 2.82 + g.node[n]['weight'] = weight #+ weight/10 2.83 + if g.node[n].has_key('AssignerInvocation_start'): 2.84 + if not starttimes.has_key(g.node[n]['core']) or starttimes[g.node[n]['core']] > g.node[n]['AssignerInvocation_start']: 2.85 + starttimes[g.node[n]['core']] = g.node[n]['AssignerInvocation_start'] 2.86 + if g.node[n].has_key('Timestamp_start'): 2.87 + if not tscstarttimes.has_key(g.node[n]['core']) or tscstarttimes[g.node[n]['core']] > g.node[n]['Timestamp_start']: 2.88 + tscstarttimes[g.node[n]['core']] = g.node[n]['Timestamp_start'] 2.89 + if g.node[n].has_key('Timestamp_start'): 2.90 + if not tscendtimes.has_key(g.node[n]['core']) or tscendtimes[g.node[n]['core']] < g.node[n]['Timestamp_start']: 2.91 + tscendtimes[g.node[n]['core']] = g.node[n]['Timestamp_start'] 2.92 + except Exception as e: 2.93 + print e,n 2.94 + g.node['start']['starttimes']=starttimes 2.95 + g.node['start']['tscstarttimes']=tscstarttimes 2.96 + g.node['start']['tscstarttime']=min(tscstarttimes.values()) 2.97 + g.node['start']['tscendtime']=max(tscendtimes.values()) 2.98 + 2.99 def path_length(graph,path): 2.100 length = 0 2.101 + if path==None: 2.102 + return 0 2.103 for node in path: 2.104 try: 2.105 length += graph.node[node]['weight'] 2.106 @@ -101,14 +127,44 @@ 2.107 if not graph.has_node(end): 2.108 return None 2.109 longest = None 2.110 + print graph.predecessors(end) 2.111 for node in graph.predecessors(end): 2.112 if node not in path: 2.113 newpath = find_critical_path(graph, start, node, path) 2.114 - if newpath: 2.115 - if not longest or path_length(graph,newpath) > path_length(graph,longest): 2.116 + if newpath!=None: 2.117 + ll=path_length(graph,longest) 2.118 + nl=path_length(graph,newpath) 2.119 + if (longest==None) or nl > ll: 2.120 longest = newpath 2.121 + #print nl, ll 2.122 return longest 2.123 2.124 +def annotate_critical_path(graph, start, end, lend={}, predd={}): 2.125 + path_to_here = 0 2.126 + if len(graph.predecessors(end)) == 0: 2.127 + assert end == start 2.128 + for node in graph.predecessors(end): 2.129 + if not lend.has_key(node): 2.130 + lend,predd = annotate_critical_path(graph, start, node, lend, predd) 2.131 + try: 2.132 + if lend[node] > path_to_here: 2.133 + path_to_here = lend[node] 2.134 + predd[end] = node 2.135 + except KeyError: 2.136 + print node, nlend 2.137 + exit(0) 2.138 + lend[end] = path_to_here + graph.node[end]['weight'] 2.139 + return lend,predd 2.140 + 2.141 +def get_path(predd,end): 2.142 + path = [] 2.143 + node = end 2.144 + while predd.has_key(node): 2.145 + path = [node] + path 2.146 + node = predd[node] 2.147 + path = [node] + path 2.148 + return path 2.149 + 2.150 def build_cg(loopfile,counterfile): 2.151 d = read_from_file(loopfile) 2.152 print "Parsed file", loopfile.name, "and found:" 2.153 @@ -124,16 +180,43 @@ 2.154 print len(d["hwDep"]), "Hardware constraints" 2.155 g = loopgraph_from_dict(d) 2.156 add_attributes_to_nodes_from_file(g,counterfile) 2.157 - critical_path = find_critical_path(g,"start","end") 2.158 + #cont = raw_input("Calculate and show critical path (y/N)? ") 2.159 + #if not cont.startswith(('y','Y')): 2.160 + # sys.exit() 2.161 + lend,predd = annotate_critical_path(g, 'start', 'end') 2.162 + print "Critical path length:",lend['end'] 2.163 + critical_path = get_path(predd,'end') 2.164 if critical_path == None: 2.165 print "No path found!" 2.166 nx.draw(g) 2.167 else: 2.168 - print "Expected execution time:\t",path_length(g,critical_path),"cycles" 2.169 + #print "Critical path:",critical_path 2.170 + print "Expected execution time:",path_length(g,critical_path),"cycles" 2.171 try: 2.172 - print "Actual execution time:\t", g.node[(2,98)]['MasterLoop_beforeReqHdlr'] - g.node[(2,1)]['MasterLoop_beforeAssign'], "cycles" 2.173 - except KeyError: 2.174 - pass 2.175 + actual_time = g.node['start']['tscendtime'] - g.node['start']['tscstarttime'] 2.176 + print "Actual execution time:", actual_time, "cycles" 2.177 + dif = actual_time - lend['end'] 2.178 + print "(Difference:", dif, "- Relative Error:", 100*float(dif)/float(lend['end']),"%)" 2.179 + print g.node['start']['starttimes'] 2.180 + print g.node['start']['tscstarttimes'] 2.181 + column_view.save_column_view(g,4,max(actual_time,lend['end']),lend) 2.182 + #column_view.save_tsc_scale(g,4,lend['end']) 2.183 + return # 2.184 + print "Node \tCalculated\t Actual\tCore\tDifference\tNon-cumulative part" 2.185 + drf = 0 2.186 + for n in critical_path: 2.187 + if g.node[n].has_key('AppResponder_end'): 2.188 + clen = g.node[n]['AppResponder_end'] 2.189 + elif g.node[n].has_key('AppResponder_start'): 2.190 + clen = g.node[n]['AppResponder_start'] 2.191 + else: 2.192 + print n 2.193 + if n!='start' and n!='end': 2.194 + print "{}\t{:10}\t{:10}\t({})\t{:10}\t{:10}".format(n,lend[n],clen,g.node[n]['core'],clen-lend[n],clen-lend[n]-drf) 2.195 + drf = clen-lend[n] 2.196 + except KeyError as e: 2.197 + print e 2.198 + return # 2.199 colors = [] 2.200 for node in g.nodes(): 2.201 if node in critical_path: 2.202 @@ -145,12 +228,23 @@ 2.203 2.204 2.205 def main(): 2.206 - if len(sys.argv)<2: 2.207 - sys.exit() 2.208 - uccfile = open(sys.argv[1]) 2.209 - counterfile = open(sys.argv[2]) 2.210 + if len(sys.argv)<3: 2.211 + if len(sys.argv)==2: 2.212 + uccfile = open("LoopGraph.{0}".format(sys.argv[1])) 2.213 + counterfile = open("Counters.{0}.csv".format(sys.argv[1])) 2.214 + else: 2.215 + print "Usage: {} SCGfile Counterfile".format(sys.argv[0]) 2.216 + sys.exit() 2.217 + else: 2.218 + uccfile = open(sys.argv[1]) 2.219 + counterfile = open(sys.argv[2]) 2.220 + print sys.getrecursionlimit() 2.221 build_cg(uccfile,counterfile) 2.222 2.223 2.224 if __name__ == "__main__": 2.225 - main() 2.226 + sys.setrecursionlimit(10000) 2.227 + try: 2.228 + main() 2.229 + except Exception as e: 2.230 + print e