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.
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
Same Simulation, Different Evidence: Where Retrieved Tool Output Costs LLM Agents Accuracy
Saving long tool output to files cut GPT-5.1 accuracy by 11.3 points; naming the authoritative file restored it.
Fake News, Real Crashes: Information Injection Attacks on LLM Financial Trading Agents
Fake headlines hijacked LLM trading agents 62% of the time versus 14% for prompt injection.
Harness Engineering 101: The LLM is the brain, the harness is the body
An agent is a loop managing a JSON array; 16 chapters build one from scratch
Harness2 by Google Research – Recursive Agent Harnessing
Recursively refining the harness with fixed model weights raised benchmark scores by up to 11.8 points.
Ousted Savannah police officer gave ICE agent husband access to Flock system
A police officer shared her Flock login with her ICE-agent husband; an audit found 983 searches and she was fired
Tmux and Claude Code: Sessions, Send-Keys, and the Ceiling
Running Claude Code agents in tmux works well, but limits appear around four agents.