Add Kernel Optimization Template to PromptManager#90
Open
kaiming-cheng wants to merge 35 commits intomainfrom
Open
Add Kernel Optimization Template to PromptManager#90kaiming-cheng wants to merge 35 commits intomainfrom
kaiming-cheng wants to merge 35 commits intomainfrom
Conversation
Consolidates previous kernel_benchmark.py and pytorch_benchmark.py into a streamlined 3-file architecture with clear separation of concerns: Architecture: - benchmark.py (299 lines): Main Benchmark class with simplified API - benchmark_kernel(): Always uses subprocess for crash protection - benchmark_pytorch(): Always uses direct mode for stable code - BenchmarkLockManager: GPU lock management for multi-worker scenarios - timing.py (437 lines): Complete timing infrastructure - Timing: time_with_cuda_events(), time_with_triton_do_bench() - Loading: prepare_pytorch_model(), load_kernel_function() - Stats: compute_timing_stats() with essential metrics (mean/std/min/max) - kernel_subprocess.py (442 lines): Subprocess runner for kernel isolation - Crash protection for potentially buggy kernels - Clean CUDA state between runs - Timeout handling Key improvements: - Eliminated string code generation (was generating Python as strings) - Removed unnecessary statistics (median, p25/p75/p95/p99) - Removed confusing use_subprocess parameter (behavior now deterministic) - Fixed dtype bug causing incorrect speedup measurements - Reduced from 5 files to 3 files with clearer naming - Code reduction: ~1,400 lines → 1,178 lines Simple API: bench = Benchmark(logger, temp_dir, lock, worker_id) pytorch_result = bench.benchmark_pytorch(problem_file) kernel_result = bench.benchmark_kernel(kernel_file, problem_file) speedup = pytorch_result['stats']['mean'] / kernel_result['time_ms']
Jack-Khuu
approved these changes
Feb 4, 2026
Contributor
Jack-Khuu
left a comment
There was a problem hiding this comment.
Not in this PR so you don't need to change it, but once everything lands we should consider creating arg dataclasses, so that we aren't passing around 10+ arg to functions
| ... print(f"SM Count: {specs['sm_count']}") | ||
| """ | ||
| if gpu_name in GPU_SPECS_DATABASE: | ||
| return GPU_SPECS_DATABASE[gpu_name].copy() |
Contributor
There was a problem hiding this comment.
Is this just to prevent folks from editing it by accident? If so consider GPU_SPECS_DATABASE = MappingProxyType(GPU_SPECS_DATABASE)
This makes it so that you can read from the DB, but not write. Removes the need for this file
| root_causes: list[dict[str, Any]] = field(default_factory=list) | ||
| recommended_fixes: list[dict[str, Any]] = field(default_factory=list) | ||
|
|
||
| def to_dict(self) -> dict[str, Any]: |
Contributor
There was a problem hiding this comment.
If we aren't customizing to_dict, have callers use asdict
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.
This PR adds a new Jinja2 template for bottleneck-guided kernel optimization.
Each optimization round targets exactly one root cause with one recommended fix
kernel_optimization.j2
prompt_manager.py
render_kernel_optimization_prompt()with explicit params: category, summary, reasoning, root_cause, recommended_fixExample Usage