Skip to content
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

[MLIR][OpenMP] More robust support for target SPMD #161

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1127,13 +1127,16 @@ def TargetOp : OpenMP_Op<"target", traits = [
let hasVerifier = 1;

let extraClassDeclaration = [{
/// Returns the innermost OpenMP dialect operation nested inside of this
/// operation's region. For an operation to be detected as captured, it must
/// be inside a (possibly multi-level) nest of OpenMP dialect operation's
/// Returns the innermost OpenMP dialect operation captured by this target
/// construct. For an operation to be detected as captured, it must be
/// inside a (possibly multi-level) nest of OpenMP dialect operation's
/// regions where none of these levels contain other operations considered
/// not-allowed for these purposes (i.e. only terminator operations are
/// allowed from the OpenMP dialect, and other dialect's operations are
/// allowed as long as they don't have a memory write effect).
///
/// If there are omp.loop_nest operations in the sequence of nested
/// operations, the top level one will be the one captured.
Operation *getInnermostCapturedOmpOp();

/// Tells whether this target region represents a single worksharing loop
Expand Down
19 changes: 8 additions & 11 deletions mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,13 @@ Operation *TargetOp::getInnermostCapturedOmpOp() {
if (op == *this)
return;

// Reset captured op if crossing through an omp.loop_nest, so that the top
// level one will be the one captured.
if (llvm::isa<LoopNestOp>(op)) {
capturedOp = nullptr;
capturedParentRegion = nullptr;
}

bool isOmpDialect = op->getDialect() == ompDialect;
bool hasRegions = op->getNumRegions() > 0;

Expand Down Expand Up @@ -1583,21 +1590,11 @@ Operation *TargetOp::getInnermostCapturedOmpOp() {

bool TargetOp::isTargetSPMDLoop() {
Operation *capturedOp = getInnermostCapturedOmpOp();

// Allow an omp.atomic_update to be captured inside of the loop and still
// consider the parent omp.target operation to be potentially defining an SPMD
// loop.
// TODO: Potentially accept other captured OpenMP dialect operations as well,
// if they are allowed inside of an SPMD loop.
if (isa_and_present<AtomicUpdateOp>(capturedOp))
capturedOp = capturedOp->getParentOp();

if (!isa_and_present<LoopNestOp>(capturedOp))
return false;

Operation *workshareOp = capturedOp->getParentOp();

// Accept optional SIMD leaf construct.
Operation *workshareOp = capturedOp->getParentOp();
if (isa_and_present<SimdOp>(workshareOp))
workshareOp = workshareOp->getParentOp();

Expand Down