llvm-project/mlir
William S. Moses 973cb2c326 [MLIR][OMP] Ensure nested scf.parallel execute all iterations
Presently, the lowering of nested scf.parallel loops to OpenMP creates one omp.parallel region, with two (nested) OpenMP worksharing loops on the inside. When lowered to LLVM and executed, this results in incorrect results. The reason for this is as follows:

An OpenMP parallel region results in the code being run with whatever number of threads available to OpenMP. Within a parallel region a worksharing loop divides up the total number of requested iterations by the available number of threads, and distributes accordingly. For a single ws loop in a parallel region, this works as intended.

Now consider nested ws loops as follows:

omp.parallel {
   A: omp.ws %i = 0...10 {
      B: omp.ws %j = 0...10 {
          code(%i, %j)
      }
   }
}

Suppose we ran this on two threads. The first workshare loop would decide to execute iterations 0, 1, 2, 3, 4 on thread 0, and iterations 5, 6, 7, 8, 9 on thread 1. The second workshare loop would decide the same for its iteration. This means thread 0 would execute i \in [0, 5) and j \in [0, 5). Thread 1 would execute i \in [5, 10) and j \in [5, 10). This means that iterations i in [5, 10), j in [0, 5) and i in [0, 5), j in [5, 10) never get executed, which is clearly wrong.

This permits two options for a remedy:
1) Change the semantics of the omp.wsloop to be distinct from that of the OpenMP runtime call or equivalently #pragma omp for. This could then allow some lowering transformation to remedy the aforementioned issue. I don't think this is desirable for an abstraction standpoint.
2) When lowering an scf.parallel always surround the wsloop with a new parallel region (thereby causing the innermost wsloop to use the number of threads available only to it).

This PR implements the latter change.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D108426
2021-08-20 19:06:28 -04:00
..
cmake/modules [MLIR] [Python] Fix out-of-tree Windows python bindings 2021-08-16 19:18:54 -07:00
docs [mlir][linalg] fixed typo 2021-08-11 11:59:15 -07:00
examples [mlir] factor memref-to-llvm lowering out of std-to-llvm 2021-07-09 14:49:52 +02:00
include [mlir][linalg] Finish refactor of TC ops to YAML 2021-08-20 12:35:04 -07:00
lib [MLIR][OMP] Ensure nested scf.parallel execute all iterations 2021-08-20 19:06:28 -04:00
python [mlir][linalg] Finish refactor of TC ops to YAML 2021-08-20 12:35:04 -07:00
test [MLIR][OMP] Ensure nested scf.parallel execute all iterations 2021-08-20 19:06:28 -04:00
tools [mlir][ods] Skip adding TOC in doc gen when present 2021-08-20 07:01:54 -07:00
unittests [mlir][Analysis][NFC] FlatAffineConstraints: Use BoundType enum in functions 2021-08-19 10:33:42 +09:00
utils [vscode-mlir] Add proper support for mlir markdown codeblocks 2021-08-03 19:55:31 +00:00
.clang-format
.clang-tidy NFC: .clang-tidy: Inherit configs from parents to improve maintainability 2021-06-08 08:25:59 -07:00
CMakeLists.txt [MLIR] Drop old cmake var names 2021-05-24 15:30:01 +05:30
LICENSE.TXT
README.md

README.md

Multi-Level Intermediate Representation

See https://mlir.llvm.org/ for more information.