AI-Assisted GPU Porting of a 250k Line Legacy Weather Simulation Code
TL;DR Highlight
An AI agent ported 250k lines of Fortran to GPU, giving a 5.1x application speedup.
Who Should Read
Backend or HPC developers using AI agents to migrate large legacy codebases who worry about validating the results.
Core Mechanics
- Validation-centric workflow drove the port
- CReSS is a legacy Fortran weather simulation code with over 250,000 lines.
- A CLI-based AI agent extracted OpenMP regions, generated dump-based kernel benchmarks, applied OpenACC transformations, and validated results.
- Validation used dumps and element-wise comparison
- Dumps came from physically meaningful simulation states and served as reference data.
- Results were compared element by element, then validated at the application level.
- 162 kernels validated on a real typhoon run
- The workflow produced numerically validated GPU implementations for 162 target kernels.
- Application-level speedup was 5.1x within practical wall-clock development cost.
- Five kernels showed numerical discrepancies
- Causes were floating-point and intrinsic-function differences.
- These included threshold-sensitive branch divergence and cancellation effects.
- Findings were fed back to the application developers.
- Code generation alone is not enough
- Session-spanning context had to be managed.
- Runtime-state reconstruction and costly recovery from small static-analysis omissions also needed handling.
Community Reactions
- Opinion that validation takes longer than porting
- One comment said validating numerical correctness across edge cases on 250k lines likely took twice as long as the porting.
- Eagerness to try it on 1960s Fortran reactor codes
- One comment wanted to apply this to legacy Fortran nuclear reactor simulators.
How to Apply
- Dump reference outputs before migrating
- Pick one legacy module today and save its inputs and outputs on representative data.
- Write the element-wise comparison script first.
- Make the agent convert and validate in one loop
- Make passing the dump comparison the completion condition in your prompt.
- Feed failing element locations and errors back to the agent to fix.
- Log discrepancies separately from bugs
- Keep errors from floating-point or intrinsic differences in their own list.
- Review cases near branch thresholds with the original developers.
- Persist context across sessions in a file
- Save progress and validation results to a file so new agent sessions can resume.
- Have each session read that file first.
Try It
# Paste into Claude Code or ChatGPT (simplified version of the paper's method)
You are a legacy code porting agent. Convert the function below for {{target environment}}.
[Original code]
{{code}}
[Reference I/O dump description]
{{dump file path or sample}}
Rules:
1. First write validation code that compares against the dump element by element.
2. If there are mismatches, report location and error in a table.
3. Classify the cause: floating-point, intrinsic function difference, branch threshold, or cancellation.
4. Record bugs and numerical differences separately.
Next: ask it to summarize progress in PORTING_NOTES.md.Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques