Performance Profiling on AMD GPUs – Part 5: Profiling-Driven Kernel Optimization with an AI Code-Assist Tool AMD published a blog post detailing a workflow that combined ROCm profiling tools with Cursor's AI code-assist agent to optimize a double-precision HIP kernel on an Instinct MI250 GPU, achieving a cumulative 28.3× speedup across 45 experiments while maintaining bit-identical results at 1e-12 relative tolerance. The four-day process, which included planned reverts and scaling characterization, would typically have taken weeks to months in a manual workflow. The post emphasizes the generalizable pattern of prompts, tool commands, and guardrails rather than kernel-specific optimizations. Performance Profiling on AMD GPUs – Part 5: Profiling-Driven Kernel Optimization with an AI Code-Assist Tool performance-profiling-on-amd-gpus-part-5-profiling-driven-kernel-optimization-with-an-ai-code-assist-tool In this fifth installment of the Performance Profiling on AMD GPUs blog series, the focus shifts from tutorial format to a worked end-to-end case study: driving the iterative optimization of a double-precision HIP kernel on an AMD Instinct™ MI250 Graphics Compute Die GCD , using the same profiling workflow that the earlier parts covered, combined with a modern AI code-assist tool to keep the per-experiment loop tight. Parts 1 https://rocm.blogs.amd.com/software-tools-optimization/profiling-guide/intro/README.html , 2 https://rocm.blogs.amd.com/software-tools-optimization/profiling-guide/novice/README.html , and 3 https://rocm.blogs.amd.com/software-tools-optimization/profiling-guide/advanced/README.html of the series covered the foundations of GPU performance profiling and basic and advanced usage of the ROCm profiling toolkit see Additional Resources below ; Part 4 https://rocm.blogs.amd.com/software-tools-optimization/profiling-guide/fortran openmp/README.html applied that toolkit to a Fortran code with OpenMP offload. AMD Instinct™ GPUs are routinely deployed for HPC and AI workloads that benefit from hand-tuned kernels. Producing those kernels has traditionally involved long, manual cycles of profiling, hypothesis formation, code edits, validation, and documentation. Modern AI code-assist tools integrated with the developer’s editor and shell can compress that cycle significantly, provided the workflow is structured to keep the developer in control of correctness, direction, and measurement. This post describes a concrete end-to-end workflow for iteratively optimizing a double-precision HIP kernel running on a single Instinct MI250 GCD, using Cursor’s agent mode as the code-assist tool. The workflow produced a cumulative 28.3× speedup 1 id7 across roughly 45 recorded experiments while maintaining bit-identical results at 1e-12 relative tolerance at every step. The entire sequence — including planned reverts, a scaling-characterization pause, and post-mortem documentation — spanned roughly four working days of developer time; in a pre-AI-assist workflow of manual edit, build, profile, and diff cycles, the same progression would typically have taken weeks to months. The emphasis is not on the kernel-specific wins or on a step-by-step recipe for the reader to reproduce, but on the pattern of prompts, tool commands, and guardrails that made the workflow productive and that generalize to other kernels, other projects, and other GPU architectures the kernel optimizations themselves are tuned to MI250 and the gfx90a / CDNA2 instruction set architecture ISA ; the workflow does not depend on the device — including the experiments that regressed and were reverted, which are as instructive as the ones that were kept. Each Pattern section ends with a bolded Generalizable lesson; the prompts in between are what ground them. The intended audience is HPC and scientific-application developers who are already comfortable with HIP and ROCm profiling tools see the ROCm profiling guide series in Additional Resources below and want a practical template for incorporating an AI code-assist tool into the optimization loop. The Example: A Stiff-ODE Solver on a Sparse Update Graph the-example-a-stiff-ode-solver-on-a-sparse-update-graph The kernel used in this study comes from a stiff ordinary-differential-equation ODE solver — that is, a numerical integrator for a system of coupled rate equations where the fastest and slowest components evolve on very different timescales, which forces the use of small, fixed-size timesteps. For each of N independent zones, the kernel integrates such a system representing on the order of 10^2 state variables coupled through on the order of 10^3 sparse coupling terms, forward in time through many thousands of those timesteps per zone. Each timestep evaluates coupling rates, accumulates per-state positive and negative update contributions, and performs an explicit state update. Relevant structural details: Every zone is independent, so zones map naturally to thread blocks. The per-timestep working set coupling rates, per-state accumulators, state variables, coupling-to-state index maps easily exceeds register files, so the kernel relies heavily on Local Data Share LDS, also known as shared memory . Two loops dominate execution time: the rate-evaluation loop over all coupling terms and the state-update loop over all state variables, each with a variable number of contributing coupling terms ragged, from a handful to several hundred per state variable . Correctness is anchored by a numerical diff against a reference output at 1e-12 relative tolerance. This is the discipline that makes rapid iteration possible: any change that perturbs the result beyond that threshold is reverted immediately. Experiments are launched via Slurm sbatch against a single MI250 GCD. The canonical timing configuration is 104 zones × 2 iterations: the 104-zone count matches the 104 compute units CUs on one GCD one zone per CU , and two iterations are enough to amortize launch and copy overhead while keeping per-experiment turnaround short. A longer configuration — 14 iterations at the same zone count — is used only for detailed hardware-counter profiling under rocprof-compute , whose iteration-multiplexing option collects different performance monitoring counter PMC subsets across separate kernel launches and benefits from a larger invocation count to produce stable per-counter aggregates iteration multiplexing is planned for a future ROCm release; readers on ROCm 7.2.0 can run the same profiling flow without it . Timings reported below are GPU-side wall-clock under the canonical 2-iteration configuration. The starting baseline for this study was 46.7 seconds at 104 zones. The final kept configuration, after the experiments described here, ran in 1.65 seconds — a cumulative 28.3× speedup 1 id7 , bit-identical to the baseline. The AI Code-Assist Tool the-ai-code-assist-tool Cursor is an IDE built on VS Code that exposes a chat-based agent with full access to the workspace file system, terminal, and tool-invocation APIs. In agent mode the assistant can read files, run shell commands including Slurm submissions , edit source files, and report back — while the developer reviews each substantive action in the usual diff and terminal panes. For this project, the IDE ran on the developer’s laptop and connected over remote-SSH to the HPC node where the source tree, build system, and MI250 GCD lived; all sbatch builds, runs, profiling invocations, and git operations executed on the remote node. The agent’s underlying model was Anthropic’s Claude Opus 4.7 high-reasoning mode . Three properties of the tool mattered most for the workflow described here: A shared log file. All experiment plans, hypotheses, measured results, and revert decisions were written into a single experiment log.md by the agent. Across 45 experiments spanning several days, this log replaced the developer’s own memory of what had already been tried. Non-destructive git behavior. The agent created feature branches and wrote commit messages to a text file, but the final git commit and git push were executed by the developer from their own shell. This kept SSH authentication, sign-off, and remote pushes under the developer’s explicit control. Arbitrary shell and tooling invocation. Submitting sbatch build.sh , polling squeue , extracting vector general-purpose register VGPR counts from a rocprofv3 CSV, and running a numerical diff against a reference output are all shell operations the agent performs autonomously once the commands are established. The rest of this post walks through a representative sequence of prompts and the outcomes they produced. Each example is generalizable; the specific kernel details are incidental. Setting Up the Environment and Baseline setting-up-the-environment-and-baseline The first session fixed the baseline, the reproducible build and run commands, and the correctness check. Two prompts were enough to establish the loop. Prompt 1.Set up Slurm sbatch scripts that build this project with CMAKE BUILD TYPE=Release , ENABLE GPU=ON , and CMAKE HIP ARCHITECTURES=gfx90a on an MI250 node, run the produced binary with