Repository navigation
[Tools] Perfetto profile dump (trace, tile traces, index page) replaces util_viewer - #536
Draft
student-Jungmin wants to merge 4 commits into
Draft
student-Jungmin wants to merge 4 commits into
student-Jungmin wants to merge 4 commits into
Conversation
student-Jungmin
marked this pull request as draft
November 14, 2026 03:42
…M_GEM5_TRACE=1
With TORCHSIM_GEM5_TRACE=1 the cycle-table run passes --coprocessor-trace-file=coprocessor_trace.pftrace to
gem5, which writes the sampled tiles' coprocessor trace as a Perfetto binary trace in schema
coprocessor-trace/2 (1 cycle = 1 ns). write_cycle_tables reads it with the decoder in
pytorchsim/simulator/perfetto_trace.py and splits it into tog_tile_timeline.pftrace beside
tog_tile_cycles.tsv: one process per cycle-table row, named by row, tile, call and cycles, with the
instruction lanes ("insn", "insn 2", ...) as threads and one counter track per <group>.<counter>. Each dump
closes the window the latest reset opened; slices are clipped to the window, a counter's held value is carried
in at the window start and everything is rebased to it. A schema other than coprocessor-trace/2, a window
count or a window length that disagrees with the cycle table is refused instead of tabled. The file carries a
tog-tile-timeline/2 schema instant and ts in cycles at 1 ns each. Off by default; nothing changes for a run
without the variable.
perfetto_trace.py is the codec, a hand-written protobuf wire encoder and decoder with no dependency:
encode_trace and decode_trace between a Chrome-style event dict and the binary Trace, and decode_tracks for a
trace with inline names such as gem5's. It lands here because gem5.py needs it at compile time; its unit tests
are in test_perfetto_trace.py.
Depends on gem5 (PSAL-POSTECH/gem5, branch coprocessor-trace: coprocessorTraceFile on the Coprocessor unit)
and on the Coprocessor repository's script_systolic.py --coprocessor-trace-file option (branch
coprocessor-trace). The new test needs neither: it splits a two-window prefix and the whole of a real sample
checked into tests/system/data/viewer, and a hand-encoded trace for clipping and carried counters.
… one tile trace per kernel scripts/dump_profile.py reads TOGSim logs and writes <out>/trace.pftrace, a Perfetto binary trace on the simulated time axis: runs laid end to end in log order, ts and dur in microseconds (cycles / core MHz) and the raw cycles (start_cycle, cycles) in the args of every kernel, copy, DMA, compute and tile slice or instant. Per NPU core it has a Kernels thread (one slice per launch, with cycles including and excluding its copy_node runs, workdir, the model lines and ATen ops from TORCH_TRACE or Inductor's debug dir, and the relative paths tile_trace, source and dump_dir to go to next), a copy thread, one utilization counter per unit from the Core stat windows, and, for a trace-level log, DMA read/write, compute lanes and tile markers. A DRAM process has GB/s, utilization and request counters (per-channel ones with --dram-channels). Runs that scheduled nothing are listed in the metadata and left off. The axis (machine, core MHz, "simulated runs concatenated in log order; 1 us = N cycles") and the verdict rule ride on the trace's metadata instant. Each kernel slice also has a utilization-based speed of light (scripts/profile_sol.py, no FLOP counts): the utilization of Issue, MXU, Vpu, XLU, SFU and MISC (util_<unit>), the compute peak and its unit (sol_compute_pct, sol_compute_unit), DRAM GB/s and % of the peak in the log's "Total bandwidth" line, DMA busy % and a verdict: compute-bound (<unit>), memory-bound (DRAM), DMA-latency-bound or latency/dependency-bound. They are the cycle-weighted mean of the Core stat and DRAM windows overlapping the kernel's span (its copy_node runs included, as in cycles_incl_copy), or of the whole-run table when no window does (sol_source says which). BOUND = 60 and LOW = 20 are named constants: compute or DRAM at BOUND is bound, DMA at BOUND under LOW DRAM is DMA-latency-bound, anything else latency/dependency-bound. The binary writer is the codec in pytorchsim/simulator/perfetto_trace.py (previous commit). The binary form can only nest slices, so check_trace refuses overlapping non-nested slices of a thread. cname colors are not carried. Fields used are listed in the codec's docstring and the schema is Perfetto's trace protos. With the kernel's tog_tile_timeline.pftrace (TORCHSIM_GEM5_TRACE=1, or --tile-timeline KERNEL=PATH) it also writes tiles/<kernel>.pftrace: the timeline with the kernel's name added to its metadata, one process per cycle-table row; a timeline of another schema is refused and kernels without one are skipped. Checked against Perfetto's trace processor in a throwaway container: for the 4-run demo trace, slices per (thread, name), global instants, counter tracks and samples (795) equal the encoded event model, ts and dur within 1 ns and the kernel slice's scalar args equal; the tile trace likewise. Needs pip and network, so it is not a test. The tests cover the tile trace, speed of light, args and metadata without Slurm, gem5 or a browser. Depends on the preceding commit for the codec and the tile timeline file; scripts/trace_timeline.py and scripts/util_viewer.py are not modified.
…LE_DUMP=1 writes the dump at exit dump_profile.py now also writes index.html beside trace.pftrace: a summary (total cycles, kernel launches, machine), a cycle-weighted run verdict with the share of cycles per verdict, a kernel table and links to the trace, TORCH_TRACE and tlparse (--tlparse). Under the trace link one sentence names the time axis (runs laid end to end, 1 us = N cycles). Under Kernels a note states that the speed of light is utilization-based, not a FLOP roofline, with the BOUND and LOW thresholds of scripts/profile_sol.py. The kernel table has launches, cycles including copy_node runs, share, compute % with its unit, DRAM % of peak, DMA % and a verdict (a colored badge by CSS only; numbers merged over the kernel's launches by cycle span, the verdict decided again from the merged numbers). Each row's links start with tile detail (tiles/<kernel>.pftrace, with its own "tile in Perfetto" button), source (the generated Triton source) and the earliest stage MLIR, then the dump directory, the other stage files and timing.json. The page's only script is the Open in Perfetto button: it fetches the named .pftrace, opens ui.perfetto.dev and posts the binary buffer (from file:// it offers a file picker instead). Plain HTML and CSS, light and dark, usable at phone width, links relative to the dump and only to files that exist, written as UTF-8. TORCHSIM_PROFILE_DUMP=1 (pytorchsim/config.py) makes every TOGSim log this process starts (TOGSimProcess and run_standalone outside autotune) be recorded, and an atexit hook writes <dump path>/profile/ from them (pytorchsim/simulator/profile_dump.py); a failure there is printed to stderr and does not change the exit status. TORCH_TRACE is linked and used for origins when set. Builds on the preceding dump_profile commit. The new test_profile_dump cases run without Slurm, gem5 or a browser; the two TOGSim hook sites need a real TOGSim and are not exercised by them.
…replace it scripts/dump_profile.py and the profile/ directory it writes (trace.pftrace for Perfetto, tiles/<kernel>.pftrace, a thin index.html; also written at exit with TORCHSIM_PROFILE_DUMP=1) replace the self-contained util_viewer.py page. Deleted with it: tests/system/test_breakdown_viewer.py, which only exercised that script, and its entries in the CI test list. scripts/trace_timeline.py stays because dump_profile's trace exporter parses trace-level logs with it. No Python code imports util_viewer; prose mentions remain in .claude/CLAUDE.md (left as they are).
student-Jungmin
force-pushed
the
viewer-perfetto
branch
from
November 16, 2026 04:55
ace3a71 to
b4f28d9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces scripts/util_viewer.py with file dumps opened in standard tools. With TORCHSIM_PROFILE_DUMP=1 (or scripts/dump_profile.py over existing results) PyTorchSim writes /profile/:
PyTorch's own guidance is to view profiler traces in Perfetto (the TensorBoard profiler integration was deprecated and its tutorial removed). The trace codec is a small hand-written protobuf encoder/decoder (pytorchsim/simulator/perfetto_trace.py), no new dependency.
Depends on PSAL-POSTECH/gem5#22 and PSAL-POSTECH/Coprocessor#72 for the tile timeline (gem5 schema coprocessor-trace/2); without them only the tile traces are missing.
Tests: test_perfetto_trace, test_gem5_trace_split, test_profile_dump (37 tests, no Slurm/gem5/browser needed). The written traces were also checked against Perfetto's trace processor.
Not yet verified: the automatic dump inside a real PyTorchSim run (the TOGSim hook sites need a real TOGSim), the compiler-side tile labels, a full suite on this base, and the new gem5 in the runtime image.