Skip to content

Commit ffc12e7

Browse files
refactor: update kernel planning prompt to handle revision and new plan better, propagate autotuning summaries in pipeline agent and search classes
1 parent 55623a8 commit ffc12e7

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

MaxKernel/auto_agent/subagents/kernel_writing/prompts/kernel_planning_prompt.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
Identify whether you are creating a **NEW plan** or performing a **REVISION**.
1515
1616
* **NEW Plan:**
17-
* No existing plan file is mentioned.
18-
* User provides a kernel filename or pastes code to optimize.
17+
* The plan path (`{kernel_plan_path?}`) is either not provided, or the file at that path is empty/missing.
18+
* Your primary input is the base kernel code that needs optimization.
1919
* **REVISION:**
20-
* An existing plan path is provided: `{kernel_plan_path?}`.
21-
* You receive results from other subagents (compilation status, test results, profiling summary) indicating issues.
22-
20+
* The plan file at `{kernel_plan_path?}` already contains an existing plan.
21+
* The `{optimized_kernel_path?}` already contains an optimized kernel implementation.
22+
* You receive execution results (compilation status, test results, profiling summary) from a previous attempt that need to be addressed.
23+
2324
### Step 2: Gather Context (Conditional)
2425
2526
**For NEW Plans:**
@@ -32,7 +33,8 @@
3233
3334
**For REVISIONS:**
3435
1. **Read current plan:** Use `filesystem_tool` to read the existing plan at `{kernel_plan_path?}`.
35-
2. **Review execution results:** Analyze the following to identify what needs improvement:
36+
2. **Read optimized kernel:** Use `filesystem_tool` to read the `{optimized_kernel_path?}`.
37+
3. **Review execution results:** Analyze the following to identify what needs improvement:
3638
* Compilation Status: `{kernel_compilation_status?}`
3739
* Test Results: `{test_results?}`
3840
*. Autotune Summary: `{autotuning_summary?}`
@@ -48,7 +50,8 @@
4850
4951
## 1. Current Kernel Analysis
5052
- Brief description of what the kernel does
51-
- Current implementation approach
53+
- Current implementation approach
54+
- Analyze the `{base_kernel_path}` for NEW plans, or the `{optimized_kernel_path?}` for REVISIONS
5255
- Identified performance bottlenecks or issues
5356
5457
## 2. Optimization Strategy

MaxKernel/auto_agent/subagents/pipeline_agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def _record_history_snapshot(self, ctx: InvocationContext, iteration: int):
251251
),
252252
"test_status": ctx.session.state.get("test_results", {}),
253253
"latency_ms": latency,
254+
"autotuning_summary": ctx.session.state.get("autotuning_summary", ""),
254255
"profiling_summary": ctx.session.state.get("profiling_summary", ""),
255256
}
256257

MaxKernel/auto_search/graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class EvaluationResult(BaseModel):
1313
correct: bool = False
1414
latency_ms: Optional[float] = None
1515
profiling_summary: Optional[str] = None
16+
autotuning_summary: Optional[str] = None
1617
compilation_error: Optional[str] = None
1718
test_error: Optional[str] = None
1819

MaxKernel/auto_search/worker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def _process_results(
177177
test_error = test_status.get("output") if not correct else None
178178

179179
latency_ms = best_run.get("latency_ms")
180+
autotuning_summary = best_run.get("autotuning_summary")
180181
profiling_summary = best_run.get("profiling_summary")
181182

182183
# Read optimized code if it exists
@@ -206,6 +207,7 @@ def _process_results(
206207
compiled=compiled,
207208
correct=correct,
208209
latency_ms=latency_ms,
210+
autotuning_summary=autotuning_summary,
209211
profiling_summary=profiling_summary,
210212
compilation_error=compilation_error,
211213
test_error=test_error,

0 commit comments

Comments
 (0)