Mapping of non-trivial type support

Hi,
This simple code:

int main() {
std::vector v(100, 0);
#pragma omp target teams distribute parallel for map(tofrom: v)
for (int i=0;i<100;i++) {
v[i] =i;
}
};

causes Clang to warn a message like:

vectormap.cpp:31:62: warning: Non-trivial type ‘std::vector’ is mapped, only trivial types are guaranteed to be mapped correctly [-Wopenmp-target]
#pragma omp target teams distribute parallel for map(tofrom: v)

^
1 warning generated.

… and encounters an issue at run time. How much non-trivial types are
supported in trunk Clang?

clang works in accordance with the standard. Standard says that mapping is performed as bitwise copy of the objects. You can perform the bitwise copy safely only for the trivial types.
You cannot simply map a vector. You need to convert it to C/C++ array at first.
OpenMP 5.0 introduced user-defined mappers to solve the problem of non-trivial types mapping, which are not supported by clang yet. We're working on this feature.

Best regards,
Alexey Bataev

Alexey et al.,
What’s the plan for OpenMP 5.0 API adoption in Clang? Would you point me to a link to an appropriate web page?
Is there an OpenMP 5.0 API work-in-progress branch which I can give it a try?

The plan to support it is “when it will be done”. No, there is no special branch for this.

Best regards,
Alexey Bataev

Alexey,
With OpenMP 4.5 API, what do I do to call a virtual function on the device?

You cannot map such variables, but you can try to define them on the device.

Best regards,
Alexey Bataev

Itaru, a webpage with implementation status details is in the works,
  https://reviews.llvm.org/D64375
but it seems hard to agree on an initial version.

In which issue the virtual function offloading feature support being worked on? I am not certain still after
going over the OpenMP 5.0 features list.

You mean, calling a virtual function of a mapped object?
That is, as far as I know, not OpenMP 5.0. It might make it in 5.1 though.
(Allocating the object on the device and then calling a virtual function should be fine though.)

@Ravi Is this correct?

It will be hard to map the type with the virtual functions. But OpenMP 5.0 introduces deep copy semantics. Anyway, I would not suggest to use virtual functions on the GPU, it is going to be very slow. Better to use trivial types, that can be bitcopied to/from GPUs.

Best regards,
Alexey Bataev

Correct.
We are still working on supporting function pointers which should include support for virtual function.

You can mark the class and object with declare target and use the object to invoke virtual function.
Currently you cannot pass an object through the map clause and use virtual function with that object.

Ravi,
Do you have a simple C++ code that does show how it is done? As I am still inserting a line

A a;

#pragma omp target data map(alloc: a)

?

A a;
#pragma omp declare target to(a)

Best regards,
Alexey Bataev

$ cat test.cpp
int main() {
int a;
#pragma omp declare target to (a)

}
$ clang++ -fopenmp -fopenmp-targets=nvptx64 test.cpp
test.cpp:3:21: error: unexpected OpenMP directive ‘#pragma omp declare target’
#pragma omp declare target to (a)
^

1 error generated.

Tested with the latest trunk Clang on POWER8.

It is applied only to global vars in the file/namespace scope.

Best regards,
Alexey Bataev

int a;
#pragma omp declare target to (a)

int main() {
#pragma omp target
a = 10;
#pragma omp target update from(a)
}