Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

SHELL := /bin/bash

.PHONY: help docker-shell docker-check-agents docker-smoke docker-run docker-parallel-run docker-setup-flydsl \
.PHONY: help docker-shell docker-check-agents docker-smoke docker-run docker-parallel-run docker-setup-flydsl docker-setup-geak \
check-docker-runner check-evaluator check-held-out check-visualization \
visualization-build visualization-serve visualization-run \
sync-perf-helpers check-perf-helpers materialize-perf-workspace \
Expand All @@ -27,6 +27,7 @@ help:
@echo " On other GPUs, pass a matching CONFIG explicitly"
@echo " Images: gfx942->mi30x, gfx950->mi35x; override with AKA_DOCKER_IMAGE=..."
@echo "make docker-setup-flydsl - Install FlyDSL when absent (for flydsl2flydsl, torch2flydsl, and triton2flydsl)"
@echo "make docker-setup-geak - Install the Claude Agent SDK when absent (for the geak_v4 agent)"
@echo "make check-docker-runner - Check Docker runner syntax and runtime-specific arguments"
@echo "make check-evaluator - Run centralized evaluator unit tests"
@echo "make check-held-out - Run held-out module unit tests"
Expand Down Expand Up @@ -74,6 +75,11 @@ docker-parallel-run:
docker-setup-flydsl:
@$(DOCKER_RUNNER) setup-flydsl

# Install the Claude Agent SDK into the container's persistent pip user-base when
# the selected image does not ship it. Needed by the geak_v4 agent.
docker-setup-geak:
@$(DOCKER_RUNNER) setup-geak

check-docker-runner:
@bash tests/test_docker_benchmark.sh

Expand Down
108 changes: 108 additions & 0 deletions agents/geak_v4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# GEAK v4 Agent

The `geak_v4` integration runs GEAK's deterministic
`kernel_workflow/kernel_workflow.js` through Claude Code's dynamic **Workflow**
tool. GEAK optimizes the kernel and, when its Director validation passes, applies
the validated patch directly into the task workspace (`apply_to_original="true"`).

**AgentKernelArena is the single source of truth for scoring.** After GEAK
finishes, AKA verifies its harness is intact, re-materializes the perf helpers,
and independently re-evaluates the kernel (compile → correctness → performance);
GEAK's own numbers are not used for the final result.

Like the `forge` and `claude_code` agents, `geak_v4` relies purely on the
environment — it touches nothing outside `agents/geak_v4/`. The launcher stays
thin: it writes a versioned handoff and shells out to `workflow_runner.py`.

## Why a runner instead of a plain `claude -p`

On current Claude builds the `Workflow` tool runs as a **background task**: the
main agent turn ends immediately, so a one-shot `claude -p` would return (and
tear the still-running workflow down) before GEAK finishes. `workflow_runner.py`
keeps a persistent `claude_agent_sdk` client alive and drives completion off the
SDK's background-task lifecycle (`TaskStartedMessage` → `TaskNotificationMessage`)
plus GEAK's on-disk terminal marker. It is a kernel-scoped analogue of GEAK's own
`interface/run_e2e.py` and mirrors its `handoff.json` / `result.json` contract.

## Prerequisites

- An AMD Instinct GPU and a supported profiler (`rocprof-compute`).
- A local GEAK checkout. Point `GEAK_V4_WORKFLOW_DIR` at its
`kernel_workflow/` directory (default: `/opt/geak/kernel_workflow`).
- Claude Code 2.1.177 or newer, installed and logged in (the minimum version for
the dynamic Workflow feature), plus access to the model configured in
`agents/geak_v4/agent_config.yaml`.
- The `claude-agent-sdk` Python package installed in the interpreter that runs
the agent.
- For a `flydsl2flydsl` task, FlyDSL available in the environment.

## Setup

