Migrating a Legacy Scientific Application with an AI Coding Agent: NICAM from Fortran to Kokkos
Abstract: Migrating from Fortran to C++/Kokkos broadens access to hardware accelerators through backends such as CUDA and HIP while offering greater flexibility in software design. However, legacy Fortran applications often have large codebases, making manual porting time-consuming and costly. Recent advances in LLMs and AI coding agents have made large-scale code migration increasingly feasible. In this study, we ported NICAM (Nonhydrostatic ICosahedral Atmospheric Model), a legacy Fortran climate model accelerated with OpenACC, to C++/Kokkos with the assistance of Claude Code. The agent translated the code directly from Fortran to C++/Kokkos under human review. Approximately 140,000 lines of Fortran were analyzed and ported into 35,000 lines of C++/Kokkos, covering the dynamical core and seven physics packages. A 100-member ensemble comparison with the original Fortran model showed that the port is statistically consistent with the original. Performance was evaluated on Miyabi-G, an NVIDIA GH200 cluster, and Sirius, an AMD MI300A cluster. Compared with the Fortran/OpenACC baseline on GH200, the port achieved application speedups of on GH200 and on MI300A. The CUDA build achieved a GPU kernel-time speedup of on GH200. After normalization by peak memory bandwidth, the HIP build on MI300A achieved the kernel performance of the Fortran/OpenACC baseline.
Paper Prompts
Sign up for free to create and run prompts on this paper.
Explain it Like I'm 14
1. What is this paper about?
This paper explains how researchers used an AI coding agent to help move a large climate-science computer program from Fortran to C++ with Kokkos.
The program is called NICAM, which stands for Nonhydrostatic Icosahedral Atmospheric Model. NICAM is used to simulate Earth’s atmosphere, including things such as wind, clouds, rain, temperature, and energy.
The researchers wanted NICAM to work well on different kinds of powerful computers, especially:
- NVIDIA GPUs, which use CUDA
- AMD GPUs, which use HIP
Kokkos helps programmers write one version of a program that can run on both types of GPUs.
The migration was assisted by Claude Code, an AI tool that can read code, write new code, compile programs, run tests, and fix some errors. However, people still guided the AI and carefully checked its work.
2. What questions did the researchers ask?
The main question was:
Can an AI coding agent help humans successfully move a very large, complicated climate model from old Fortran code to modern C++/Kokkos code?
The researchers also wanted to know:
- Does the new program produce scientifically trustworthy results? In other words, does it behave like the original Fortran program?
- Does the new program run quickly? The researchers tested whether the C++/Kokkos version could be faster than the original.
- Can the new program work on both NVIDIA and AMD GPUs?
- How much human checking is still needed?
- How much computer usage and money did the AI-assisted process require?
3. How did they do the research?
Moving the code
The original NICAM program contained about 140,000 lines of Fortran code. The researchers used Claude Code to translate the important parts into about 35,000 lines of C++/Kokkos code.
The port included:
- The model’s main atmospheric calculations, called the dynamical core
- Cloud and rain calculations
- Radiation
- Surface heat and water exchanges
- Turbulence
- Land processes
- Ocean and sea-ice processes
The AI worked on the program one section at a time. Humans first made a plan, then the AI translated a section, built it, tested it, and revised it when needed.
What are Kokkos and GPU backends?
A GPU is a processor designed to perform many calculations at the same time. This is useful for climate models because they must calculate conditions at many places in the atmosphere.
Kokkos acts somewhat like a universal adapter. Scientists can write the main program once, and Kokkos helps it run on different types of computer hardware.
- CUDA is the software system used to run programs on NVIDIA GPUs.
- HIP is the software system used to run programs on AMD GPUs.
Testing the new program
The researchers used three levels of testing.
1. Testing individual pieces
They gave a translated routine exactly the same input as the original Fortran routine and compared the outputs.
This is similar to testing one part of a machine separately to see whether it works correctly.
2. Testing short complete runs
They ran the whole model for 30 or 60 time steps and compared it with the Fortran version.
This helped catch problems that individual tests might miss. For example, one test found that the new program was calculating surface radiation incorrectly because a needed initialization step had been left out.
3. Testing groups of simulations
Weather and climate models are very sensitive to tiny changes. Two versions may not produce exactly the same weather pattern after several days, even if both are correct.
To handle this, the researchers created 100 simulations, or an ensemble, with tiny differences in their starting temperatures. They ran the same 100 starting conditions using both the Fortran and Kokkos versions.
Instead of asking whether every cloud and wind pattern matched exactly, they compared the overall statistics, such as:
- Average energy
- Amount of water and rainfall
- Global average temperature
- Average wind speeds
- Mass and energy balances
This is like comparing two groups of students by their overall test-score patterns rather than expecting every student to receive exactly the same score.
Measuring speed
The researchers tested the programs on two powerful supercomputers:
- An NVIDIA GH200 system called Miyabi-G
- An AMD MI300A system called Sirius
They measured how long each version took to complete the same atmospheric calculations.
4. What did they find?
The new program was scientifically consistent
The C++/Kokkos version produced results that were statistically similar to the original Fortran version.
The researchers examined 59 different quantities across two groups of 100 simulations. About 95.3% of the results fell within the expected range for both versions.
This does not mean every number was exactly identical. Small differences are normal because the two programs may perform calculations in a different order. What matters is that the differences did not change the overall behavior of the climate model.
The new program was faster
Compared with the original Fortran/OpenACC version on the NVIDIA computer:
- The Kokkos version on NVIDIA was 1.71 times faster
- The Kokkos version on AMD was 1.54 times faster
For example, if the original program took about 81 seconds, the NVIDIA Kokkos version took about 47 seconds.
When looking only at the time spent in GPU calculations:
- The NVIDIA CUDA version was 1.38 times faster
- The AMD HIP version was 1.27 times faster
The speed improvements came partly from reducing unnecessary data movement and waiting. The new version often worked directly with complete data arrays instead of repeatedly copying smaller pieces of data.
It worked on both NVIDIA and AMD hardware
The same general C++/Kokkos code could be compiled for both CUDA and HIP.
This is important because scientific organizations may use different kinds of supercomputers. They do not want to rewrite the entire program every time they buy a new type of machine.
The AMD version was not quite as efficient as the NVIDIA version. The researchers believe this was partly because the AMD version used settings originally chosen for NVIDIA GPUs. More tuning could probably improve its performance.
The AI did not work alone
Claude Code wrote the C++/Kokkos model code, but human researchers:
- Decided what should be translated
- Created rules and goals
- Reviewed the AI’s plans
- Checked the program structure
- Compared results
- Investigated errors
- Approved each stage
One important error was found only during a complete model run, even though the smaller tests had passed. This shows that AI-generated code still needs careful human testing.
The researchers recorded about 4 billion cached tokens and estimated that the work would cost about $5,589 at standard API prices. They also sent 797 instructions to the AI during the recorded workflow.
5. Why is this important?
Large scientific programs are often decades old. Rewriting them by hand can take many years and require experts who understand both the science and several programming languages.
This research suggests that an AI coding agent can greatly speed up part of that work. It can act like a very fast programming assistant that:
- Reads old code
- Writes new code
- Runs tests
- Finds some mistakes
- Repeats the process many times
The new Kokkos version also makes NICAM more flexible. In the future, researchers may be able to run it efficiently on many types of processors without maintaining a completely separate program for each machine.
However, the paper also shows that AI is not a replacement for scientific experts. Humans still need to check whether the calculations make sense, design good tests, and find errors that simple tests miss.
Conclusion
The paper demonstrates that an AI-assisted approach can help modernize a very large climate model. The researchers successfully moved an important part of NICAM from Fortran to C++/Kokkos, tested it on NVIDIA and AMD supercomputers, and showed that it produced results similar to the original while running faster.
The biggest possible impact is that other old scientific programs might be modernized more quickly and made ready for future supercomputers. Still, the safest approach is a partnership: AI can do much of the repetitive coding, while human scientists provide judgment, testing, and responsibility for the final results.
Practical Applications
Immediate Applications
- HPC climate-model modernization: Research institutions and meteorological agencies can use the demonstrated human-in-the-loop workflow to begin migrating large Fortran climate, weather, ocean, and environmental models to C++/Kokkos. The workflow—planning, module-by-module translation, compilation, reference testing, integration testing, and human review—is deployable now for selected production configurations.
- Potential tools/workflows: Agent-assisted migration pipelines, source-to-source translation assistants, compiler/test orchestration, and progress-tracking artifacts such as module maps and migration logs.
- Dependency: The legacy code should have reasonably consistent data structures, maintainable organization, and usable compiler directives or documentation. Expert review remains necessary.
- Cross-vendor deployment of atmospheric simulations: The C++/Kokkos NICAM implementation can be deployed on NVIDIA CUDA and AMD HIP systems from a shared source base. This supports climate centers and universities operating heterogeneous clusters without maintaining separate NVIDIA- and AMD-specific implementations.
- Sectors: Weather forecasting, climate science, environmental modeling, and national laboratories.
- Practical benefit: The port achieved a 1.71× application speedup on an NVIDIA GH200 relative to the Fortran/OpenACC baseline and ran on AMD MI300A with a 1.54× speedup relative to that baseline.
- Dependency: Performance is not automatically equivalent across architectures. The MI300A build reused CUDA-oriented tile sizes and may require architecture-specific tuning.
- Faster ensemble climate experiments: The validated port can support larger or more frequent ensemble simulations for uncertainty quantification, sensitivity analysis, data assimilation research, and extreme-weather studies.
- Potential workflow: Launch many perturbed NICAM members across NVIDIA or AMD GPU partitions, using the C++/Kokkos implementation as a common executable.
- Dependency: The reported consistency was demonstrated for 100-member ensembles, 59 quantities, and 10-day simulations. Longer integrations, additional diagnostics, and broader initial conditions require further validation.
- Regression testing for scientific software: The paper’s three-tier validation protocol can be adopted immediately by scientific software teams:
- component-level comparisons against dumped reference inputs and outputs;
- short coupled integration tests checking fields and conservation budgets; and
- ensemble or distributional comparisons when bitwise reproducibility is inappropriate.
- Sectors: Computational physics, chemistry, computational fluid dynamics, biology, and engineering simulation.
- Potential product: A reusable scientific-model continuous-integration system that runs reference tests on CPU, CUDA, HIP, and other backends.
- Dependency: Reference data must be representative. The paper notes that isolated unit tests can miss errors in initialization or data-production pathways.
- Modernization of other legacy scientific codes: The same workflow can be applied to legacy Fortran applications in ocean modeling, plasma physics, molecular dynamics, computational fluid dynamics, and energy systems.
- Evidence from the paper: Related work has already applied similar approaches to FESOM2 and ORB5, while NICAM demonstrates application-scale migration involving approximately 140,000 lines of Fortran.
- Dependency: Results should not be generalized to arbitrary codebases. Highly irregular control flow, undocumented numerical assumptions, weak test coverage, or extensive global state may substantially increase human effort.
- Improved scientific software maintainability: Converting implicit Fortran dependencies into explicit C++ interfaces and representing state with Kokkos Views can make ownership, lifetime, data movement, and module dependencies easier to inspect.
- Potential workflow: Use class-based modules, explicit dependency injection, device-resident state arrays, and backend-independent execution policies when adding new physics or diagnostics.
- Dependency: C++ complexity, template behavior, and kernel fusion can create new maintenance challenges. The paper specifically notes that fused kernels may be faster but harder to review.
- Simplified runtime configuration and experiment management: The YAML-based configuration layer can be used immediately to manage model resolution, time integration, and physics-package choices in scripts and workflow systems.
- Sectors: Academic research, operational forecasting, and reproducible computational experiments.
- Potential tools: YAML-driven parameter sweeps, workflow schedulers, containerized model runs, and automated experiment registries.
- Dependency: Only the selected configuration and explicitly supported options are available; unported branches are rejected rather than silently supported.
- Education and training in performance-portable computing: The translated NICAM code, Fortran-to-Kokkos comparisons, and validation procedure can serve as teaching material for courses and workshops on HPC, GPU programming, numerical methods, and software engineering.
- Practical activities: Students can translate individual kernels, compare OpenACC and Kokkos implementations, measure memory movement, and construct reference-based tests.
- Dependency: The full production model may be too large for introductory use; smaller kernels or the dry dynamical core are more suitable.
- Institutional planning for AI-assisted software engineering: HPC centers can use the reported token consumption, estimated API cost of approximately USD 5,589, and 23 active workflow days as an initial budgeting reference for similar migration projects.
- Dependency: The estimate includes porting, analysis, plotting, and data-generation tasks, and does not include unrecorded human review time, cluster costs, or the cost of correcting failures after deployment. Actual costs may vary substantially.
- Policy and funding decisions for sustainable scientific infrastructure: Funding agencies and research organizations can prioritize performance-portable rewrites of strategically important legacy applications rather than maintaining separate architecture-specific forks.
- Practical implication: Shared Kokkos implementations can reduce dependence on a particular accelerator vendor and extend model usability across national supercomputing systems.
- Dependency: Portability must be evaluated alongside performance, numerical reliability, developer expertise, licensing, and long-term Kokkos/backend support.
Long-Term Applications
- Reusable autonomous migration agents for scientific software: The workflow could evolve into a semi-automated platform that performs dependency analysis, translates modules, invokes compilers, generates tests, runs benchmarks, and proposes fixes across an entire codebase.
- Potential product: A domain-aware “scientific code modernization agent” with specialized roles for translation, numerical verification, performance tuning, and documentation.
- Required development: Formal dependency graphs, stronger boundary-case generation, persistent project memory, reproducible tool execution, and safeguards against incorrect numerical transformations.
- Key assumption: Human experts will remain responsible for approving algorithmic equivalence and scientific validity.
- Automated ensemble-based acceptance testing: The paper’s z-score comparison could become a general tool for validating compiler changes, GPU backends, precision changes, parallel decomposition, and model rewrites in chaotic simulations.
- Sectors: Weather, climate, oceanography, wildfire prediction, turbulence modeling, and data assimilation.
- Potential workflow: Every software release generates matched perturbed ensembles and automatically evaluates distributions of conservation metrics, global means, variability, and application-specific diagnostics.
- Required development: More rigorous acceptance criteria, principal-component or multivariate tests, longer simulations, and methods for distinguishing numerical drift from scientifically meaningful changes.
- Operational weather and climate forecasting on mixed accelerator fleets: Once additional NICAM components and configurations are ported and validated, a single codebase could support operational workloads across heterogeneous national or commercial clouds.
- Potential applications: Global weather prediction, seasonal forecasting, climate projection, hazard assessment, and rapid scenario generation.
- Required development: Porting all relevant physics and I/O paths, validating longer forecasts, improving multi-node scaling, and integrating operational data-assimilation pipelines.
- Dependency: The current evidence covers one selected production configuration and relatively limited simulation durations.
- Architecture-aware automatic performance tuning: Kokkos provides portability, but the results show that portable code still needs backend-specific optimization. Future systems could automatically explore tile sizes, layouts, execution policies, kernel fusion, memory placement, and MPI decompositions.
- Potential tools: Auto-tuning frameworks coupled to Kokkos, hardware-performance-model-guided agents, and benchmark-driven optimization loops.
- Expected benefit: Improve AMD performance toward or beyond the NVIDIA results while preserving one shared implementation.
- Dependency: Automated tuning must preserve numerical behavior and avoid optimizing short benchmarks at the expense of large-scale or long-duration workloads.
- Migration of broader energy and engineering applications: The approach could eventually modernize legacy simulators for energy-grid planning, renewable-energy forecasting, combustion, nuclear engineering, battery systems, and computational fluid dynamics.
- Potential products: Portable GPU-enabled solvers, accelerator-ready digital twins, and simulation services deployable on different cloud and supercomputing platforms.
- Dependency: These fields may contain stricter safety, certification, or regulatory requirements than climate research. Numerical equivalence alone may not establish suitability for operational or safety-critical use.
- AI-assisted generation of scientific test suites: Agents could infer numerical invariants, conservation laws, boundary cases, and cross-module contracts from legacy code and generate tests before or during migration.
- Potential workflow: Combine static code analysis, symbolic reasoning, reference-output generation, property-based testing, and ensemble testing.
- Benefit: Address the paper’s limitation that current tests use a limited collection of dumped inputs and may not cover boundary conditions.
- Dependency: Automatically inferred properties must be checked by domain experts; incorrect assumptions about conservation or valid ranges could produce misleading tests.
- Research reproducibility and executable model archives: The combination of YAML configuration, containerized builds, backend-specific compilation, and recorded validation artifacts could support portable archival versions of scientific models.
- Sectors: Academia, public research infrastructure, and policy-oriented climate assessment.
- Potential tools: Reproducible model capsules containing source, compiler versions, Kokkos configuration, reference datasets, test results, and performance metadata.
- Dependency: Long-term reproducibility depends on preserving compiler, library, hardware, input-data, and numerical-environment compatibility.
- Workforce transformation in scientific computing: AI agents may allow domain scientists to contribute to modernization projects without becoming specialists in every target programming model, while HPC engineers focus on verification, architecture tuning, and system integration.
- Long-term implication: Universities and research organizations may develop hybrid roles combining numerical analysis, software assurance, and AI-agent supervision.
- Dependency: Training must address code review, numerical stability, floating-point behavior, security, intellectual property, and responsible use of generated code.
- Policy frameworks for trustworthy AI-generated scientific code: As agent-assisted migration expands, organizations may establish formal governance requiring provenance records, human approvals, reproducible builds, independent validation, and documented performance comparisons.
- Potential policy use: Procurement standards for AI-modernized public-sector models and certification requirements for software used in climate, energy, or environmental decisions.
- Dependency: Standards must distinguish ordinary research software from operational or safety-critical systems and must account for uncertainty caused by non-bitwise numerical behavior.
Glossary
- Agentic workflow: A software-development process in which an AI agent autonomously performs multiple coordinated tasks under human direction. “Additional Key Words and Phrases: NICAM, Kokkos, agentic workflow, performance portability”
- Amortization: The allocation of a cost across multiple operations or time steps. “For the kernel-time breakdown, the radiation update cost was amortized over its 60-step interval.”
- APU (Accelerated Processing Unit): A processor that combines CPU and GPU components in a shared system. “Sirius uses AMD Instinct MI300A APUs”
- Backend: An implementation layer that maps a programming abstraction onto a particular hardware or execution system. “Its CUDA and HIP backends provide a route to NVIDIA and AMD GPUs from a common source codebase”
- Bandwidth normalization: Adjustment of performance measurements to account for differences in peak memory bandwidth between hardware platforms. “Figure 1(b) compares the CUDA and HIP builds after normalization by peak memory bandwidth”
- Big-endian: A byte-ordering convention in which the most significant byte is stored first. “highlighted the original model’s big-endian input/output”
- Cloud microphysics: The atmospheric-physics processes governing cloud particles, phase changes, and precipitation. “NSW6 cloud microphysics”
- Coupled simulation: A simulation in which multiple interacting physical or computational subsystems are integrated together. “the statistical behavior of coupled simulations”
- Data layout: The organization of multidimensional data in memory, affecting indexing and performance. “Kokkos addresses this goal through C++ abstractions for parallel execution, memory spaces, and multidimensional data layouts”
- Device-resident: Stored in accelerator memory so that data can be accessed without repeated transfers from the host. “The prognostic state remains device-resident across time steps”
- Dynamical core: The numerical component of an atmospheric model that solves the governing equations for fluid motion and thermodynamics. “The completed application combines NICAM’s nonhydrostatic dynamical core with seven physics packages”
- Ensemble consistency testing: Statistical comparison of multiple simulations to determine whether two implementations exhibit compatible behavior. “Tier 3. Ensemble-inspired consistency testing.”
- Execution policy: A specification of how a parallel operation is iterated and executed across an execution space. “the port exposes work across regions through a multidimensional Kokkos execution policy”
- Fused computation: The combination of adjacent computational operations into a larger operation to reduce intermediate data movement and launch overhead. “The time spent in the ‘Surface flux + turbulence’ kernels decreases from 58.8 to 28.5 ms following the fusion of adjacent computations”
- Global mean: The average value of a field over the entire modeled spatial domain. “the global means and standard deviations of model fields”
- Gyrokinetic particle-in-cell: A plasma simulation method that combines gyrokinetic equations with particle-in-cell numerical techniques. “the Fortran ORB5 gyrokinetic particle-in-cell code”
- Heterogeneous hardware: A computing system containing different types of processors or accelerators with distinct execution and memory characteristics. “Modernizing weather and climate models for heterogeneous hardware predates LLM-based code generation.”
- HIP: AMD’s GPU programming platform and the Kokkos backend targeting AMD accelerators. “The CUDA build achieved a GPU kernel-time speedup of 1.38× on GH200.”
- Host–device data transfer: Movement of data between the host processor’s memory and an accelerator’s memory. “Host-to-device copy at setup”
- Ill-conditioned: Numerically sensitive or unstable, such that small input or rounding errors can cause relatively large output errors. “Exceptions for ill-conditioned intermediate quantities were documented”
- Kernel: A parallel function launched for execution on a GPU or other accelerator. “The kernel-duration sums include only time spent executing GPU kernels”
- Kokkos View: A multidimensional, memory-space-aware data structure provided by the Kokkos programming model. “The classes own model state arrays through Kokkos Views”
- LayoutLeft: A Kokkos memory layout in which the leftmost array index varies fastest in memory. “LayoutLeft retains the Fortran array ordering with the horizontal index g contiguous in memory.”
- Memory space: A Kokkos abstraction identifying the memory region in which data is allocated and accessed. “Kokkos addresses this goal through C++ abstractions for parallel execution, memory spaces, and multidimensional data layouts”
- Multidimensional execution policy: A parallel-iteration specification over more than one index dimension. “the port exposes work across regions through a multidimensional Kokkos execution policy”
- Nonhydrostatic: Describing a model that does not impose hydrostatic balance and can explicitly represent vertically accelerating atmospheric motions. “NICAM uses an icosahedral grid and nonhydrostatic equations to support global atmospheric simulations.”
- Numerical parameterization: An approximate representation of unresolved physical processes within a numerical model. “These codebases combine numerical algorithms, physical parameterizations, communication routines, and input/output infrastructure.”
- OpenACC: A directive-based programming model for accelerating applications on GPUs and other parallel processors. “The reference was evaluated on Miyabi-G.”
- Prognostic variable: A model variable whose future value is calculated by integrating governing equations over time. “The prognostic state remains device-resident across time steps”
- Reduction: A parallel operation that combines many values into a single result, such as a sum or maximum. “which can alter the order of floating-point operations in reductions”
- Relative error: The magnitude of an error divided by the magnitude of a reference value. “The standard acceptance threshold was a relative error of at most 10−13”
- Strong scaling: The reduction in execution time achieved by increasing processing resources while keeping the problem size fixed. “To assess performance beyond a single accelerator, we conducted strong-scaling experiments”
- Tile size: The dimensions of a block of iteration space processed together to improve locality or accelerator efficiency. “The HIP build reuses the CUDA tile sizes in MDRange”
- Trajectory: The time-evolving sequence of states produced by a simulation. “agreement between individual trajectories becomes difficult to interpret as the integration proceeds.”
- Vertical implicit solver: A numerical solver that determines vertically coupled variables implicitly rather than using only previously known values. “the Fortran offload in the vertically implicit solver”
- z-score: A standardized measure expressing a value’s distance from a reference mean in units of reference standard deviation. “Our test compares diagnostic quantities and their distributions directly using 𝑧-scores”
- Zero-based indexing: An array-indexing convention in which the first element is assigned index zero. “Array indices are converted to zero-based indexing”