Show the full optimization plan with Amdahl's law analysis.
(state: dict)
| 714 | |
| 715 | |
| 716 | def cmd_plan(state: dict) -> None: |
| 717 | """Show the full optimization plan with Amdahl's law analysis.""" |
| 718 | plan = load_plan() |
| 719 | if plan is None: |
| 720 | print("ERROR: No optimization_plan.json found. Run extract.py first.") |
| 721 | sys.exit(1) |
| 722 | |
| 723 | kernels_plan = plan.get("kernels_to_optimize", plan.get("kernels", [])) |
| 724 | kernels_state = state["kernels"] |
| 725 | |
| 726 | # Build a lookup from file -> state entry |
| 727 | state_by_file: dict[str, dict] = {} |
| 728 | for k in kernels_state: |
| 729 | state_by_file[k["file"]] = k |
| 730 | state_by_file[Path(k["file"]).name] = k |
| 731 | |
| 732 | print() |
| 733 | print("=" * 65) |
| 734 | print(" AutoKernel -- Optimization Plan") |
| 735 | print("=" * 65) |
| 736 | print() |
| 737 | |
| 738 | # Plan table |
| 739 | total_gpu_time = plan.get("total_gpu_time_ms", 0) |
| 740 | if total_gpu_time > 0: |
| 741 | print(f" Total profiled GPU time: {total_gpu_time:.1f} ms") |
| 742 | print() |
| 743 | |
| 744 | print(f" {'Rank':<5} {'Op Type':<20} {'Shape':<30} {'GPU Time (ms)':<15} {'% Total':<10} {'Status':<12} {'Speedup':<10}") |
| 745 | print(f" {'-'*5} {'-'*20} {'-'*30} {'-'*15} {'-'*10} {'-'*12} {'-'*10}") |
| 746 | |
| 747 | for kp in kernels_plan: |
| 748 | rank = kp.get("rank", "?") |
| 749 | op_type = kp.get("op_type", "unknown") |
| 750 | shape = kp.get("shape", "") |
| 751 | if isinstance(shape, dict): |
| 752 | shape = ", ".join(f"{k}={v}" for k, v in shape.items()) |
| 753 | elif isinstance(shape, list): |
| 754 | shape = str(shape) |
| 755 | gpu_time = kp.get("gpu_time_ms", 0) |
| 756 | pct_total = kp.get("pct_total", 0) |
| 757 | |
| 758 | # Match to state |
| 759 | file_key = kp.get("file", "") |
| 760 | sk = state_by_file.get(file_key) or state_by_file.get(Path(file_key).name) if file_key else None |
| 761 | |
| 762 | status = sk["status"].upper() if sk else "UNKNOWN" |
| 763 | speedup_str = f"{sk['speedup']:.2f}x" if sk and sk.get("speedup") else "--" |
| 764 | |
| 765 | # Truncate shape for display |
| 766 | shape_disp = shape[:28] + ".." if len(str(shape)) > 30 else str(shape) |
| 767 | |
| 768 | print(f" {rank:<5} {op_type:<20} {shape_disp:<30} {gpu_time:<15.2f} {pct_total:<10.1f} {status:<12} {speedup_str:<10}") |
| 769 | |
| 770 | print() |
| 771 | |
| 772 | # Amdahl's law what-if analysis |
| 773 | print(" Amdahl's Law What-If Analysis:") |
no test coverage detected