xref: /llvm-project/openmp/docs/remarks/OMP131.rst (revision dead50d4427cbdd5f41c02c5441270822f702730)
1Rewriting generic-mode kernel with a customized state machine. [OMP131]
2=======================================================================
3
4.. _omp131:
5
6This optimization remark indicates that a generic-mode kernel on the device was
7specialized for the given target region. When offloading in generic-mode, a
8state machine is required to schedule the work between the parallel worker
9threads. This optimization specializes the state machine in cases where there is
10a known number of parallel regions inside the kernel. A much simpler state
11machine can be used if it is known that there is no nested parallelism and the
12number of regions to schedule is a static amount.
13
14Examples
15--------
16
17This optimization should occur on any generic-mode kernel that has visibility on
18all parallel regions, but cannot be moved to SPMD-mode and has no nested
19parallelism.
20
21.. code-block:: c++
22
23   #pragma omp declare target
24   int TID;
25   #pragma omp end declare target
26
27   void foo() {
28   #pragma omp target
29   {
30    TID = omp_get_thread_num();
31    #pragma omp parallel
32    {
33      work();
34    }
35   }
36   }
37
38.. code-block:: console
39
40   $ clang++ -fopenmp -fopenmp-targets=nvptx64 -O2 -Rpass=openmp-opt omp131.cpp
41   omp131.cpp:8:1: remark: Rewriting generic-mode kernel with a customized state machine. [OMP131]
42   #pragma omp target
43   ^
44
45Diagnostic Scope
46----------------
47
48OpenMP target offloading optimization remark.
49