fortranspire¶
An LLM + MCP pipeline that ports legacy Fortran HPC kernels to GPU (OpenACC) and differentiable JAX.
fortranspire automates the four transformations a senior HPC engineer
would perform by hand when porting a Fortran 90 kernel to GPU and Python:
Parse the source with Loki (ECMWF) — deterministic AST analysis of
INTENT,SAVE,COMMON,POINTER, and inline loops.Extract the kernels into a
MODULEwith explicitINTENT(INOUT)arguments — one LLM call against any OpenAI-compatible endpoint.Annotate purity (
PURE/ELEMENTAL) and insert OpenACC pragmas (!$acc parallel loop collapse(...),!$acc data copyin/copy).Wrap in Cython (NumPy typed memoryviews,
iso_c_bindingheader) and validate withgfortranandnvfortran -acc.
The pipeline is exposed as a CLI and as a Model Context Protocol (MCP) server, so it is callable from any MCP-aware client (Claude Desktop, Cursor, VS Code, Mistral Le Chat connectors) or any CI runner.
Getting started
Concepts
- Architecture
- Fortran patterns & transformation rules
- Summary table
- 1.
INTENT— the key to everything else - 2.
COMMONblocks — the global state to eliminate - 3.
SAVE— hidden state between calls - 4.
POINTER— dangerous aliasing for GPU - 5. Array of Structures → Structure of Arrays (AoS → SoA +
collapse) - 6. Nested dependencies — non-parallelisable loops
- 7.
ELEMENTAL+ OpenACC — the right pattern - 8. Explicit types — no compiler-inferred mixed precision
- 9. Logical flags
USE_xx→ compile-time directives - 10. MPI halo exchange → GHEX (GPU-to-GPU)
- 11. Fortran I/O → xarray / zarr + DLPack
- See also
- LLM endpoints
- Mistral integration
- Le Chat connector (preparation kit)
- Documenting a legacy Fortran codebase
- 4. PyTree State Injection
- 5. XLA Optimizations and
@jax.jit - 6. Performance Verdict
- Fortran → gt4py.next — pattern correspondences
- 1. Why gt4py.next is the right shape for this pipeline
- 2. The one mental-model shift
- 3. Pattern correspondence table
- 4. INTENT → arguments and returns (shared with Phase 2)
- 5. Neighbour access — the heart of a stencil
- 6. Conditionals →
where, neverif - 7. Unstructured neighbours → connectivity +
neighbor_sum(the primary horizontal model) - 8. Vertical recurrence →
scan_operator - 9. Dimensions, dtypes, and the portability score
- 10. What does not map — and must be reported, not emitted
- 11. Verified against gt4py.next 1.2.1
- 11bis. The domain and halos live in the driver (issue #82)
- 12. Where this plugs into the pipeline
- See also
- Fortran → gt4py.next — visual cheat-sheet
- JAX ↔ gt4py.next — the two functional targets
- Geometry catalogue & software decomposition
Integrations
- Use fortranspire from Claude Code
- Use fortranspire from mistral-vibe
- 🖥️ Tutoriel : Mode Interactif (Human-in-the-Loop)
- Claude Code GitHub Action — porting from a PR comment
- GitHub Copilot cloud agent
- GitHub App —
/fortranspirecommands on issues and PRs - Le Chat connector — hosted MCP for Mistral’s agent surface
Reference