Skip to content

Commit f4fe714

Browse files
authored
[Flang][OpenMP] Implement workdistribute construct lowering (#140523)
This PR introduces a new pass "lower-workdistribute" Fortran array statements are lowered to fir as fir.do_loop unordered. "lower-workdistribute" pass works mainly on identifying "fir.do_loop unordered" that is nested in target{teams{workdistribute{fir.do_loop unordered}}} and lowers it to target{teams{parallel{wsloop{loop_nest}}}}. It hoists all the other ops outside target region. Relaces heap allocation on target with omp.target_allocmem and deallocation with omp.target_freemem from host. Also replaces runtime function "Assign" with omp.target_memcpy from host. This pass implements following rewrites and optimisations: - **FissionWorkdistribute**: finds the parallelizable ops within teams {workdistribute} region and moves them to their own teams{workdistribute} region. - **WorkdistributeRuntimeCallLower**: finds the FortranAAssign calls nested in teams {workdistribute{}} and lowers it to unordered do loop if src is scalar and dest is array. Other runtime calls are not handled currently. - **WorkdistributeDoLower**: finds the fir.do_loop unoredered nested in teams {workdistribute{fir.do_loop unoredered}} and lowers it to teams {parallel { distribute {wsloop {loop_nest}}}}. - **TeamsWorkdistributeToSingle**: hoists all the ops inside teams {workdistribute{}} before teams op. The work in this PR is C-P and updated from @ivanradanov commits from coexecute implementation: [flang_workdistribute_iwomp_2024](https://github.com/ivanradanov/llvm-project/commits/flang_workdistribute_iwomp_2024) Paper related to this work by @ivanradanov ["Automatic Parallelization and OpenMP Offloadingof Fortran Array Notation"](https://www.osti.gov/servlets/purl/[2449728](https://www.osti.gov/servlets/purl/2449728))
1 parent eed8d3a commit f4fe714

20 files changed

+2685
-1
lines changed

flang/include/flang/Optimizer/OpenMP/Passes.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def LowerWorkshare : Pass<"lower-workshare", "::mlir::ModuleOp"> {
9393
let summary = "Lower workshare construct";
9494
}
9595

96+
def LowerWorkdistribute : Pass<"lower-workdistribute", "::mlir::ModuleOp"> {
97+
let summary = "Lower workdistribute construct";
98+
}
99+
96100
def GenericLoopConversionPass
97101
: Pass<"omp-generic-loop-conversion", "mlir::func::FuncOp"> {
98102
let summary = "Converts OpenMP generic `omp.loop` to semantically "

flang/lib/Optimizer/OpenMP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_flang_library(FlangOpenMPTransforms
88
MapsForPrivatizedSymbols.cpp
99
MapInfoFinalization.cpp
1010
MarkDeclareTarget.cpp
11+
LowerWorkdistribute.cpp
1112
LowerWorkshare.cpp
1213
LowerNontemporal.cpp
1314
SimdOnly.cpp

0 commit comments

Comments
 (0)