[OpenMP] Add implicit data sharing support when offloading to NVIDIA GPUs using OpenM...
authorGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>
Tue, 21 Nov 2017 15:54:54 +0000 (15:54 +0000)
committerGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>
Tue, 21 Nov 2017 15:54:54 +0000 (15:54 +0000)
commiteb89b1d46f1eaca94f234feca53cf9b0ff2e6480
treeb658068bf90243451983bf83bcbf0f35fbb0cc89
parentff8b8aea2ef5a9a4e02e86b4c0850244d0b6047a
[OpenMP] Add implicit data sharing support when offloading to NVIDIA GPUs using OpenMP device offloading

Summary:
This patch is part of the development effort to add support in the current OpenMP GPU offloading implementation for implicitly sharing variables between a target region executed by the team master thread and the worker threads within that team.

This patch is the first of three required for successfully performing the implicit sharing of master thread variables with the worker threads within a team. The remaining two patches are:
- Patch D38978 to the LLVM NVPTX backend which ensures the lowering of shared variables to an device memory which allows the sharing of references;
- Patch (coming soon) is a patch to libomptarget runtime library which ensures that a list of references to shared variables is properly maintained.

A simple code snippet which illustrates an implicit data sharing situation is as follows:

```
#pragma omp target
{
   // master thread only
   int v;
   #pragma omp parallel
   {
      // worker threads
      // use v
   }
}
```

Variable v is implicitly shared from the team master thread which executes the code in between the target and parallel directives. The worker threads must operate on the latest version of v, including any updates performed by the master.

The code generated in this patch relies on the LLVM NVPTX patch (mentioned above) which prevents v from being lowered in the thread local memory of the master thread thus making the reference to this variable un-shareable with the workers. This ensures that the code generated by this patch is correct.
Since the parallel region is outlined the passing of arguments to the outlined regions must preserve the original order of arguments. The runtime therefore maintains a list of references to shared variables thus ensuring their passing in the correct order. The passing of arguments to the outlined parallel function is performed in a separate function which the data sharing infrastructure constructs in this patch. The function is inlined when optimizations are enabled.

Reviewers: hfinkel, carlo.bertolli, arpith-jacob, Hahnfeld, ABataev, caomhin

Reviewed By: ABataev

Subscribers: cfe-commits, jholewinski

Differential Revision: https://reviews.llvm.org/D38976

llvm-svn: 318773
clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
clang/test/OpenMP/nvptx_data_sharing.cpp [new file with mode: 0644]
clang/test/OpenMP/nvptx_parallel_codegen.cpp
clang/test/OpenMP/nvptx_target_teams_codegen.cpp