-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Flang][OpenMP]Support for lowering task_reduction and in_reduction to MLIR #111155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
60cbcc2
1b5a47e
3f53c5e
c2026f4
258259a
4954246
32e59c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -344,8 +344,15 @@ void DataSharingProcessor::collectSymbols( | |||||
| // Collect all symbols referenced in the evaluation being processed, | ||||||
| // that matches 'flag'. | ||||||
| llvm::SetVector<const semantics::Symbol *> allSymbols; | ||||||
|
|
||||||
| auto itr = llvm::find_if(clauses, [](const omp::Clause &clause) { | ||||||
| return clause.id == llvm::omp::Clause::OMPC_in_reduction; | ||||||
| }); | ||||||
|
|
||||||
| bool collectSymbols = (itr == clauses.end()); | ||||||
|
|
||||||
| converter.collectSymbolSet(eval, allSymbols, flag, | ||||||
| /*collectSymbols=*/true, | ||||||
| /*collectSymbols=*/collectSymbols, | ||||||
|
||||||
| /*collectSymbols=*/collectSymbols, | |
| collectSymbols, |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1249,34 +1249,34 @@ static void genTargetEnterExitUpdateDataClauses( | |||||||||||||||
| cp.processNowait(clauseOps); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| static void genTaskClauses(lower::AbstractConverter &converter, | ||||||||||||||||
| semantics::SemanticsContext &semaCtx, | ||||||||||||||||
| lower::StatementContext &stmtCtx, | ||||||||||||||||
| const List<Clause> &clauses, mlir::Location loc, | ||||||||||||||||
| mlir::omp::TaskOperands &clauseOps) { | ||||||||||||||||
| static void genTaskClauses( | ||||||||||||||||
| lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx, | ||||||||||||||||
| lower::StatementContext &stmtCtx, const List<Clause> &clauses, | ||||||||||||||||
| mlir::Location loc, mlir::omp::TaskOperands &clauseOps, | ||||||||||||||||
| llvm::SmallVectorImpl<const semantics::Symbol *> &inReductionSyms) { | ||||||||||||||||
| ClauseProcessor cp(converter, semaCtx, clauses); | ||||||||||||||||
| cp.processAllocate(clauseOps); | ||||||||||||||||
| cp.processDepend(clauseOps); | ||||||||||||||||
| cp.processFinal(stmtCtx, clauseOps); | ||||||||||||||||
| cp.processIf(llvm::omp::Directive::OMPD_task, clauseOps); | ||||||||||||||||
| cp.processInReduction(loc, clauseOps, inReductionSyms); | ||||||||||||||||
| cp.processMergeable(clauseOps); | ||||||||||||||||
| cp.processPriority(stmtCtx, clauseOps); | ||||||||||||||||
| cp.processUntied(clauseOps); | ||||||||||||||||
| cp.processDetach(clauseOps); | ||||||||||||||||
| // TODO Support delayed privatization. | ||||||||||||||||
|
|
||||||||||||||||
| cp.processTODO<clause::Affinity, clause::InReduction>( | ||||||||||||||||
| loc, llvm::omp::Directive::OMPD_task); | ||||||||||||||||
| cp.processTODO<clause::Affinity>(loc, llvm::omp::Directive::OMPD_task); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| static void genTaskgroupClauses(lower::AbstractConverter &converter, | ||||||||||||||||
| semantics::SemanticsContext &semaCtx, | ||||||||||||||||
| const List<Clause> &clauses, mlir::Location loc, | ||||||||||||||||
| mlir::omp::TaskgroupOperands &clauseOps) { | ||||||||||||||||
| static void genTaskgroupClauses( | ||||||||||||||||
| lower::AbstractConverter &converter, semantics::SemanticsContext &semaCtx, | ||||||||||||||||
| const List<Clause> &clauses, mlir::Location loc, | ||||||||||||||||
| mlir::omp::TaskgroupOperands &clauseOps, | ||||||||||||||||
| llvm::SmallVectorImpl<const semantics::Symbol *> &taskReductionSyms) { | ||||||||||||||||
| ClauseProcessor cp(converter, semaCtx, clauses); | ||||||||||||||||
| cp.processAllocate(clauseOps); | ||||||||||||||||
| cp.processTODO<clause::TaskReduction>(loc, | ||||||||||||||||
| llvm::omp::Directive::OMPD_taskgroup); | ||||||||||||||||
| cp.processTaskReduction(loc, clauseOps, taskReductionSyms); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| static void genTaskwaitClauses(lower::AbstractConverter &converter, | ||||||||||||||||
|
|
@@ -1887,7 +1887,9 @@ genTaskOp(lower::AbstractConverter &converter, lower::SymMap &symTable, | |||||||||||||||
| ConstructQueue::const_iterator item) { | ||||||||||||||||
| lower::StatementContext stmtCtx; | ||||||||||||||||
| mlir::omp::TaskOperands clauseOps; | ||||||||||||||||
| genTaskClauses(converter, semaCtx, stmtCtx, item->clauses, loc, clauseOps); | ||||||||||||||||
| llvm::SmallVector<const semantics::Symbol *> inReductionSyms; | ||||||||||||||||
| genTaskClauses(converter, semaCtx, stmtCtx, item->clauses, loc, clauseOps, | ||||||||||||||||
| inReductionSyms); | ||||||||||||||||
|
|
||||||||||||||||
| if (!enableDelayedPrivatization) | ||||||||||||||||
| return genOpWithBody<mlir::omp::TaskOp>( | ||||||||||||||||
|
|
@@ -1904,22 +1906,27 @@ genTaskOp(lower::AbstractConverter &converter, lower::SymMap &symTable, | |||||||||||||||
| EntryBlockArgs taskArgs; | ||||||||||||||||
| taskArgs.priv.syms = dsp.getDelayedPrivSymbols(); | ||||||||||||||||
| taskArgs.priv.vars = clauseOps.privateVars; | ||||||||||||||||
| taskArgs.inReduction.syms = inReductionSyms; | ||||||||||||||||
| taskArgs.inReduction.vars = clauseOps.inReductionVars; | ||||||||||||||||
|
|
||||||||||||||||
| auto genRegionEntryCB = [&](mlir::Operation *op) { | ||||||||||||||||
| genEntryBlock(converter.getFirOpBuilder(), taskArgs, op->getRegion(0)); | ||||||||||||||||
| bindEntryBlockArgs(converter, | ||||||||||||||||
| llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), | ||||||||||||||||
| taskArgs); | ||||||||||||||||
| return llvm::to_vector(taskArgs.priv.syms); | ||||||||||||||||
| return llvm::to_vector(taskArgs.getSyms()); | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| return genOpWithBody<mlir::omp::TaskOp>( | ||||||||||||||||
| OpWithBodyGenInfo genInfo = | ||||||||||||||||
| OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval, | ||||||||||||||||
| llvm::omp::Directive::OMPD_task) | ||||||||||||||||
| .setClauses(&item->clauses) | ||||||||||||||||
| .setDataSharingProcessor(&dsp) | ||||||||||||||||
| .setGenRegionEntryCb(genRegionEntryCB), | ||||||||||||||||
| queue, item, clauseOps); | ||||||||||||||||
| .setGenRegionEntryCb(genRegionEntryCB); | ||||||||||||||||
|
|
||||||||||||||||
| auto taskOp = | ||||||||||||||||
| genOpWithBody<mlir::omp::TaskOp>(genInfo, queue, item, clauseOps); | ||||||||||||||||
| return taskOp; | ||||||||||||||||
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| static mlir::omp::TaskgroupOp | ||||||||||||||||
|
|
@@ -1929,13 +1936,28 @@ genTaskgroupOp(lower::AbstractConverter &converter, lower::SymMap &symTable, | |||||||||||||||
| const ConstructQueue &queue, | ||||||||||||||||
| ConstructQueue::const_iterator item) { | ||||||||||||||||
| mlir::omp::TaskgroupOperands clauseOps; | ||||||||||||||||
| genTaskgroupClauses(converter, semaCtx, item->clauses, loc, clauseOps); | ||||||||||||||||
| llvm::SmallVector<const semantics::Symbol *> taskReductionSyms; | ||||||||||||||||
| genTaskgroupClauses(converter, semaCtx, item->clauses, loc, clauseOps, | ||||||||||||||||
| taskReductionSyms); | ||||||||||||||||
|
|
||||||||||||||||
| return genOpWithBody<mlir::omp::TaskgroupOp>( | ||||||||||||||||
| EntryBlockArgs taskgroupArgs; | ||||||||||||||||
| taskgroupArgs.taskReduction.syms = taskReductionSyms; | ||||||||||||||||
| taskgroupArgs.taskReduction.vars = clauseOps.taskReductionVars; | ||||||||||||||||
|
|
||||||||||||||||
| auto genRegionEntryCB = [&](mlir::Operation *op) { | ||||||||||||||||
| genEntryBlock(converter.getFirOpBuilder(), taskgroupArgs, op->getRegion(0)); | ||||||||||||||||
| return llvm::to_vector(taskgroupArgs.getSyms()); | ||||||||||||||||
|
||||||||||||||||
| genEntryBlock(converter.getFirOpBuilder(), taskgroupArgs, op->getRegion(0)); | |
| return llvm::to_vector(taskgroupArgs.getSyms()); | |
| genEntryBlock(converter.getFirOpBuilder(), taskgroupArgs, op->getRegion(0)); | |
| bindEntryBlockArgs(converter, | |
| llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), | |
| taskgroupArgs); | |
| return llvm::to_vector(taskgroupArgs.getSyms()); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Same comment as above. For consistency, return directly the result of genOpWithBody and construct the genInfo argument within the argument list.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ! RUN: bbc -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s | ||
| ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s | ||
|
|
||
| !CHECK-LABEL: omp.declare_reduction | ||
| !CHECK-SAME: @[[RED_I32_NAME:.*]] : i32 init { | ||
| !CHECK: ^bb0(%{{.*}}: i32): | ||
| !CHECK: %[[C0_1:.*]] = arith.constant 0 : i32 | ||
| !CHECK: omp.yield(%[[C0_1]] : i32) | ||
| !CHECK: } combiner { | ||
| !CHECK: ^bb0(%[[ARG0:.*]]: i32, %[[ARG1:.*]]: i32): | ||
| !CHECK: %[[RES:.*]] = arith.addi %[[ARG0]], %[[ARG1]] : i32 | ||
| !CHECK: omp.yield(%[[RES]] : i32) | ||
| !CHECK: } | ||
|
|
||
| !CHECK-LABEL: func.func @_QPomp_task_in_reduction() { | ||
| ! [...] | ||
| !CHECK: omp.task in_reduction(@[[RED_I32_NAME]] %[[VAL_1:.*]]#0 -> %[[ARG0]] : !fir.ref<i32>) { | ||
| !CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[ARG0]] | ||
| !CHECK-SAME: {uniq_name = "_QFomp_task_in_reductionEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
| !CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<i32> | ||
| !CHECK: %[[VAL_6:.*]] = arith.constant 1 : i32 | ||
| !CHECK: %[[VAL_7:.*]] = arith.addi %[[VAL_5]], %[[VAL_6]] : i32 | ||
| !CHECK: hlfir.assign %[[VAL_7]] to %[[VAL_4]]#0 : i32, !fir.ref<i32> | ||
| !CHECK: omp.terminator | ||
| !CHECK: } | ||
| !CHECK: return | ||
| !CHECK: } | ||
|
|
||
| subroutine omp_task_in_reduction() | ||
| integer i | ||
| i = 0 | ||
| !$omp task in_reduction(+:i) | ||
| i = i + 1 | ||
| !$omp end task | ||
| end subroutine omp_task_in_reduction |
Uh oh!
There was an error while loading. Please reload this page.