评估大型语言模型(LLM)用于将传统Fortran大气物理代码转换为GPU加速的JAX
Evaluating LLMs for Translating Legacy Fortran Atmospheric Physics to GPU-Accelerated JAX
AI总结:
该研究提出LAFT框架,结合确定性前端、数值验证等,用四个LLM将Fortran大气物理代码转成GPU加速JAX,其Gemini生成代码在100万大气柱下获357倍加速,为代码现代化提供实用方案。
摘要:
CESM、WRF和E3SM等大气模型中的传统Fortran物理包对其GPU现代化改造构成了障碍,而手动移植需要加速器编程专业知识。我们提出LAFT(LLM辅助Fortran翻译),这是一种智能体框架,用于将Fortran大气物理参数化转换为GPU加速的JAX,同时保留与Fortran参考代码的数值一致性。LAFT协调源代码分析、翻译、修复、运行时验证和性能分析,它结合了用于元数据提取和桥接生成的确定性前端、结构化翻译提示、数值验证以及分析指导的反馈,以识别低效执行模式。该桥接将数组布局转换与科学计算分开处理。我们使用Kessler暖雨微物理方案和四个大型语言模型(LLM):Claude、GPT、Gemini和Qwen对LAFT进行评估。所有四个经过验证的翻译在评估案例中都能重现与Fortran参考代码几乎达到浮点精度的输出,但它们的GPU性能因执行设计的不同而存在显著差异。在1,000,000个大气柱的缓存执行中,Gemini生成的实现比串行Fortran实现实现了高达357倍的加速(不包括编译和主机-设备传输)。结果表明,仅数值一致性并不能确保高效的GPU执行,并推动将数值验证与硬件感知性能分析相结合。LAFT通过LLM辅助翻译、确定性接口生成、自动化验证和修复以及可复现的分析,为传统大气物理代码的现代化提供了实用工作流。
英文摘要:
Legacy Fortran physics packages in atmospheric models such as CESM, WRF, and E3SM pose a barrier to GPU modernization, while manual porting requires accelerator-programming expertise. We present LAFT (LLM-Assisted Fortran Translation), an agentic framework for converting Fortran atmospheric physics parameterizations into GPU-accelerated JAX while preserving numerical agreement with the Fortran reference. LAFT coordinates source-code analysis, translation, repair, runtime validation, and performance profiling. It combines a deterministic front end for metadata extraction and bridge generation, structured translation prompts, numerical validation, and profiling-guided feedback to identify inefficient execution patterns. The bridge handles array-layout conversion separately from scientific computation. We evaluate LAFT using the Kessler warm-rain microphysics scheme and four LLMs: Claude, GPT, Gemini, and Qwen. All four validated translations reproduce the Fortran reference outputs to near floating-point precision for the evaluated case, but their GPU performance differs substantially with execution design. The Gemini-generated implementation achieves up to a 357-fold speedup over serial Fortran in cached execution at 1,000,000 atmospheric columns, excluding compilation and host-device transfers. The results demonstrate that numerical agreement alone does not ensure efficient GPU execution and motivate combining numerical validation with hardware-aware performance analysis. LAFT provides a practical workflow for modernizing legacy atmospheric physics code through LLM-assisted translation, deterministic interface generation, automated validation and repair, and reproducible profiling.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。