[flang-commits] [flang] [flang][OpenMP][RFC] Add support for COPYPRIVATE (PR #73128)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Sun Nov 26 07:48:30 PST 2023


kiranchandramohan wrote:

> I am a bit rusty with OpenMP, but how do you ensure that the sync variable is shared by all the threads when this is a single in a subprogram without a parallel?
> 
> I would expect the alloca for the buffer to be "private" to each threads that entered the subprogram from a call in some parallel region (so unusable to broadcast the value to all threads).

I think @jeanPerier is right here, storing the sync variable on the stack is probably not sufficient. I guess a global or support from runtime is required. This is probably the reason that the `kmpc_copyprivate` runtime exists.
https://github.com/llvm/llvm-project/blob/f42eb15c39405a8ae26d7f4f2fe7b29337ed6799/openmp/runtime/src/kmp_csupport.cpp#L2180

> would there be advantages to keep the copyprivate implementation abstract in the IR (e.g, to not make the buffer/barriers/copies explicit yet)?

One advantage is that it will help make it possible to handle copyprivate with a call to the runtime.

I think two options for this are :
1. Since the copyprivate clause is only applicable to the single construct we could consider making the `omp.single` operation an operation with two regions. The semantics being that the first region is executed only by the `single` thread and all other threads execute the `copy` region after the `single` region is executed. The copy region can later become the copy function used in the `kmpc_copyprivate` runtime call.
```
omp.single copyprivate(x1,x2) {
 x1 = bval1
 x2 = bval2
} copy  {
bb0(tmp1,tmp2): !tmp1 and tmp2 are block arguments corresponding to the sync variables of x1 and x2
   x1 = tmp1
   x2 = tmp2
}
```
2. Model it like the OpenMP reduction/OpenACC reduction + privatisation with a declare/recipe function that can later be used to generate the copy function that is needed in the kmpc_copyprivate runtime call.
```
omp.single copyprivate(x1:copy_x1,x2:copy_x2) {
 x1 = bval1
 x2 = bval2
}
```

https://github.com/llvm/llvm-project/pull/73128


More information about the flang-commits mailing list