8000 [feature request] add memory counter event to pytorch trace result · Issue #577 · gaogaotiantian/viztracer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[feature request] add memory counter event to pytorch trace result #577
Open
@FindDefinition

Description

@FindDefinition

New Feature

We can use memory instant events in pytorch profiler result to generate a nice gpu memory trace in perfetto:

Image

This memory trace is aligned to python stack trace so it's more useful than pytorch solutions such as export_memory_timeline

I have implemented this by add profile_memory to torch.profiler.profile and parse pytorch trace events, I think viztracer can add this feature easily. we may use --log_torch and --log_torch_memory to enable this feature.

            for ev in pth_trace_dict["traceEvents"]:
                if (ev["ph"] == "I" or ev["ph"] == "i") and "args" in ev:
                    if "Total Allocated" in ev["args"]:
                        total_alloc = ev["args"]["Total Allocated"]
                        total_reserv = ev["args"]["Total Reserved"]
                        if ev["args"]["Device Id"] >= 0:
                            external_events.append({
                                "name": "pth_memory",
                                "ph": "C",
                                "pid": pid,
                                "tid": 0,
                                "ts": ev["ts"] + base_ts_us,
                                "args": {
                                    "Total Allocated": total_alloc,
                                    "Total Reserved": total_reserv,
                                },
                            })

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0