This repository was archived by the owner on Nov 12, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcprof2allocinfo.py
More file actions
executable file
·122 lines (100 loc) · 3.09 KB
/
Copy pathcprof2allocinfo.py
File metadata and controls
executable file
·122 lines (100 loc) · 3.09 KB
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
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
import sys
import json
import csv
import math
import pycprof
Allocations = {}
Memories = {}
A2D = {}
D2A = {}
A2A = {}
Values = {}
def api_handler(api):
if type(api) != pycprof.API:
return
name = api.functionName
if name == "cudaLaunch" or "cublas" in name or "cudnn" in name:
dev = api.device
for v_id in api.inputs:
v = Values[v_id]
a_id = v.allocation_id
a = Allocations[a_id]
if v.size == 0:
v.size = a.size
if dev not in A2D:
A2D[dev] = {}
if a_id not in A2D[dev]:
A2D[dev][a_id] = []
A2D[dev][a_id] += [v.size]
for v_id in api.outputs:
v = Values[v_id]
a_id = v.allocation_id
a = Allocations[a_id]
if v.size == 0:
v.size = a.size
if dev not in D2A:
D2A[dev] = {}
if a_id not in D2A[dev]:
D2A[dev][a_id] = []
D2A[dev][a_id] += [v.size]
else:
for vin_id in api.inputs:
vin = Values[vin_id]
ain_id = vin.allocation_id
if ain_id not in A2A:
A2A[ain_id] = {}
for vout_id in api.outputs:
vout = Values[vout_id]
aout_id = vout.allocation_id
if aout_id not in A2A[ain_id]:
A2A[ain_id][aout_id] = []
assert(vin.size == vout.size)
# print "adding A2A"
A2A[ain_id][aout_id] += [vin.size]
def allocation_handler(a):
if type(a) != pycprof.Allocation:
return
Allocations[a.id_] = a
loc = a.mem.location
Id = a.mem.id_
if loc not in Memories:
Memories[loc] = {}
if Id not in Memories[loc]:
Memories[loc][Id] = {}
Memories[loc][Id][a.id_] = a
def value_handler(v):
if type(v) != pycprof.Value:
return
if v.id_ in Values:
print "duplicate value", v.id_, "overwriting..."
Values[v.id_] = v
pycprof.run_handler(allocation_handler)
print len(Allocations), "allocations found"
pycprof.run_handler(value_handler)
print len(Values), "values found"
pycprof.run_handler(api_handler)
print max(len(D2A), len(A2D)), "devices"
pycprof.set_edge_fields(["Weight"])
pycprof.set_node_fields(["pos", "size"])
# Add allocation nodes
for aid, alloc in Allocations.iteritems():
node = {"pos": alloc.pos, "size": alloc.size}
pycprof.add_node(aid, node)
# add device nodes
for dev in D2A:
pycprof.add_node(dev, {})
for dev in A2D:
pycprof.add_node(dev, {})
# add edges
for dev, xfers in D2A.iteritems():
for aid, sizes in xfers.iteritems():
pycprof.add_edge(dev, aid, {"Weight": math.log(sum(sizes),2)})
for dev, xfers in A2D.iteritems():
for aid, sizes in xfers.iteritems():
pycprof.add_edge(aid, dev, {"Weight": math.log(sum(sizes),2)})
for src, dsts in A2A.iteritems():
for dst in dsts:
pycprof.add_edge(src, dst, {"Weight": math.log(sum(sizes),2)})
pycprof.write_nodes("nodes")
pycprof.write_edges("edges")