An AMD engineer has landed experimental support within the LLVM codebase for building Flang-RT on GPUs. Flang-RT being the run-time for LLVM’s modern Fortran “Flang” compiler and in turn this effort working to allow more Fortran code to easily run on GPUs with capable LLVM back-ends.
AMD engineer Joseph Huber continues working on nifty improvements to the LLVM compiler stack on the GPU side. Joseph Huber was the one who last year ported DOOM to run o nthe GPU using AMD ROCm and LLVM libc. While that DOOM port was just a fun example, it’s part of a broader AMD effort for getting more standard C/C++ code to run directly on GPUs. Or in this case, more easily getting Fortran code running on GPUs.
Merged to LLVM 21 Git today by Huber was [flang-rt] Add experimental support for GPU build:
“This patch adds initial support for compiling `flang-rt` directly for the GPU. The method used here matches what’s already done for `libc` and `libc++` for the GPU and builds off of those projects.
Mainly this requires setting up some flags and setting the sources that currently work. This will deposit the resulting library in the appropriate directory. These files are then intended to be linked via `-Xoffload-linker` support in the offloading driver.
“`
lib/clang/21/lib/nvptx64-nvidia-cuda/libflang_rt.runtime.a
lib/clang/21/lib/amdgcn-amd-amdhsa/libflang_rt.runtime.a
“`This is obviously missing a lot of functions, mainly the `io` support. Most of what we cannot support is due to using POSIX things that just don’t make sense on the GPU. Stuff like `pthreads` or `sema`.”
This flang-rt GPU building work in turn is working for opening upstream Flang to GPU-based execution not only for AMD GPUs but with the NVIDIA CUDA/PTX back-end for LLVM and the like is beneficial to other hardware too. Again, what’s upstream today in LLVM is just the initial experimental support.
Merged a few days ago as well by Joseph Huber was making the GPU loader utilities an LLVM tool as another step toward improving the GPU execution experience within LLVM.