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

[flang][OpenMP][DoConcurrent] Handle mapping non-reference values to device #233

Merged
merged 1 commit into from
Jan 2, 2025
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
22 changes: 15 additions & 7 deletions flang/lib/Optimizer/OpenMP/DoConcurrentConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {

return Fortran::lower::omp::internal::createMapInfoOp(
rewriter, liveIn.getLoc(), rawAddr,
/*varPtrPtr=*/{}, declareOp.getUniqName().str(), boundsOps,
/*varPtrPtr=*/{}, name.str(), boundsOps,
/*members=*/{},
/*membersIndex=*/mlir::ArrayAttr{},
static_cast<
Expand All @@ -814,8 +814,8 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
llvm::SmallVector<mlir::Type> regionArgTypes;
llvm::SmallVector<mlir::Location> regionArgLocs;

for (auto var :
llvm::concat<const mlir::Value>(clauseOps.hostEvalVars, mappedVars)) {
for (auto var : llvm::concat<const mlir::Value>(clauseOps.hostEvalVars,
clauseOps.mapVars)) {
regionArgTypes.push_back(var.getType());
regionArgLocs.push_back(var.getLoc());
}
Expand All @@ -825,11 +825,19 @@ class DoConcurrentConversion : public mlir::OpConversionPattern<fir::DoLoopOp> {
rewriter,
fir::getKindMapping(targetOp->getParentOfType<mlir::ModuleOp>()));

for (auto [arg, mapInfoOp, mappedVar] : llvm::zip_equal(
argIface.getMapBlockArgs(), clauseOps.mapVars, mappedVars)) {
// Within the loop, it possible that we discover other values that need to
// mapped to the target region (the shape info values for arrays, for
// example). Therefore, the map block args might be extended and resized.
// Hence, we invoke `argIface.getMapBlockArgs()` every iteration to make
// sure we access the proper vector of data.
int idx = 0;
for (auto [mapInfoOp, mappedVar] :
llvm::zip_equal(clauseOps.mapVars, mappedVars)) {
auto miOp = mlir::cast<mlir::omp::MapInfoOp>(mapInfoOp.getDefiningOp());
hlfir::DeclareOp liveInDeclare = genLiveInDeclare(
builder, targetOp, arg, miOp, liveInShapeInfoMap.at(mappedVar));
hlfir::DeclareOp liveInDeclare =
genLiveInDeclare(builder, targetOp, argIface.getMapBlockArgs()[idx],
miOp, liveInShapeInfoMap.at(mappedVar));
++idx;

// TODO If `mappedVar.getDefiningOp()` is a `fir::BoxAddrOp`, we probably
// need to "unpack" the box by getting the defining op of it's value.
Expand Down
30 changes: 30 additions & 0 deletions flang/test/Transforms/DoConcurrent/non_reference_to_device.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
! Tests that we can map "unnamed" and non-reference/non-box values to device; for
! example, values that result from `fix.box_dims` ops.

! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-parallel=device %s -o - \
! RUN: | FileCheck %s
! RUN: bbc -emit-hlfir -fopenmp -fdo-concurrent-parallel=device %s -o - \
! RUN: | FileCheck %s

subroutine test_non_refernece
integer i
real, allocatable :: arr(:)

associate(a => arr)
do concurrent (i = 1:10)
block
real z(size(a,1))
end block
end do
end associate
end subroutine test_non_refernece

! CHECK: %[[DIM_MAP:.*]] = omp.map.info var_ptr(%{{.*}} : !fir.ref<index>, index)
! CHECK-SAME: map_clauses(implicit, exit_release_or_enter_alloc)
! CHECK-SAME: capture(ByCopy) -> !fir.ref<index> {name = ""}


! CHECK: omp.target host_eval({{.*}} : index, index, index)
! CHECK-SAME: map_entries(%{{.*}} -> %{{.*}}, %[[DIM_MAP]] -> %{{.*}} :
! CHECK-SAME: !fir.ref<i32>, !fir.ref<index>)