CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
102 lines
3.6 KiB
C++
102 lines
3.6 KiB
C++
//===- StackToShared.cpp -------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements various OpenMP dialect utilities.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/OpenMP/Utils/Utils.h"
|
|
|
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
|
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
|
|
|
|
using namespace mlir;
|
|
|
|
static bool allocaUseRequiresSharedMem(const OpOperand &use) {
|
|
Operation *owner = use.getOwner();
|
|
if (auto parallelOp = dyn_cast<omp::ParallelOp>(owner)) {
|
|
if (llvm::is_contained(parallelOp.getReductionVars(), use.get()))
|
|
return true;
|
|
} else if (auto callOp = dyn_cast<CallOpInterface>(owner)) {
|
|
if (llvm::is_contained(callOp.getArgOperands(), use.get()))
|
|
return true;
|
|
}
|
|
|
|
// If it is used directly inside of a parallel region, it has to be replaced
|
|
// unless the use is a private clause.
|
|
if (owner->getParentOfType<omp::ParallelOp>()) {
|
|
if (auto argIface = dyn_cast<omp::BlockArgOpenMPOpInterface>(owner)) {
|
|
OperandRange privateVars = argIface.getPrivateVars();
|
|
auto it = llvm::find(privateVars, use.get());
|
|
if (it != privateVars.end()) {
|
|
auto privateSyms = owner->getAttrOfType<ArrayAttr>("private_syms");
|
|
size_t idx = std::distance(privateVars.begin(), it);
|
|
auto privateOp =
|
|
SymbolTable::lookupNearestSymbolFrom<omp::PrivateClauseOp>(
|
|
owner, cast<SymbolRefAttr>(privateSyms[idx]));
|
|
return privateOp.getDataSharingType() !=
|
|
omp::DataSharingClauseType::Private;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool mlir::omp::allocaUsesRequireSharedMem(Value alloc) {
|
|
for (const OpOperand &use : alloc.getUses()) {
|
|
Operation *owner = use.getOwner();
|
|
if (isa<LLVM::AddrSpaceCastOp, LLVM::GEPOp>(owner)) {
|
|
if (llvm::any_of(owner->getResults(), [&](Value result) {
|
|
return allocaUsesRequireSharedMem(result);
|
|
}))
|
|
return true;
|
|
} else if (allocaUseRequiresSharedMem(use)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool mlir::omp::opInSharedDeviceContext(Operation &op) {
|
|
if (isa<omp::ParallelOp>(op))
|
|
return false;
|
|
|
|
auto offloadIface = op.getParentOfType<omp::OffloadModuleInterface>();
|
|
if (!offloadIface || !offloadIface.getIsTargetDevice())
|
|
return false;
|
|
|
|
auto targetOp = op.getParentOfType<omp::TargetOp>();
|
|
|
|
// It must be inside of a generic omp.target or in a target device function,
|
|
// and not inside of omp.parallel.
|
|
if (auto parallelOp = op.getParentOfType<omp::ParallelOp>()) {
|
|
if (!targetOp || targetOp->isProperAncestor(parallelOp))
|
|
return false;
|
|
}
|
|
|
|
// The omp.target operation itself is considered in a shared device context in
|
|
// order to properly process its own allocation-defining entry block
|
|
// arguments.
|
|
if (!targetOp)
|
|
targetOp = dyn_cast<omp::TargetOp>(op);
|
|
|
|
if (targetOp) {
|
|
if (targetOp.getKernelExecFlags(targetOp.getInnermostCapturedOmpOp()) !=
|
|
omp::TargetExecMode::generic)
|
|
return false;
|
|
} else {
|
|
auto declTargetIface = op.getParentOfType<omp::DeclareTargetInterface>();
|
|
if (!declTargetIface || !declTargetIface.isDeclareTarget() ||
|
|
declTargetIface.getDeclareTargetDeviceType() ==
|
|
omp::DeclareTargetDeviceType::host)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|