MCPcopy Create free account
hub / github.com/pytorch/tutorials / compare_traces

Function compare_traces

advanced_source/cuda_graph_annotations_tutorial.py:510–532  ·  view source on GitHub ↗

Compare kernel distribution before and after annotation.

(raw_trace, annotated_trace)

Source from the content-addressed store, hash-verified

508# across thread IDs (which represent visualization lanes in the trace).
509
510def compare_traces(raw_trace, annotated_trace):
511 """Compare kernel distribution before and after annotation."""
512 def count_lanes(trace):
513 """Count kernels per lane (tid)."""
514 counter = Counter(
515 event["tid"]
516 for event in trace["traceEvents"]
517 if event.get("cat") == "kernel"
518 )
519 return dict(sorted(counter.items()))
520
521 raw_lanes = count_lanes(raw_trace)
522 annotated_lanes = count_lanes(annotated_trace)
523
524 print("\n" + "="*60)
525 print("BEFORE annotation - kernels per lane (tid -> count):")
526 for tid, count in raw_lanes.items():
527 print(f" Stream {tid}: {count} kernels")
528
529 print("\nAFTER annotation - kernels per lane (tid -> count):")
530 for tid, count in annotated_lanes.items():
531 print(f" Stream {tid}: {count} kernels")
532 print("="*60)
533
534###############################################################################
535# Putting It All Together

Callers 1

mainFunction · 0.85

Calls 1

count_lanesFunction · 0.85

Tested by

no test coverage detected