Hi @sttaft!
I took a look at your library as I was interested in OMP and Ada interop. I had seen your work in the past plus the one done by Sara Royuela and Luis Miguel’s.
From what I saw in parasail/lwt/lwt-openmp.ads at 19b7ca4eab850579fcf950f2c90a36c6439cb4a8 · parasail-lang/parasail · GitHub, you are not using pragma OMP
but “just” bolting the OMP infraestructure with Import
. I saw that in Sara’s and Miguel’s paper, they seem to be using pragma OMP
as their parallel directives, see their open access paper Enabling Ada and OpenMP runtimes interoperability through template-based execution. So it may seem that GNAT could potentially deal with OpenMP/OpenACC directives in Ada… I also know you/AdaCore have played around with this technology. I am interested in this technology as one can use OpenMP/OpenACC to offload code to accelerators, such as GFX cards (my laptop has two and GCC-GCN and NVPTX targets support them!).
Do you know if one can have somewhat native OpenMP/OpenACC support in Ada? Here is what I tried and what I got…
OpenMP turmoil
I tried reproducing some code snippets from the aforementioned paper with GNAT 14, using pragma OMP
, see the semi-valid code snipped below. However, it does not seem to be supported by GNAT.
with Ada.Text_IO; use Ada.Text_IO;
procedure Fibonacci_OMP is
function Parallel_Fibonacci(N : Positive) return Positive
is
pragma OMP (Parallel, Shared=>X,
Firstprivate => N);
pragma OMP (Single, Nowait);
X : Positive := 1;
Y : Positive := 1;
begin
if N <= 2 then
return N;
else
pragma OMP (task, Shared => X, Firstprivate => N);
X := Parallel_Fibonacci(N - 2);
pragma OMP (task, Shared => Y, Firstprivate => N);
Y := Parallel_Fibonacci(N - 2);
end if;
pragma OMP (taskwait);
return X + Y;
end Parallel_Fibonacci;
begin
Put_Line(Parallel_Fibonacci(50)'Image);
end Fibonacci_OMP;
If I compile the code with a simple gnatmake fibonacci-omp.adb
, GNAT gets confused by the existence of the task
keyword in the pragma
, see error below:
gcc -c fibonacci-omp.adb
fibonacci-omp.adb:15:22: error: missing operand
fibonacci-omp.adb:18:22: error: missing operand
fibonacci-omp.adb:20:06: error: missing "end;" for "begin" at line 18
fibonacci-omp.adb:20:06: error: missing "end;" for "begin" at line 15
fibonacci-omp.adb:20:06: error: missing "begin" for procedure <error> at line 12
gnatmake: "fibonacci-omp.adb" compilation error
If I issue the gnatmake fibonacci-omp.adb -fopenmp
compilation command, the compiler generates the same error message plus a warning, indicating that OpenMP is not supported for Ada:
gnat1: warning: command-line option ‘-fopenmp’ is valid for C/C++/Fortran/LTO/ObjC/ObjC++ but not for Ada
From what I saw, one can first do a normal code compilation into object code and then, during binding, the OpenMP infraestructure will be bolted in, so I ran gcc -c ada fibonacci-omp.adb -o fibonacci-omp.o -fopenmp
with the pragma OMP (task...)
commented out (so that it actually gets correctly parsed) and it generated the following:
fernando@localhost:~/Dirt> gcc -c ada fibonacci-omp.adb -o fibonacci-omp.o -fopenmp
gnat1: warning: command-line option ‘-fopenmp’ is valid for C/C++/Fortran/LTO/ObjC/ObjC++ but not for Ada
fibonacci-omp.adb:3:11: warning: file name does not match unit name, should be "fibonacci_omp.adb" [enabled by default]
fibonacci-omp.adb:6:14: warning: unrecognized pragma "Omp" [-gnatwg]
fibonacci-omp.adb:8:14: warning: unrecognized pragma "Omp" [-gnatwg]
fibonacci-omp.adb:22:14: warning: unrecognized pragma "Omp" [-gnatwg]
gcc: warning: ada: linker input file unused because linking not done
gcc: error: ada: linker input file not found: No such file or directory
It says that the OMP
pragma is not recognised… I expected it to be, as the code shown in Sara’s paper was used in the benchmark… I checked the generated object file to see if there were any .openmp
directives but there are none, so the OMP pragmas were completely ignored…
It should be possible?
From what I read in attachment:OpenMP-OpenACC-Offload-Cauldron2022-1.pdf of cauldron2022talks - GCC Wiki one could theoretically compile any code down to object/GIMPLE format (with the OpenMP directives being present in the generated file) and then that would be correctly processed down to assembly/the target architecture…
But of course, if the pragma OMP
directives are ignored, there is not that much to do…
Is there a special flag that needs to be given to GNAT in order for it to process OMP directives? Is it maybe a development branch that is being used?
OpenACC tests
I know that the idea of usign OpenACC has been studied within AdaCore (see this article/video). But once again, no info on the matter…
GNAT implementation
I saw no pragma
s related to parallelism/OpenMP/OpenACC/Offloading in the 2. Implementation Defined Pragmas — GNAT Reference Manual 25.0w documentation GNAT documentation… So there does not seem to be anything available…
Soooo… That is all from my side… It does not seem to be possible to have any OpenMP/OpenACC support in Ada from the default GCC/GNAT…
Have you/AdaCore explored upstreaming the work done? If it maybe possible to do so with LLVM? I know that there is GitHub - AdaCore/cuda and some CUDA support in GNAT…
EDIT: for information, here is the GCC documentation regarding offloading Offloading - GCC Wiki and Offloading - GCC Wiki AMD GCN Options (Using the GNU Compiler Collection (GCC))