Using OpenMP target offloading in llvm-8.0.0

Hello,

i came across this message on the list and found no better place to ask for help on a similar problem.
I am just experimenting offloading to x86_64 code from a x86_64 host system (ubuntu 18.04).
I have the packages:
- libomp-8-dev , containing among others :
   /usr/lib/llvm-8/lib/libomptarget.so
   /usr/lib/llvm-8/lib/libgomp.so
   /usr/lib/llvm-8/lib/libiomp5.so
   /usr/lib/llvm-8/lib/libomp.so
- clang-8

I compiled the same offload.c program as the one given in the referenced mail.

My first try was :
$ clang-8 -g -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu offload.c

which did produce a binary a.out, but this one fails with the cryptic error message:
$ export LD_LIBRARY_PATH=/usr/lib/llvm-8/lib/
$ ./a.out
Libomptarget fatal error 1: default offloading policy must switched to mandatory or disabled

Second try, after reading some of the hints was
$ clang-8 -g -I//usr/lib/llvm-8/include/ -L/usr/lib/llvm-8/lib -Xopenmp-target -march=x86-64 -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu offload.c

which resulted in the same error.
By the way, i have no clue why -Xopenmp-target -march=x86-64 would be required, which quite seem redundant with -fopenmp_targets.

I went to see the source code at
https://github.com/llvm-mirror/openmp/blob/master/libomptarget/src/interface.cpp line:56
but still can’t figure out what makes libomptarget unhappy.
In case this is related to ‘device’, i tested omp_get_default_device() which returns 1.

Any help would be appreciated.
Thanks.

This looks like a bug in 8.0 that is fixed in trunk.
You have a `target teams distribute`, right?

Can you put an empty target region before that and see if it helps.

Cheers,
  Johannes

P.S.
This is the right place to ask these questions

Thanks for the quick answer.

This looks like a bug in 8.0 that is fixed in trunk.
You have a `target teams distribute`, right?

Can you put an empty target region before that and see if it helps.

Yes, indeed the weird error message disappears after inserting a parallel target region,
that is, the following code works.

#include <omp.h>
#include <stdio.h>
int a[100];

int main() {

  printf("* number of devices: %d\n",omp_get_num_devices());
#pragma omp target
{
}

#pragma omp target teams distribute parallel for
  for(int i=0; i<100; i++)
        a[i]++;
  return 0;
}