Re:Translate Fortran to C++ with AI and RAG
by AndrewGaspar on Saturday April 19, 2025 @09:00PM
(#43740735)
What you want isn't really "output C++ code that is pedantically equivalent to this Fortran code but with the array indexing fixed up", it's usually more like "translate this Fortran module into something that I can offload to a GPU using CUDA/ROCm/etc. with the same high level semantics, but GPU-friendly low level optimizations", and the exact composition of those low level bits probably don't look exactly like a loop-by-loop translation.
Re:Translate Fortran to C++ with AI and RAG
by jeffbee on Saturday April 19, 2025 @09:59PM
(#43740997)
Doesn't CUDA handle FORTRAN as such?
CUDA supports Fortran, is one of the reasons OpenCL lost.
Re:Translate Fortran to C++ with AI and RAG
by SanjayMehta on Saturday April 19, 2025 @09:01PM
(#43740737)
I don’t know what the transpiled code would look like vs that rendered by an LLM, but maybe the hope is that latter will be more readable?
Re:Translate Fortran to C++ with AI and RAG
by int_19h on Sunday April 20, 2025 @03:13AM
(#43742100)
Yeah, but there's also N% chance that it's silently wrong.
Re:Translate Fortran to C++ with AI and RAG
by IshKebab on Sunday April 20, 2025 @03:16AM
(#43742115)
Yeah I've used FORTRAN to C transpilers before too and they worked fine. There were some downsides though like it has to add and subtract 1 everywhere to deal with FORTRAN's 1-based indexing.
In theory AI could do a more idiomatic translation, but I think I would still prefer the janky but correct translation over the looks nice but probably subtly buggy AI one.
I've actually had to do this with a couple of different Fortran projects when I was in college, I translated them to C for various reasons.
Maybe it's because it was specifically code written by scientists (i.e somewhat brute force and very straightforward) but there really wasn't very many features that I can recall that didn't have a direct C counterpart, other than column major ordering and arrays staring at 1.
Was I just blissfully unaware?