Skip to content

Commit

Permalink
Ensure that the same distribute op is enclosing the reduction.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjodin committed Nov 26, 2024
1 parent 85629e8 commit e63aa72
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1657,12 +1657,22 @@ convertOmpSingle(omp::SingleOp &singleOp, llvm::IRBuilderBase &builder,
static bool teamsReductionContainedInDistribute(omp::TeamsOp teamsOp) {
auto iface =
llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(teamsOp.getOperation());
// Check that all uses of the reduction block arg has a distribute op parent.
// Check that all uses of the reduction block arg has the same distribute op
// parent.
Operation* distOp = nullptr;
for (auto ra : iface.getReductionBlockArgs())
for (auto &use : ra.getUses()) {
auto useOp = use.getOwner();
if (!useOp->getParentOfType<omp::DistributeOp>())
auto currentDistOp = useOp->getParentOfType<omp::DistributeOp>();
// Use is not inside a distribute op - return false
if (!currentDistOp)
return false;
// Multiple distribute operations - return false
Operation *currentOp = currentDistOp.getOperation();
if (distOp && (distOp != currentOp))
return false;

distOp = currentOp;
}
return true;
}
Expand Down

0 comments on commit e63aa72

Please sign in to comment.