xref: /netbsd-src/external/apache2/llvm/dist/clang/docs/OpenMPSupport.rst (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1.. raw:: html
2
3  <style type="text/css">
4    .none { background-color: #FFCCCC }
5    .part { background-color: #FFFF99 }
6    .good { background-color: #CCFF99 }
7  </style>
8
9.. role:: none
10.. role:: part
11.. role:: good
12
13.. contents::
14   :local:
15
16==================
17OpenMP Support
18==================
19
20Clang supports the following OpenMP 5.0 features (see also `OpenMP implementation details`_):
21
22* The `reduction`-based clauses in the `task` and `target`-based directives.
23
24* Support relational-op != (not-equal) as one of the canonical forms of random
25  access iterator.
26
27* Support for mapping of the lambdas in target regions.
28
29* Parsing/sema analysis for the requires directive.
30
31* Nested declare target directives.
32
33* Make the `this` pointer implicitly mapped as `map(this[:1])`.
34
35* The `close` *map-type-modifier*.
36
37Clang fully supports OpenMP 4.5. Clang supports offloading to X86_64, AArch64,
38PPC64[LE] and has `basic support for Cuda devices`_.
39
40* #pragma omp declare simd: :part:`Partial`.  We support parsing/semantic
41  analysis + generation of special attributes for X86 target, but still
42  missing the LLVM pass for vectorization.
43
44In addition, the LLVM OpenMP runtime `libomp` supports the OpenMP Tools
45Interface (OMPT) on x86, x86_64, AArch64, and PPC64 on Linux, Windows, and macOS.
46
47General improvements
48--------------------
49- New collapse clause scheme to avoid expensive remainder operations.
50  Compute loop index variables after collapsing a loop nest via the
51  collapse clause by replacing the expensive remainder operation with
52  multiplications and additions.
53
54- The default schedules for the `distribute` and `for` constructs in a
55  parallel region and in SPMD mode have changed to ensure coalesced
56  accesses. For the `distribute` construct, a static schedule is used
57  with a chunk size equal to the number of threads per team (default
58  value of threads or as specified by the `thread_limit` clause if
59  present). For the `for` construct, the schedule is static with chunk
60  size of one.
61
62- Simplified SPMD code generation for `distribute parallel for` when
63  the new default schedules are applicable.
64
65.. _basic support for Cuda devices:
66
67Cuda devices support
68====================
69
70Directives execution modes
71--------------------------
72
73Clang code generation for target regions supports two modes: the SPMD and
74non-SPMD modes. Clang chooses one of these two modes automatically based on the
75way directives and clauses on those directives are used. The SPMD mode uses a
76simplified set of runtime functions thus increasing performance at the cost of
77supporting some OpenMP features. The non-SPMD mode is the most generic mode and
78supports all currently available OpenMP features. The compiler will always
79attempt to use the SPMD mode wherever possible. SPMD mode will not be used if:
80
81   - The target region contains an `if()` clause that refers to a `parallel`
82     directive.
83
84   - The target region contains a `parallel` directive with a `num_threads()`
85     clause.
86
87   - The target region contains user code (other than OpenMP-specific
88     directives) in between the `target` and the `parallel` directives.
89
90Data-sharing modes
91------------------
92
93Clang supports two data-sharing models for Cuda devices: `Generic` and `Cuda`
94modes. The default mode is `Generic`. `Cuda` mode can give an additional
95performance and can be activated using the `-fopenmp-cuda-mode` flag. In
96`Generic` mode all local variables that can be shared in the parallel regions
97are stored in the global memory. In `Cuda` mode local variables are not shared
98between the threads and it is user responsibility to share the required data
99between the threads in the parallel regions.
100
101Collapsed loop nest counter
102---------------------------
103
104When using the collapse clause on a loop nest the default behavior is to
105automatically extend the representation of the loop counter to 64 bits for
106the cases where the sizes of the collapsed loops are not known at compile
107time. To prevent this conservative choice and use at most 32 bits,
108compile your program with the `-fopenmp-optimistic-collapse`.
109
110
111Features not supported or with limited support for Cuda devices
112---------------------------------------------------------------
113
114- Cancellation constructs are not supported.
115
116- Doacross loop nest is not supported.
117
118- User-defined reductions are supported only for trivial types.
119
120- Nested parallelism: inner parallel regions are executed sequentially.
121
122- Static linking of libraries containing device code is not supported yet.
123
124- Automatic translation of math functions in target regions to device-specific
125  math functions is not implemented yet.
126
127- Debug information for OpenMP target regions is supported, but sometimes it may
128  be required to manually specify the address class of the inspected variables.
129  In some cases the local variables are actually allocated in the global memory,
130  but the debug info may be not aware of it.
131
132
133.. _OpenMP implementation details:
134
135OpenMP 5.0 Implementation Details
136---------------------------------
137
138The following table provides a quick overview over various OpenMP 5.0 features
139and their implementation status. Please contact *openmp-dev* at
140*lists.llvm.org* for more information or if you want to help with the
141implementation.
142
143+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
144|Category                      | Feature                                                      | Status                   | Reviews                                                               |
145+==============================+==============================================================+==========================+=======================================================================+
146| loop extension               | support != in the canonical loop form                        | :good:`done`             | D54441                                                                |
147+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
148| loop extension               | #pragma omp loop (directive)                                 | :none:`unclaimed`        |                                                                       |
149+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
150| loop extension               | collapse imperfectly nested loop                             | :none:`unclaimed`        |                                                                       |
151+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
152| loop extension               | collapse non-rectangular nested loop                         | :good:`done`             |                                                                       |
153+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
154| loop extension               | C++ range-base for loop                                      | :none:`unclaimed`        |                                                                       |
155+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
156| loop extension               | clause: nosimd for SIMD directives                           | :none:`unclaimed`        |                                                                       |
157+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
158| loop extension               | inclusive scan extension (matching C++17 PSTL)               | :none:`unclaimed`        |                                                                       |
159+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
160| memory mangagement           | memory allocators                                            | :good:`done`             | r341687,r357929                                                       |
161+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
162| memory mangagement           | allocate directive and allocate clause                       | :good:`done`             | r355614,r335952                                                       |
163+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
164| OMPD                         | OMPD interfaces                                              | :part:`not upstream`     | https://github.com/OpenMPToolsInterface/LLVM-openmp/tree/ompd-tests   |
165+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
166| OMPT                         | OMPT interfaces                                              | :part:`mostly done`      |                                                                       |
167+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
168| thread affinity extension    | thread affinity extension                                    | :good:`done`             |                                                                       |
169+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
170| task extension               | taskloop reduction                                           | :good:`done`             |                                                                       |
171+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
172| task extension               | task affinity                                                | :part:`not upstream`     |                                                                       |
173+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
174| task extension               | clause: depend on the taskwait construct                     | :part:`worked on`        |                                                                       |
175+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
176| task extension               | depend objects and detachable tasks                          | :part:`worked on`        |                                                                       |
177+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
178| task extension               | mutexinoutset dependence-type for tasks                      | :good:`done`             | D53380,D57576                                                         |
179+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
180| task extension               | combined taskloop constructs                                 | :none:`unclaimed`        |                                                                       |
181+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
182| task extension               | master taskloop                                              | :good:`done`             |                                                                       |
183+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
184| task extension               | parallel master taskloop                                     | :none:`done`             |                                                                       |
185+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
186| task extension               | master taskloop simd                                         | :none:`done`             |                                                                       |
187+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
188| task extension               | parallel master taskloop simd                                | :none:`unclaimed`        |                                                                       |
189+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
190| SIMD extension               | atomic and critical constructs inside SIMD code              | :none:`unclaimed`        |                                                                       |
191+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
192| SIMD extension               | SIMD nontemporal                                             | :none:`unclaimed`        |                                                                       |
193+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
194| device extension             | infer target functions from initializers                     | :part:`worked on`        |                                                                       |
195+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
196| device extension             | infer target variables from initializers                     | :part:`worked on`        |                                                                       |
197+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
198| device extension             | OMP_TARGET_OFFLOAD environment variable                      | :good:`done`             | D50522                                                                |
199+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
200| device extension             | support full 'defaultmap' functionality                      | :part:`worked on`        |                                                                       |
201+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
202| device extension             | device specific functions                                    | :none:`unclaimed`        |                                                                       |
203+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
204| device extension             | clause: device_type                                          | :good:`done`             |                                                                       |
205+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
206| device extension             | clause: in_reduction                                         | :none:`unclaimed`        | r308768                                                               |
207+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
208| device extension             | omp_get_device_num()                                         | :part:`worked on`        | D54342                                                                |
209+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
210| device extension             | structure mapping of references                              | :none:`unclaimed`        |                                                                       |
211+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
212| device extension             | nested target declare                                        | :good:`done`             | D51378                                                                |
213+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
214| device extension             | implicitly map 'this' (this[:1])                             | :good:`done`             | D55982                                                                |
215+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
216| device extension             | allow access to the reference count (omp_target_is_present)  | :part:`worked on`        |                                                                       |
217+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
218| device extension             | requires directive (unified shared memory)                   | :part:`worked on`        |                                                                       |
219+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
220| device extension             | clause: unified_address, unified_shared_memory               | :part:`worked on`        | D52625,D52359                                                         |
221+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
222| device extension             | clause: reverse_offload                                      | :none:`unclaimed parts`  | D52780                                                                |
223+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
224| device extension             | clause: atomic_default_mem_order                             | :none:`unclaimed parts`  | D53513                                                                |
225+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
226| device extension             | clause: dynamic_allocators                                   | :none:`unclaimed parts`  | D53079                                                                |
227+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
228| device extension             | user-defined mappers                                         | :part:`worked on`        | D56326,D58638,D58523,D58074,D60972,D59474                             |
229+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
230| device extension             | mapping lambda expression                                    | :good:`done`             | D51107                                                                |
231+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
232| device extension             | clause: use_device_addr for target data                      | :good:`done`             |                                                                       |
233+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
234| device extension             | map(replicate) or map(local) when requires unified_shared_me | :part:`worked on`        | D55719,D55892                                                         |
235+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
236| device extension             | teams construct on the host device                           | :part:`worked on`        | Clang part is done, r371553.                                          |
237+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
238| atomic extension             | hints for the atomic construct                               | :part:`worked on`        | D51233                                                                |
239+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
240| base language                | C11 support                                                  | :none:`unclaimed`        |                                                                       |
241+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
242| base language                | C++11/14/17 support                                          | :none:`unclaimed`        |                                                                       |
243+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
244| base language                | lambda support                                               | :good:`done`             |                                                                       |
245+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
246| misc extension               | array shaping                                                | :none:`unclaimed`        |                                                                       |
247+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
248| misc extension               | library shutdown (omp_pause_resource[_all])                  | :none:`unclaimed parts`  | D55078                                                                |
249+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
250| misc extension               | metadirectives                                               | :none:`unclaimed`        |                                                                       |
251+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
252| misc extension               | conditional modifier for lastprivate clause                  | :none:`unclaimed`        |                                                                       |
253+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
254| misc extension               | user-defined function variants                               | :part:`worked on`        | D67294, D64095                                                        |
255+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
256| misc extensions              | pointer/reference to pointer based array reductions          | :none:`unclaimed`        |                                                                       |
257+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
258| misc extensions              | prevent new type definitions in clauses                      | :none:`unclaimed`        |                                                                       |
259+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
260