[Openmp-commits] [PATCH] D51107: [LIBOMPTARGET] Add support for mapping of lambda captures.

Alexey Bataev via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 23 06:14:17 PDT 2018


ABataev added a comment.

In https://reviews.llvm.org/D51107#1210775, @grokos wrote:

> In https://reviews.llvm.org/D51107#1209670, @ABataev wrote:
>
> > In https://reviews.llvm.org/D51107#1209660, @grokos wrote:
> >
> > > Is this patch about lambdas inside target regions or about lambdas containing a target region? From the description I assume it's the former. In that case, what happens if there are more than 1 lambdas in the target region?
> >
> >
> >
> >
> > 1. This is for lambdas inside target region.
> > 2. For each lambda we generate this sequence: <lambda1>, <capture1_1>, .., <capture1_n>, <lambda2>, <capture2_1>, ..., <capture2_m>, ...
>
>
> OK, I understand.
>
> As far as I know, lambdas are internally represented as structs, right? In that case, wouldn't it make sense to treat captured references as struct members? Then we would just use the `MEMBER_OF` field to find the base address of a lambda instead of relying on the last element in `tgt_args` (`omptarget.cpp:619`). Also, the reference would be marked with the `PTR_AND_OBJ` flag and there is already code to handle such entries, so there is no need to duplicate it (lines 612-640 of this patch basically replicate what is already implemented in `target_data_begin` in lines 254-270 and 316-332).


I tried it, it won't work.

1. Lambdas are captured as firstprivates, thus we cannot translate the host address of the lambda to the device address. `MEMBER_OF` does not work here because of that.
2. `PTR_AND_OBJ` performs the deep copy, which is incorrect. `LAMBDA_REF` translates host reference address to the previously mapped device reference address. It makes it possible to implement the correct behavior of the lambdas with the captures by reference.


Repository:
  rOMP OpenMP

https://reviews.llvm.org/D51107





More information about the Openmp-commits mailing list