Large language models (LLMs) can translate and modify source code, and have been shown to do so for codes of different complexity. Whether they can port a complete, production geophysical model to a different language without degrading its physics has not been established. We demonstrate that LLM-assisted code translation can preserve the physics of a complete production ocean model while moving it into a modern performance-portable form. We report our experience using an agentic LLM coding assistant, directed by domain experts, to port the FESOM2 unstructured mesh ocean--sea-ice model (about 74000 lines of core Fortran) first to C and then to C++/Kokkos for performance portability across CPUs and GPUs. We describe the practices that proved necessary, what worked and what did not, and the failure modes that we encountered. Three practices mattered most: translating in two stages that separate reproducing the numerics (Fortran to a clean C reference) from introducing parallelism (C to Kokkos); requiring a strictly literal translation in which the assistant was not permitted to ``improve'' the source; and validating each stage against an acceptance criterion suited to it. The C port reproduces the original Fortran at the level of long-term simulation statistics over five years. The Kokkos port is bit-for-bit identical to the C reference on CPU and statistically close on GPU over multi-year runs. On eddy-rich meshes up to 7.4 million surface vertices a single A100 GPU node runs 1.6--3.7 times faster than a CPU node, reaching the 1-2 simulated-years-per-day required for production integrations. The result is more than a single GPU port: by following a clear validation procedure, an LLM moved a full Fortran ocean model into another language and onto accelerators while preserving its physics in a matter of weeks.
翻译:大语言模型(LLMs)能够翻译和修改源代码,且已被证明可处理不同复杂程度的代码。然而,它们能否在保留物理过程完整性的前提下,将完整的生产级地球物理模式移植至另一种语言,此前尚未得到证实。我们证明,LLM辅助的代码翻译能保留完整生产级海洋模式的物理过程,同时将其转化为现代性能可移植形式。我们报告了在领域专家指导下,使用智能体型LLM编程助手将FESOM2非结构化网格海洋-海冰模式(约74000行核心Fortran代码)先移植至C语言,再移植至C++/Kokkos以实现跨CPU和GPU性能可移植性的实践经验。我们描述了被证明必要的实践方法、有效和无效的策略,以及遇到的失败模式。三项实践最为关键:分两阶段翻译——将再现数值计算(Fortran到纯净C参考实现)与引入并行化(C到Kokkos)分离;要求严格直译,禁止助手"优化"源代码;对每个阶段采用适配的验收标准进行验证。C移植版本在长达五年的长期模拟统计量层面复现了原始Fortran结果。Kokkos版本的CPU计算结果与C参考实现逐位一致,多年运行的GPU结果在统计上接近。在拥有高达740万表面顶点的涡旋丰富网格上,单个A100 GPU节点较CPU节点运行速度快1.6-3.7倍,达到生产集成所需的每日1-2模拟年速度。成果不仅限于单个GPU移植:通过遵循明确的验证流程,LLM在数周内将完整的Fortran海洋模式移植至另一种语言及加速器,同时保留了其物理过程。