Skip to content

Commit e79d8f6

Browse files
[flang][acc] Update stride calculation to include inner-dimensions (#136613)
The acc.bounds operation allows specifying stride - but it did not clarify what it meant. The dialect was updated to specifically note that stride must capture inner dimension sizes when specified for outer dimensions. Flang lowering was also updated for OpenACC to adhere to this. This was already the case for descriptor-based arrays - but now this is also being done for all arrays.
1 parent 56910a8 commit e79d8f6

File tree

7 files changed

+80
-26
lines changed

7 files changed

+80
-26
lines changed

flang/include/flang/Lower/DirectivesCommon.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
670670
const std::vector<Fortran::evaluate::Subscript> &subscripts,
671671
std::stringstream &asFortran, fir::ExtendedValue &dataExv,
672672
bool dataExvIsAssumedSize, fir::factory::AddrAndBoundsInfo &info,
673-
bool treatIndexAsSection = false) {
673+
bool treatIndexAsSection = false,
674+
bool strideIncludeLowerExtent = false) {
674675
int dimension = 0;
675676
mlir::Type idxTy = builder.getIndexType();
676677
mlir::Type boundTy = builder.getType<BoundsType>();
@@ -679,6 +680,7 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
679680
mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0);
680681
mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
681682
const int dataExvRank = static_cast<int>(dataExv.rank());
683+
mlir::Value cumulativeExtent = one;
682684
for (const auto &subscript : subscripts) {
683685
const auto *triplet{std::get_if<Fortran::evaluate::Triplet>(&subscript.u)};
684686
if (triplet || treatIndexAsSection) {
@@ -847,6 +849,15 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
847849
ubound = builder.create<mlir::arith::SubIOp>(loc, extent, one);
848850
}
849851
}
852+
853+
// When the strideInBytes is true, it means the stride is from descriptor
854+
// and this already includes the lower extents.
855+
if (strideIncludeLowerExtent && !strideInBytes) {
856+
stride = cumulativeExtent;
857+
cumulativeExtent = builder.createOrFold<mlir::arith::MulIOp>(
858+
loc, cumulativeExtent, extent);
859+
}
860+
850861
mlir::Value bound = builder.create<BoundsOp>(
851862
loc, boundTy, lbound, ubound, extent, stride, strideInBytes, baseLb);
852863
bounds.push_back(bound);
@@ -882,7 +893,8 @@ fir::factory::AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
882893
const Fortran::semantics::MaybeExpr &maybeDesignator,
883894
mlir::Location operandLocation, std::stringstream &asFortran,
884895
llvm::SmallVector<mlir::Value> &bounds, bool treatIndexAsSection = false,
885-
bool unwrapFirBox = true, bool genDefaultBounds = true) {
896+
bool unwrapFirBox = true, bool genDefaultBounds = true,
897+
bool strideIncludeLowerExtent = false) {
886898
using namespace Fortran;
887899

888900
fir::factory::AddrAndBoundsInfo info;
@@ -943,7 +955,8 @@ fir::factory::AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
943955
asFortran << '(';
944956
bounds = genBoundsOps<BoundsOp, BoundsType>(
945957
builder, operandLocation, converter, stmtCtx, arrayRef->subscript(),
946-
asFortran, dataExv, dataExvIsAssumedSize, info, treatIndexAsSection);
958+
asFortran, dataExv, dataExvIsAssumedSize, info, treatIndexAsSection,
959+
strideIncludeLowerExtent);
947960
}
948961
asFortran << ')';
949962
} else if (auto compRef = detail::getRef<evaluate::Component>(designator)) {
@@ -955,7 +968,7 @@ fir::factory::AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
955968
mlir::isa<fir::SequenceType>(fir::unwrapRefType(info.addr.getType())))
956969
bounds = fir::factory::genBaseBoundsOps<BoundsOp, BoundsType>(
957970
builder, operandLocation, compExv,
958-
/*isAssumedSize=*/false);
971+
/*isAssumedSize=*/false, strideIncludeLowerExtent);
959972
asFortran << designator.AsFortran();
960973

