arXiv:2608.00130cs.PLcs.AI2026-08

将老式Fortran代码自动转为可运行的Python/JAX程序,解决科学计算现代化难题。

A Fortran General-Purpose Transpiler: Proof of Concept

论文配图:A Fortran General-Purpose Transpiler: Proof of Concept
图 1 · 摘自论文原文
  • 分三阶段处理:解析、中间表示转换、生成目标代码,确保语义不变。
  • 在气候模拟核心代码上验证,生成结果正确且支持自动微分。
  • 适合需要现代化遗留科学代码的科研团队,尤其关注数值精度和自动化。

Fortran作为高性能计算的基石,仍广泛应用于多个领域,但面临人才断层问题:新一代科研人员普遍不熟悉该语言,而资深开发者也正逐步转向JAX等现代生态。这导致大量‘Fython’——以Fortran思维编写的低效Python代码——出现,无法发挥现代框架优势。本文提出FGPT,一个通用的Fortran转译框架,可系统性地将Fortran代码转为适配GPU的Fortran、支持自动微分的Fortran(通过Tapenade),或NumPy与JAX脚本。其架构包含三阶段:(i) 前端解析Fortran并提取目标过程及其依赖;(ii) 中间件将代码降至中间表示,再转换为GPU优化或自动微分版本,或生成NumPy类;(iii) 后端将NumPy脚本转化为针对GPU加速和自动微分优化的JAX模块。大型科学代码通常达数十万行,大模型在此规模下失效,因难以保证一致转换、严格数值保真及生产级测试验证。FGPT通过全程保持程序语义完整性,解决了这些问题。我们在代表性气候建模核心代码上验证了该框架,证明其可生成无须人工干预的正确、可微分的Python实现。结合严谨的编译技术与现代加速器支持,FGPT为老旧Fortran代码的现代化提供了可扩展、可信的路径。

原文摘要 · Abstract (English)

Fortran has been the cornerstone of high-performance computing for decades and remains unmatched in many domains. Yet the language faces an expertise gap: a new generation of scientists is barely familiar with it, while many experienced Fortran developers are only now transitioning to modern ecosystems such as JAX. This gap often results in "Fython" - Python code written with a Fortran mindset - that fails to leverage modern frameworks. We present FGPT, a transpiler framework designed to bridge this gap. It provides a systematic pipeline that transpiles Fortran into GPU-adapted Fortran, auto-differentiable Fortran via Tapenade, or NumPy and JAX scripts. Its architecture comprises three stages: (i) a frontend that parses Fortran and extracts target procedures along with all their dependencies; (ii) a middle-end that lowers the code into an intermediate representation, then into GPU-adapted or auto-differentiable Fortran, or a NumPy class; and (iii) a backend that transforms NumPy scripts into JAX modules optimized for GPU acceleration and automatic differentiation. Large language models fail when applied to the scale of community scientific codes-often spanning hundreds of thousands of lines-where consistent transformations, strict numerical fidelity, and validation against production tests are non-negotiable. FGPT addresses these challenges by preserving program semantics throughout the entire translation. We verified the framework on representative climate modeling kernels and demonstrated that it produces correct, differentiable Python implementations without requiring manual intervention. By combining rigorous compiler techniques with modern accelerator support, FGPT offers a scalable, trustworthy path for modernizing legacy Fortran code.

代码转译科学计算JAXFortran

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。