[flang-commits] [flang] [clang] [Flang][Driver] Enable gpulibc/nogpulibc options for Flang, which allows linking of GPU LIBC for the fortran and OpenMP runtime (PR #77135)

via flang-commits flang-commits at lists.llvm.org
Mon Jan 8 06:03:07 PST 2024


agozillon wrote:

> Thanks for the discussion!
> 
> > It defaults to on if it finds the `libc` wrapper headers in the `clang` resource directory, `lib/clang/18/include/llvm_libc_wrappers/llvm-libc-decls`. I'm assuming that Fortran doesn't have this?
> 
> It shouldn't, which means that the semantics of `-gpulibc` will be a bit different in Flang, right? That's something that could be tested.
> 

I believe Flang inherits this functionality via the addOpenMPDeviceLibC function in CommonArgs.cpp, which gets called after the Fortran runtime libraries are added for each of the relevant ToolChains (gnu etc.) from what I can tell! It's where the gpulibc/nogpulibc flags are also handled. However, the desired library doesn't reside in those directories with a regular build command, you seem to require adding the building of GPU libc specifically to your build options and then subsequently installing the build into a directory! The build I've tested with is an amalgamation of Clang/OpenMP/Flang/GPU LIBC.

That is to say the auto find and include seems to work quite happily for Flang (at least when the whole host of projects are enabled and installed), but having the options available would be desirable, the most important cases being to be able to turn off GPU libc inclusion in an installed build and turn it on in a regular non-installed build (provided it can find it in your environments path). Just more flexibility to replicate what Clang has just now.

> > I'm not familiar with how Fortran handles stuff here. It's tested in the clang portion at least. The handling of this is in CommonArgs somewhere I believe. If Fortran shares that it should be inherited, so it's at least tested in the clang version so it might be fine.
> 
> Some bits in "CommonArgs" will be shared, but we do specialise for Flang in various places. Also, tests in Clang check the driver in the "Clang" mode - it would be good to verify this option in the "Flang" mode as well. There's [driver-help.f90](https://github.com/llvm/llvm-project/pull/77135/files#diff-4c4771b20e711ab7224825cfe3902f57465195797c39a29d8a59027360f6bf30), but it is not that helpful (it only makes sure that we don't pollute `flang-new -help` with options from Clang that are not supported).
> 
> > However, i am a little bit of a driver and build environment/system noob
> 
> Not true, you've already landed a few patches :)

True, thank you :-)! 

> 
> > ill defer to everyone else's better judgement in this case!
> 
> Replicating the following would be sufficient: https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/openmp-offload-gpu.c#L392.

Thank you I'll add a similar test to the PR in the flang/test/Driver/omp-driver-offload.f90 test file, I believe this is still the closest equivalent we have to openmp-offload-gpu.c, but please do correct me if I am wrong!


https://github.com/llvm/llvm-project/pull/77135


More information about the flang-commits mailing list