961974
if (semantics::IsOptional(compRef->GetLastSymbol())) {
@@ -1012,7 +1025,8 @@ fir::factory::AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
10121025
if (genDefaultBounds &&
10131026
mlir::isa<fir::SequenceType>(fir::unwrapRefType(info.addr.getType())))
10141027
bounds = fir::factory::genBaseBoundsOps<BoundsOp, BoundsType>(
1015-
builder, operandLocation, dataExv, dataExvIsAssumedSize);
1028+
builder, operandLocation, dataExv, dataExvIsAssumedSize,
1029+
strideIncludeLowerExtent);
10161030
asFortran << symRef->get().name().ToString();
10171031
} else { // Unsupported
10181032
llvm::report_fatal_error("Unsupported type of OpenACC operand");

flang/include/flang/Optimizer/Builder/DirectivesCommon.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ genBoundsOpsFromBox(fir::FirOpBuilder &builder, mlir::Location loc,
203203
template <typename BoundsOp, typename BoundsType>
204204
llvm::SmallVector<mlir::Value>
205205
genBaseBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
206-
fir::ExtendedValue dataExv, bool isAssumedSize) {
206+
fir::ExtendedValue dataExv, bool isAssumedSize,
207+
bool strideIncludeLowerExtent = false) {
207208
mlir::Type idxTy = builder.getIndexType();
208209
mlir::Type boundTy = builder.getType<BoundsType>();
209210
llvm::SmallVector<mlir::Value> bounds;
@@ -213,23 +214,30 @@ genBaseBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
213214

214215
mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
215216
const unsigned rank = dataExv.rank();
217+
mlir::Value cumulativeExtent = one;
216218
for (unsigned dim = 0; dim < rank; ++dim) {
217219
mlir::Value baseLb =
218220
fir::factory::readLowerBound(builder, loc, dataExv, dim, one);
219221
mlir::Value zero = builder.createIntegerConstant(loc, idxTy, 0);
220222
mlir::Value ub;
221223
mlir::Value lb = zero;
222-
mlir::Value ext = fir::factory::readExtent(builder, loc, dataExv, dim);
224+
mlir::Value extent = fir::factory::readExtent(builder, loc, dataExv, dim);
223225
if (isAssumedSize && dim + 1 == rank) {
224-
ext = zero;
226+
extent = zero;
225227
ub = lb;
226228
} else {
227229
// ub = extent - 1
228-
ub = builder.create<mlir::arith::SubIOp>(loc, ext, one);
230+
ub = builder.create<mlir::arith::SubIOp>(loc, extent, one);
231+
}
232+
mlir::Value stride = one;
233+
if (strideIncludeLowerExtent) {
234+
stride = cumulativeExtent;
235+
cumulativeExtent = builder.createOrFold<mlir::arith::MulIOp>(
236+
loc, cumulativeExtent, extent);
229237
}
230238

231-
mlir::Value bound =
232-
builder.create<BoundsOp>(loc, boundTy, lb, ub, ext, one, false, baseLb);
239+
mlir::Value bound = builder.create<BoundsOp>(loc, boundTy, lb, ub, extent,
240+
stride, false, baseLb);
233241
bounds.push_back(bound);
234242
}
235243
return bounds;

flang/lib/Lower/OpenACC.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ static llvm::cl::opt<bool> generateDefaultBounds(
5252
llvm::cl::desc("Whether to generate default bounds for arrays."),
5353
llvm::cl::init(false));
5454

55+
static llvm::cl::opt<bool> strideIncludeLowerExtent(
56+
"openacc-stride-include-lower-extent",
57+
llvm::cl::desc(
58+
"Whether to include the lower dimensions extents in the stride."),
59+
llvm::cl::init(true));
60+
5561
// Special value for * passed in device_type or gang clauses.
5662
static constexpr std::int64_t starCst = -1;
5763

@@ -396,7 +402,8 @@ genDataOperandOperations(const Fortran::parser::AccObjectList &objectList,
396402
converter, builder, semanticsContext, stmtCtx, symbol, designator,
397403
operandLocation, asFortran, bounds,
398404
/*treatIndexAsSection=*/true, /*unwrapFirBox=*/unwrapFirBox,
399-
/*genDefaultBounds=*/generateDefaultBounds);
405+
/*genDefaultBounds=*/generateDefaultBounds,
406+
/*strideIncludeLowerExtent=*/strideIncludeLowerExtent);
400407
LLVM_DEBUG(llvm::dbgs() << __func__ << "\n"; info.dump(llvm::dbgs()));
401408

402409
// If the input value is optional and is not a descriptor, we use the
@@ -437,7 +444,8 @@ static void genDeclareDataOperandOperations(
437444
converter, builder, semanticsContext, stmtCtx, symbol, designator,
438445
operandLocation, asFortran, bounds,
439446
/*treatIndexAsSection=*/true, /*unwrapFirBox=*/unwrapFirBox,
440-
/*genDefaultBounds=*/generateDefaultBounds);
447+
/*genDefaultBounds=*/generateDefaultBounds,
448+
/*strideIncludeLowerExtent=*/strideIncludeLowerExtent);
441449
LLVM_DEBUG(llvm::dbgs() << __func__ << "\n"; info.dump(llvm::dbgs()));
442450
EntryOp op = createDataEntryOp<EntryOp>(
443451
builder, operandLocation, info.addr, asFortran, bounds, structured,
@@ -914,7 +922,8 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList,
914922
converter, builder, semanticsContext, stmtCtx, symbol, designator,
915923
operandLocation, asFortran, bounds,
916924
/*treatIndexAsSection=*/true, /*unwrapFirBox=*/unwrapFirBox,
917-
/*genDefaultBounds=*/generateDefaultBounds);
925+
/*genDefaultBounds=*/generateDefaultBounds,
926+
/*strideIncludeLowerExtent=*/strideIncludeLowerExtent);
918927
LLVM_DEBUG(llvm::dbgs() << __func__ << "\n"; info.dump(llvm::dbgs()));
919928

