Add native Perfetto (.pftrace) export to torch.profiler - #1
Open
ajassani wants to merge 1 commit into
Open
Conversation
Expose a new `export_pftrace()` API on both `torch.profiler.profile` (`_KinetoProfile`) and the legacy `torch.autograd.profiler.profile`, letting users write Perfetto protobuf traces directly instead of going through Chrome JSON conversion. Python side mirrors `export_chrome_trace`, including `.gz` handling. C++ side adds `ProfilerResult::savePftrace` / `ActivityTraceWrapper::savePftrace`, which route through Kineto's `pftrace://` save protocol, plus the pybind binding `save_pftrace`. Build is gated behind the new `USE_KINETO_PERFETTO` option (default OFF), which is plumbed to Kineto's `KINETO_ENABLE_PERFETTO`. When Kineto is built without Perfetto support the existing JSON path is unaffected. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Adds a native Perfetto (
.pftrace) export path totorch.profiler, so users can write Perfetto protobuf traces directly from a profiling session instead of exporting Chrome JSON and converting afterwards.export_pftrace(path)ontorch.profiler.profile(_KinetoProfile) and on the legacytorch.autograd.profiler.profile, mirroringexport_chrome_trace(including.gzhandling).ProfilerResult::savePftrace/ActivityTraceWrapper::savePftrace, routed through Kineto'spftrace://save protocol, exposed to Python assave_pftrace.USE_KINETO_PERFETTOCMake option (defaultOFF), plumbed to Kineto'sKINETO_ENABLE_PERFETTO.When Kineto is built without Perfetto support, behavior is unchanged and the existing JSON path is untouched.
This is the PyTorch-side companion to the Kineto change that implements the actual Perfetto trace logger and the
pftrace://protocol registration.Usage
Test plan
USE_KINETO_PERFETTO=ONagainst a Kineto built with Perfetto support (MI300-class GPU, ROCm)..pftracethat loads in the Perfetto UI..pftracewith device track events.USE_KINETO_PERFETTO=OFF(JSON path unchanged).