From Legacy Fortran to Portable Kokkos: An Autonomous Agentic AI Workflow
Organizations: Los Alamos National Laboratory, Los Alamos, NM 87544 USA · Franklin W. Olin College of Engineering, Needham, MA 02492 USA
Abstract
Scientific applications continue to rely on legacy Fortran codebases originally developed for homogeneous, CPU-based systems. As High-Performance Computing (HPC) shifts toward heterogeneous GPU-accelerated architectures, many accelerators lack native Fortran bindings, creating an urgent need to modernize legacy codes for portability. Frameworks like Kokkos provide performance portability and a single-source C++ abstraction, but manual Fortran-to-Kokkos porting demands significant expertise and time. Large language models (LLMs) have shown promise in source-to-source code generation, yet their use in fully autonomous workflows for translating and optimizing parallel code remains largely unexplored, especially for performance portability across diverse hardware. This paper presents an agentic AI workflow where specialized LLM "agents" collaborate to translate, validate, compile, run, test, debug, and optimize Fortran kernels into portable Kokkos C++ programs. Results show the pipeline modernizes a range of benchmark kernels, producing performance-portable Kokkos codes across hardware partitions. Paid OpenAI models such as GPT-5 and o4-mini-high executed the workflow for only a few U.S. dollars, generating optimized codes that surpassed Fortran baselines, whereas open-source models like Llama4-Maverick often failed to yield functional codes. This work demonstrates the feasibility of agentic AI for Fortran-to-Kokkos transformation and offers a pathway for autonomously modernizing legacy scientific applications to run portably and efficiently on diverse supercomputers. It further highlights the potential of LLM-driven agentic systems to perform structured, domain-specific reasoning tasks in scientific and systems-oriented applications.
Figures & tables
| Kernel | Type | Modularized Subroutine Lines of Code |
| CG | Memory-bound | 165 |
| EP | Compute-bound | 129 |
| MG | Memory-bound | 139 |
| FT | Memory-bound | 230 |
| DGEMM | Compute-bound | 177 |
| BIHARMONIC | Memory-bound | 256 (132 + 124) * |
| GPU | CPU | Arch. | CPU Cores |
| NVIDIA A100, 40 GiB HBM2 | AMD EPYC 7763 | x86_64 | 64 |
| AMD MI250, 64 GB HBM2e | EPYC 7763 | x86_64 | 128 |
| NVIDIA GH200, 96 GB HBM3 | ARM Neoverse-V2 | aarch64 | 72 |
| Software | Version | Software | Version |
| Spack | 1.0.0.dev0 | GCC | 8.5.0 |
| CMake | 3.31.6 | Kokkos | 4.6.01 |
| CUDA | 12.6.3 | HIP | 6.4.0 |
| Python | 3.11.13 | OpenAI Agents SDK | 0.1.0 |
| LiteLLM | 1.73.6 | Ollama | 0.11.4 |
| Model | Provider | Type | Size (parameters) | Cost (in/out, per 1M tokens) |
| GPT-5 [ 20 ] | OpenAI | Proprietary | Unknown | 10 |
| o4-mini-high [ 21 ] | OpenAI | Proprietary | Unknown | 4.40 |
| gpt-oss-120b [ 22 ] | OpenAI | Open- weights | 117B total 5.1B active | - |
| Qwen3.5-397B -A17B [ 23 ] | Alibaba | Open- weights | 397B total 17B active | - |
| Llama 4 Maverick [ 24 ] | Meta | Open- weights | 400B total 17B active | - |
| Kernel | MIN_N | MAX_N | Num. of Sizes ( ) | Program Iters. | Kernel Reps ( ) |
| CG | 1000 | 1000000 | 10 | 2-5 | 500 |
| EP | 18 | 28 | 5 | 2-5 | 50 |
| MG | 32 | 256 | 10 | 2-10 | 250 |
| FT | 32 | 128 | 5 | 2-5 | 50 |
| DGEMM | 1024 | 4096 | 5 | 2-5 | 5 |
| BIHARMONIC | 64 | 2048 | 5 | 2-5 | 100 |
| Model | Type | Functional baseline * | Full workflow completed |
| GPT-5 | Proprietary | 29/30 (97%) | 24/30 (80%) |
| o4-mini-high | Proprietary | 28/30 (93%) | 17/30 (57%) |
| gpt-oss-120b | Open-weights | 19/30 (63%) | 11/30 (37%) |
| Qwen3.5-397B-A17B | Open-weights | 19/30 (63%) | 8/30 (27%) |
| Kernel (s = input size) | Best LLM | Achieved Performance | Arithmetic Intensity (FLOP/byte) | % of Roof Achieved | Bound |
| CG ( ) | Qwen3.5-397B-A17B | 998.89 GFLOPS | 0.839 | 76.54% | Memory |
| EP ( ) | GPT-5 | 6.23 TFLOPS | 83.07% | Compute | |
| MG ( ) | o4-mini-high | 2.80 TFLOPS | 2.898 | 62.11% | Memory |
| FT ( ) | Qwen3.5-397B-A17B | 268.50 GFLOPS | 1.021 | 16.91% | Memory |
| DGEMM ( ) | Qwen3.5-397B-A17B | 2.63 TFLOPS | 11.666 | 35.12% | Compute |
| BIHARMONIC ( ) | GPT-5 | 2.91 TFLOPS | 16.895 | 11.07% | Memory |
Code Translation
Code translation converts programs between languages, frameworks, and representations while aiming to preserve behavior and sometimes improve safety or performance.
See all 42 papers