920929
RecipeOp recipe;
@@ -1545,7 +1554,8 @@ genReductions(const Fortran::parser::AccObjectListWithReduction &objectList,
15451554
converter, builder, semanticsContext, stmtCtx, symbol, designator,
15461555
operandLocation, asFortran, bounds,
15471556
/*treatIndexAsSection=*/true, /*unwrapFirBox=*/unwrapFirBox,
1548-
/*genDefaultBounds=*/generateDefaultBounds);
1557+
/*genDefaultBounds=*/generateDefaultBounds,
1558+
/*strideIncludeLowerExtent=*/strideIncludeLowerExtent);
15491559
LLVM_DEBUG(llvm::dbgs() << __func__ << "\n"; info.dump(llvm::dbgs()));
15501560

15511561
mlir::Type reductionTy = fir::unwrapRefType(info.addr.getType());

flang/test/Lower/OpenACC/acc-bounds.f90

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,19 @@ subroutine acc_optional_data3(a, n)
182182
! CHECK: %[[NOCREATE:.*]] = acc.nocreate varPtr(%[[DECL_A]]#1 : !fir.ref<!fir.array<?xf32>>) bounds(%[[BOUNDS]]) -> !fir.ref<!fir.array<?xf32>> {name = "a(1:n)"}
183183
! CHECK: acc.data dataOperands(%[[NOCREATE]] : !fir.ref<!fir.array<?xf32>>) {
184184

185+
subroutine acc_explicit_shape_3d(arr)
186+
real :: arr(1000,100,10)
187+
!$acc data copyin(arr(:1000,:100,:10))
188+
!$acc end data
189+
end subroutine
190+
191+
! Test that the stride is cummulative of the lower extents
192+
! CHECK-LABEL: func.func @_QMopenacc_boundsPacc_explicit_shape_3d(
193+
! CHECK-SAME: %[[ARR:.*]]: !fir.ref<!fir.array<1000x100x10xf32>> {fir.bindc_name = "arr"}) {
194+
! CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%c0 : index) upperbound(%c999 : index) extent(%c1000 : index) stride(%c1{{.*}} : index) startIdx(%c1 : index)
195+
! CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%c0 : index) upperbound(%c99 : index) extent(%c100 : index) stride(%c1000{{.*}} : index) startIdx(%c1 : index)
196+
! CHECK: %[[BOUND3:.*]] = acc.bounds lowerbound(%c0 : index) upperbound(%c9 : index) extent(%c10 : index) stride(%c100000{{.*}} : index) startIdx(%c1 : index)
197+
! CHECK: %[[COPYIN:.*]] = acc.copyin varPtr({{.*}} : !fir.ref<!fir.array<1000x100x10xf32>>) bounds(%[[BOUND1]], %[[BOUND2]], %[[BOUND3]]) -> !fir.ref<!fir.array<1000x100x10xf32>> {name = "arr(:1000,:100,:10)"}
198+
! CHECK: acc.data dataOperands(%[[COPYIN]] : !fir.ref<!fir.array<1000x100x10xf32>>) {
199+
185200
end module

flang/test/Lower/OpenACC/acc-enter-data-unwrap-defaultbounds.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ subroutine acc_enter_data
2626
!CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
2727
!CHECK: %[[LB:.*]] = arith.constant 0 : index
2828
!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index
29-
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[EXTENT_C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
29+
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[EXTENT_C10]] : index) stride(%c1{{.*}} : index) startIdx(%[[ONE]] : index)
3030
!CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a", structured = false}
3131
!CHECK: acc.enter_data dataOperands(%[[CREATE_A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
3232

@@ -37,7 +37,7 @@ subroutine acc_enter_data
3737
!CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
3838
!CHECK: %[[LB:.*]] = arith.constant 0 : index
3939
!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index
40-
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[EXTENT_C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
40+
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[EXTENT_C10]] : index) stride(%c1{{.*}} : index) startIdx(%[[ONE]] : index)
4141
!CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a", structured = false}
4242
!CHECK: [[IF1:%.*]] = arith.constant true
4343
!CHECK: acc.enter_data if([[IF1]]) dataOperands(%[[CREATE_A]] : !fir.ref<!fir.array<10x10xf32>>){{$}}
@@ -49,7 +49,7 @@ subroutine acc_enter_data
4949
!CHECK: %[[BOUND0:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
5050
!CHECK: %[[LB:.*]] = arith.constant 0 : index
5151
!CHECK: %[[UB:.*]] = arith.subi %[[EXTENT_C10]], %[[ONE]] : index
52-
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[EXTENT_C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
52+
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%[[EXTENT_C10]] : index) stride(%c1{{.*}} : index) startIdx(%[[ONE]] : index)
5353
!CHECK: %[[CREATE_A:.*]] = acc.create varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND0]], %[[BOUND1]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a", structured = false}
5454
!CHECK: [[IFCOND:%.*]] = fir.load %{{.*}} : !fir.ref<!fir.logical<4>>
5555
!CHECK: [[IF2:%.*]] = fir.convert [[IFCOND]] : (!fir.logical<4>) -> i1
@@ -161,7 +161,7 @@ subroutine acc_enter_data
161161
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : index) upperbound(%[[UB1]] : index) extent(%c10{{.*}} : index) stride(%[[ONE]] : index) startIdx(%c1{{.*}} : index)
162162
!CHECK: %[[LB2:.*]] = arith.constant 0 : index
163163
!CHECK: %[[UB2:.*]] = arith.constant 4 : index
164-
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%[[ONE]] : index) startIdx(%c1{{.*}} : index)
164+
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
165165
!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a(1:,1:5)", structured = false}
166166
!CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref<!fir.array<10x10xf32>>)
167167

@@ -172,7 +172,7 @@ subroutine acc_enter_data
172172
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB1]] : index) extent(%[[C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
173173
!CHECK: %[[LB:.*]] = arith.constant 0 : index
174174
!CHECK: %[[UB2:.*]] = arith.constant 4 : index
175-
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
175+
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%c1{{.*}} : index) startIdx(%[[ONE]] : index)
176176
!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a(:10,1:5)", structured = false}
177177
!CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref<!fir.array<10x10xf32>>)
178178

@@ -182,7 +182,7 @@ subroutine acc_enter_data
182182
!CHECK: %[[UB:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index
183183
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%c10{{.*}} : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
184184
!CHECK: %[[UB:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index
185-
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%c10{{.*}} : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
185+
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%c10{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%[[ONE]] : index)
186186
!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a(:,:)", structured = false}
187187
end subroutine acc_enter_data
188188

flang/test/Lower/OpenACC/acc-enter-data.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ subroutine acc_enter_data
105105
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB1]] : index) upperbound(%[[UB1]] : index) extent(%c10{{.*}} : index) stride(%[[ONE]] : index) startIdx(%c1{{.*}} : index)
106106
!CHECK: %[[LB2:.*]] = arith.constant 0 : index
107107
!CHECK: %[[UB2:.*]] = arith.constant 4 : index
108-
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%[[ONE]] : index) startIdx(%c1{{.*}} : index)
108+
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB2]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
109109
!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a(1:,1:5)", structured = false}
110110
!CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref<!fir.array<10x10xf32>>)
111111

