大型语言模型移植海洋模型:FESOM2(Fortran到C再到C++/Kokkos)的经验与教训
An Ocean Model Ported by a Large Language Model: Experience and Lessons from FESOM2 (Fortran to C to C++/Kokkos)
AI总结:
本文展示利用LLM将FESOM2海洋模型从Fortran移植到C再到C++/Kokkos,通过两阶段翻译、严格字面转换和逐级验证,在数周内保持物理准确性并实现GPU加速。
摘要:
大型语言模型(LLM)能够翻译和修改源代码,并且已被证明可以对不同复杂度的代码进行此类操作。然而,它们是否能够将完整的、生产级的地球物理模型移植到另一种语言而不降低其物理保真度,尚未得到证实。我们证明,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海洋模型迁移到另一种语言并移植到加速器上,同时保持了其物理特性。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。