```bash
# 1. Clone GEAK and expose its kernel_workflow directory.
git clone https://github.com/AMD-AGI/GEAK.git
export GEAK_V4_WORKFLOW_DIR=/absolute/path/to/GEAK/kernel_workflow

# 2. Authenticate Claude Code and confirm the Workflow-capable version.
claude --version
claude # log in
claude auth status

# 3. Install the SDK the runner uses to hold the background Workflow open.
pip install claude-agent-sdk
```

This adapter was developed against GEAK commit
`4965d5b2ccde927925c8c5501a25c1233daa52eb` (`v4.0.0-102-g4965d5b`). For a
reproducible review, check out that revision; newer GEAK revisions may require an
adapter/schema update.

## Run the example

The included MI300/MI300X example runs one HIP GELU task. Run it in an
environment that already satisfies the prerequisites above (`GEAK_V4_WORKFLOW_DIR`
set, `claude-agent-sdk` installed, `claude` logged in):

```bash
python main.py --config_name example_configs/quickstart_geak_v4_mi300.yaml
```

## Supported task types

- `hip2hip`
- `triton2triton`
- `flydsl2flydsl`

These are single standalone kernels. The launcher reads `source_file_path` to
steer the optimizer ("optimize only these files") and fails early if the declared
anchor source is missing. Authoring, translation, repository, and image-level
tasks are out of scope for this integration.

## Artifacts

For a task workspace named `<workspace>`, GEAK's run artifacts live OUTSIDE the
scored workspace, under a hidden sibling directory:

```text
.<workspace>_geak_v4/<run-id>/
├── eval/ # GEAK validation + final_patch.diff
├── runs/ # GEAK experiment tree (its own copy of the kernel)
├── handoff.json
└── result.json
```

They sit beside the workspace (not inside it) because GEAK copies `kernel_path`
into its own experiment tree — nesting outputs under the workspace would recurse,
and it keeps GEAK's scratch clear of the directory Arena scores.

## Integrity boundary

`geak_v4` lets GEAK edit the workspace in place, exactly like `forge` and
`claude_code`. Integrity is enforced by the Arena harness, not the launcher:
`main.py` snapshots the harness before the run, verifies it afterwards,
re-materializes the perf helpers, and re-scores the kernel independently. A run
that tampers with a protected harness path fails harness verification. This is a
fail-closed correctness control, not an OS security sandbox; a failed run is not
automatically rolled back. A real paid Claude workflow invocation is not part of
the offline tests — run the one-task example with an authorized account before
relying on this integration for a benchmark campaign.
4 changes: 4 additions & 0 deletions agents/geak_v4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright(C) [2026] Advanced Micro Devices, Inc. All rights reserved.
from .launch_agent import launch_agent

__all__ = ["launch_agent"]
30 changes: 30 additions & 0 deletions agents/geak_v4/agent_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# GEAK v4 runs the deterministic kernel_workflow through Claude Code's dynamic
# Workflow tool. Point the runner at your GEAK checkout's kernel_workflow/
# directory; the GEAK_V4_WORKFLOW_DIR environment variable overrides this value.
# All run artifacts are written to a hidden sibling of the Arena task workspace.
workflow_dir: /opt/geak/kernel_workflow

# Defaults from GEAK v4's supported standalone kernel workflow.
model: claude-opus-4-8
effort: ultracode
budget: 6
min_improve: 0.02
deep_cost: 2
use_expert_skills: false

# Hard wall-clock bound for the complete multi-agent workflow.
timeout_seconds: 43200

# Newer Claude Code builds may finish detached validation work after the
# background task notification. Keep the SDK client alive for this bounded
# on-disk completion grace period.
done_grace_seconds: 1800
done_poll_seconds: 5

# V1 deliberately targets existing, isolated kernels with one declared source
# file. Author/translation tasks need a separate frozen-baseline adapter, while
# repository/image tasks need a storage/copy-cost qualification first.
supported_task_types:
- hip2hip
- triton2triton
- flydsl2flydsl
Loading
Loading