Skip to content

Commit f52d8ab

Browse files
Eashan Gargfacebook-github-bot
authored andcommitted
Handle multiple memory IDs using pid (#2974)
Summary: Pull Request resolved: #2974 Handle multiple memory IDs by dumping them into different processes in trace view. This solution seemed the simplest, and since the time stamps match between processes it should be fairly straightforward to look through An alternate solution I attempted was to place different memory spaces across each other separated by some horizontal "space". However, it quickly became ugly/difficult to differentiate which allocation was on which memory space - I think the above solution is probably the easier one to read. Reviewed By: kimishpatel, Olivia-liu, hsharma35 Differential Revision: D55494986 fbshipit-source-id: 1847f8c13bfed4db3f3baa3a61bcff77da69ff68
1 parent fadc076 commit f52d8ab

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

util/activation_memory_profiler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
5353
"""
5454
nodes = graph.nodes
5555
memory_timeline = [None] * len(nodes)
56-
for i, node in enumerate(nodes):
56+
for _, node in enumerate(nodes):
5757
if node.op == "output":
5858
continue
5959
if node.target == memory.alloc:
@@ -80,7 +80,7 @@ def create_tensor_allocation_info(graph: torch.fx.Graph) -> List[MemoryTimeline]
8080
Allocation(
8181
node.name,
8282
node.target,
83-
i,
83+
tensor_spec.mem_id,
8484
tensor_spec.mem_offset,
8585
size,
8686
fqn,
@@ -148,10 +148,13 @@ def generate_memory_trace(
148148
)
149149
allocation_size_kb = allocation.size_bytes
150150
e["dur"] = int(allocation_size_kb)
151-
e["pid"] = 0
151+
e["pid"] = int(allocation.memory_id)
152152
e["tid"] = tid
153153
e["args"] = {}
154154
e["args"]["op_name"] = f"{allocation.op_name}"
155+
# ID refers to memory space, typically from 1 to N.
156+
# For CPU, everything is allocated on one "space", other backends may have multiple.
157+
e["args"]["Memory ID"] = allocation.memory_id
155158
e["args"]["fqn"] = f"{allocation.fqn}"
156159
e["args"]["source"] = f"{allocation.file_and_line_num}"
157160
e["args"]["bytes"] = allocation.size_bytes

0 commit comments

Comments
 (0)