Joseph Huber | 6242f9b | 2021-07-20 16:04:13 | [diff] [blame] | 1 | .. _omp121: |
| 2 | |
Sirraide | c44fa3e | 2024-05-22 15:58:48 | [diff] [blame] | 3 | Value has potential side effects preventing SPMD-mode execution. Add `[[omp::assume(\"ompx_spmd_amenable\")]]` to the called function to override. [OMP121] |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 4 | =================================================================================================================================================================== |
| 5 | |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 6 | This analysis remarks indicates that a potential side-effect that cannot be |
| 7 | guarded prevents the target region from executing in SPMD-mode. SPMD-mode |
| 8 | requires that each thread is active inside the region. Any instruction that |
| 9 | cannot be either recomputed by each thread independently or guarded and executed |
Shao-Ce SUN | 0c66025 | 2021-11-15 01:17:08 | [diff] [blame] | 10 | by a single thread prevents the region from executing in SPMD-mode. |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 11 | |
| 12 | This remark will attempt to print out the instructions preventing the region |
| 13 | from being executed in SPMD-mode. Calls to functions outside the current |
| 14 | translation unit will prevent this transformation from occurring as well, but |
| 15 | can be overridden using an assumption stating that it contains no calls that |
| 16 | prevent SPMD execution. |
| 17 | |
| 18 | Examples |
| 19 | -------- |
| 20 | |
| 21 | Calls to functions outside the current translation unit may contain instructions |
| 22 | or operations that cannot be executed in SPMD-mode. |
| 23 | |
| 24 | .. code-block:: c++ |
| 25 | |
| 26 | extern int work(); |
| 27 | |
| 28 | void use(int x); |
Shao-Ce SUN | 0c66025 | 2021-11-15 01:17:08 | [diff] [blame] | 29 | |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 30 | void foo() { |
| 31 | #pragma omp target teams |
| 32 | { |
| 33 | int x = work(); |
| 34 | #pragma omp parallel |
| 35 | use(x); |
Shao-Ce SUN | 0c66025 | 2021-11-15 01:17:08 | [diff] [blame] | 36 | |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
| 40 | |
| 41 | .. code-block:: console |
| 42 | |
| 43 | $ clang++ -fopenmp -fopenmp-targets=nvptx64 -O2 -Rpass-analysis=openmp-opt omp121.cpp |
Shao-Ce SUN | 0c66025 | 2021-11-15 01:17:08 | [diff] [blame] | 44 | omp121.cpp:8:13: remark: Value has potential side effects preventing SPMD-mode |
Sirraide | c44fa3e | 2024-05-22 15:58:48 | [diff] [blame] | 45 | execution. Add `[[omp::assume("ompx_spmd_amenable")]]` to the called function |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 46 | to override. [OMP121] |
| 47 | int x = work(); |
| 48 | ^ |
| 49 | |
| 50 | As the remark suggests, the problem is caused by the unknown call to the |
| 51 | external function ``work``. This can be overridden by asserting that it does not |
| 52 | contain any code that prevents SPMD-mode execution. |
| 53 | |
| 54 | .. code-block:: c++ |
| 55 | |
Sirraide | c44fa3e | 2024-05-22 15:58:48 | [diff] [blame] | 56 | [[omp::assume("ompx_spmd_amenable")]] extern int work(); |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 57 | |
| 58 | void use(int x); |
Shao-Ce SUN | 0c66025 | 2021-11-15 01:17:08 | [diff] [blame] | 59 | |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 60 | void foo() { |
| 61 | #pragma omp target teams |
| 62 | { |
| 63 | int x = work(); |
| 64 | #pragma omp parallel |
| 65 | use(x); |
Shao-Ce SUN | 0c66025 | 2021-11-15 01:17:08 | [diff] [blame] | 66 | |
Joseph Huber | 1616407 | 2021-07-14 21:04:54 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | .. code-block:: console |
| 71 | |
| 72 | $ clang++ -fopenmp -fopenmp-targets=nvptx64 -O2 -Rpass=openmp-opt omp121.cpp |
| 73 | omp121.cpp:6:1: remark: Transformed generic-mode kernel to SPMD-mode. [OMP120] |
| 74 | #pragma omp target teams |
| 75 | ^ |
| 76 | |
| 77 | Diagnostic Scope |
| 78 | ---------------- |
| 79 | |
| 80 | OpenMP target offloading analysis remark. |