I want to use OpenMP target
construct to run a loop on a GPU device. After many trial, I discovered that my gcc compiler fails to compile a recursive function.
After many trials, I isolated my problem in this small test.c
function:
int func(int par){
if(par<0) return par;
return func(par--);
}
int main(void)
{
int N = 100;
#pragma omp target teams distribute parallel for
for (int i = 0; i<N; i++) {
func(i);
}
}
This is the way I compile it
gcc-12 -foffload=nvptx-none -fcf-protection=none -fno-stack-protector -foffload=-misa=sm_35 -fopenmp test.c -o testcpp.exe
This is the error I get:
test.c:5:5: error: alias definitions not supported in this configuration
5 | int func(int par){
| ^
mkoffload: fatal error: x86_64-linux-gnu-accel-nvptx-none-gcc-12 returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /usr/lib/gcc/x86_64-linux-gnu/12//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
The error disappears if I do not call func
recursively.
Note: I am aware that this test case is useless, however, consider that this is just a small example to reproduce the behaviour I have in a more complicated set-up.
How to reproduce the issue: I set up this small google-colab notebook where you can reproduce the issue: https://colab.research.google.com/drive/1zHVwKBt1hrkrDvw5IxqPwxovpC8gkVwA
My question is: how can I compile a kernel with recursion using OpenMP target
construct?