Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct OpenACCMappableModel
getOffsetInBytes(mlir::Type type, mlir::Value var, mlir::ValueRange accBounds,
const mlir::DataLayout &dataLayout) const;

bool hasUnknownDimensions(mlir::Type type) const;

llvm::SmallVector<mlir::Value>
generateAccBounds(mlir::Type type, mlir::Value var,
mlir::OpBuilder &builder) const;
Expand Down
22 changes: 22 additions & 0 deletions flang/lib/Optimizer/OpenACC/Support/FIROpenACCTypeInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ OpenACCMappableModel<fir::PointerType>::getOffsetInBytes(
mlir::Type type, mlir::Value var, mlir::ValueRange accBounds,
const mlir::DataLayout &dataLayout) const;

template <typename Ty>
bool OpenACCMappableModel<Ty>::hasUnknownDimensions(mlir::Type type) const {
assert(fir::isa_ref_type(type) && "expected FIR reference type");
return fir::hasDynamicSize(fir::unwrapRefType(type));
}

template bool OpenACCMappableModel<fir::ReferenceType>::hasUnknownDimensions(
mlir::Type type) const;

template bool OpenACCMappableModel<fir::HeapType>::hasUnknownDimensions(
mlir::Type type) const;

template bool OpenACCMappableModel<fir::PointerType>::hasUnknownDimensions(
mlir::Type type) const;

template <>
bool OpenACCMappableModel<fir::BaseBoxType>::hasUnknownDimensions(
mlir::Type type) const {
// Descriptor-based entities have dimensions encoded.
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes fir.box are created for assumed-size arrays.
In such case, you can get SSA values from the box, but the last value will be -1 at runtime.

Is this is case that should return true here, or do you just care about being able to get SSA values for the shape?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment Jean!

I actually do want to exclude this case from the logic of hasUnknownDimensions because I only want to handle scenarios where codegen cannot generate a runtime data mapping call due to lack of information of the dimensions to this data. For the boxed assumed-size arrays, we don't need to encode any information since it is all in the descriptor - so this is not a codegen issue. It is simply a runtime issue where a runtime would report to the user they need explicit bounds if it sees an extent of -1.

I do want to point out that often times in practice with OpenACC, assumed-size arrays are used after data is already mapped - in which case even an extent of -1 is not a problem because we will first do a present check and we don't need dimensions once data is already present.

Hopefully this clarifies your question and thank you for your feedback! I appreciate that you are thinking about the type coverage! :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, thanks for the detailed answer @razvanlupusoru !

}

static llvm::SmallVector<mlir::Value>
generateSeqTyAccBounds(fir::SequenceType seqType, mlir::Value var,
mlir::OpBuilder &builder) {
Expand Down
5 changes: 5 additions & 0 deletions flang/test/Fir/OpenACC/openacc-mappable.fir
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<f16 = dense<16> : vector<2xi64>,
// CHECK: Mappable: !fir.box<!fir.array<10xf32>>
// CHECK: Type category: array
// CHECK: Size: 40
// CHECK: Has unknown dimensions: false

// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<10xf32>>) -> !fir.ref<!fir.array<10xf32>> {name = "arr", structured = false}
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<10xf32>>
// CHECK: Type category: array
// CHECK: Size: 40
// CHECK: Has unknown dimensions: false

// This second test exercises argument of explicit-shape arrays in following forms:
// `real :: arr1(nn), arr2(2:nn), arr3(10)`
Expand Down Expand Up @@ -62,6 +64,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<f16 = dense<16> : vector<2xi64>,
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> {name = "arr1", structured = false}
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<?xf32>>
// CHECK: Type category: array
// CHECK: Has unknown dimensions: true
// CHECK: Shape: %{{.*}} = fir.shape %[[EXTENT1:.*]] : (index) -> !fir.shape<1>
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB1:.*]] : index) upperbound(%[[UB1:.*]] : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
// CHECK: Lower bound: %[[LB1]] = arith.constant 0 : index
Expand All @@ -70,6 +73,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<f16 = dense<16> : vector<2xi64>,
// CHECK: Visiting: %{{.*}} = acc.copyin varPtr(%{{.*}} : !fir.ref<!fir.array<?xf32>>) -> !fir.ref<!fir.array<?xf32>> {name = "arr2", structured = false}
// CHECK: Pointer-like and Mappable: !fir.ref<!fir.array<?xf32>>
// CHECK: Type category: array
// CHECK: Has unknown dimensions: true
// CHECK: Shape: %{{.*}} = fir.shape_shift %c2{{.*}}, %[[EXTENT2:.*]] : (index, index) -> !fir.shapeshift<1>
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB2:.*]] : index) upperbound(%[[UB2:.*]] : index) extent(%{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c2{{.*}} : index)
// CHECK: Lower bound: %[[LB2]] = arith.constant 0 : index
Expand All @@ -80,6 +84,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<f16 = dense<16> : vector<2xi64>,
// CHECK: Type category: array
// CHECK: Size: 40
// CHECK: Offset: 0
// CHECK: Has unknown dimensions: false
// CHECK: Shape: %{{.*}} = fir.shape %[[EXTENT3:.*]] : (index) -> !fir.shape<1>
// CHECK: Bound[0]: %{{.*}} = acc.bounds lowerbound(%[[LB3:.*]] : index) upperbound(%[[UB3:.*]] : index) extent(%c10{{.*}} : index) stride(%c1{{.*}} : index) startIdx(%c1{{.*}} : index)
// CHECK: Lower bound: %[[LB3]] = arith.constant 0 : index
Expand Down
4 changes: 4 additions & 0 deletions flang/test/lib/OpenACC/TestOpenACCInterfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ struct TestFIROpenACCInterfaces
}
}

llvm::errs() << "\t\tHas unknown dimensions: "
<< (mappableTy.hasUnknownDimensions() ? "true" : "false")
<< "\n";

if (auto declareOp =
dyn_cast_if_present<hlfir::DeclareOp>(var.getDefiningOp())) {
llvm::errs() << "\t\tShape: " << declareOp.getShape() << "\n";
Expand Down
12 changes: 12 additions & 0 deletions mlir/include/mlir/Dialect/OpenACC/OpenACCTypeInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ def OpenACC_MappableTypeInterface : TypeInterface<"MappableType"> {
return {};
}]
>,
InterfaceMethod<
/*description=*/[{
Returns true if the dimensions of this type are not known. This occurs
when the MLIR type does not encode dimensional information and there is
no associated descriptor or metadata in the current entity that would
make this information extractable. For example, an opaque pointer type
pointing to an array without dimension information would have unknown
dimensions.
}],
/*retTy=*/"bool",
/*methodName=*/"hasUnknownDimensions"
>,
InterfaceMethod<
/*description=*/[{
Returns explicit `acc.bounds` operations that envelop the whole
Expand Down
4 changes: 3 additions & 1 deletion mlir/unittests/Dialect/OpenACC/OpenACCOpsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,9 @@ void testShortDataEntryOpBuildersMappableVar(OpBuilder &b, MLIRContext &context,

struct IntegerOpenACCMappableModel
: public mlir::acc::MappableType::ExternalModel<IntegerOpenACCMappableModel,
IntegerType> {};
IntegerType> {
bool hasUnknownDimensions(mlir::Type type) const { return false; }
};

TEST_F(OpenACCOpsTest, mappableTypeBuilderDataEntry) {
// First, set up the test by attaching MappableInterface to IntegerType.
Expand Down