@@ -116,7 +116,7 @@ subroutine acc_enter_data
116116
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB1]] : index) extent(%[[C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
117117
!CHECK: %[[LB:.*]] = arith.constant 0 : index
118118
!CHECK: %[[UB2:.*]] = arith.constant 4 : index
119-
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
119+
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB2]] : index) extent(%[[EXTENT_C10]] : index) stride(%c1{{.*}} : index) startIdx(%[[ONE]] : index)
120120
!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a(:10,1:5)", structured = false}
121121
!CHECK: acc.enter_data dataOperands(%[[COPYIN_A]] : !fir.ref<!fir.array<10x10xf32>>)
122122

@@ -126,7 +126,7 @@ subroutine acc_enter_data
126126
!CHECK: %[[UB:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index
127127
!CHECK: %[[BOUND1:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%c10{{.*}} : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
128128
!CHECK: %[[UB:.*]] = arith.subi %c10{{.*}}, %[[ONE]] : index
129-
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%c10{{.*}} : index) stride(%[[ONE]] : index) startIdx(%[[ONE]] : index)
129+
!CHECK: %[[BOUND2:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) extent(%c10{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
130130
!CHECK: %[[COPYIN_A:.*]] = acc.copyin varPtr(%[[DECLA]]#0 : !fir.ref<!fir.array<10x10xf32>>) bounds(%[[BOUND1]], %[[BOUND2]]) -> !fir.ref<!fir.array<10x10xf32>> {name = "a(:,:)", structured = false}
131131
end subroutine acc_enter_data
132132

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ def OpenACC_DataBoundsOp : OpenACC_Op<"bounds",
377377
but not checked for consistency). When the source language's arrays are
378378
not zero-based, the `startIdx` must specify the zero-position index.
379379

380+
The `stride` represents the distance between consecutive elements. For
381+
multi-dimensional arrays, the `stride` for each outer dimension must account
382+
for the complete size of all inner dimensions.
383+
384+
The `strideInBytes` flag indicates that the `stride` is specified in bytes
385+
rather than the number of elements.
386+
380387
Examples below show copying a slice of 10-element array except first element.
381388
Note that the examples use extent in data clause for C++ and upperbound
382389
for Fortran (as per 2.7.1). To simplify examples, the constants are used
@@ -389,7 +396,7 @@ def OpenACC_DataBoundsOp : OpenACC_Op<"bounds",
389396
```
390397
=>
391398
```mlir
392-
acc.bounds lb(1) ub(9) extent(9) startIdx(0)
399+
acc.bounds lb(1) ub(9) extent(9) startIdx(0) stride(1)
393400
```
394401

395402
Fortran:
@@ -399,7 +406,7 @@ def OpenACC_DataBoundsOp : OpenACC_Op<"bounds",
399406
```
400407
=>
401408
```mlir
402-
acc.bounds lb(1) ub(9) extent(9) startIdx(1)
409+
acc.bounds lb(1) ub(9) extent(9) startIdx(1) stride(1)
403410
```
404411
}];
405412

0 commit comments

Comments
 (0)