Loading mlir/docs/ShapeInference.md +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ exceptional case. Shape inference is currently tested alongside type inference by `TestReturnTypeDriver` in the test dialect. This driver performs two checks: 1. Verification that the return types specified matches the infered types. This 1. Verification that the return types specified matches the inferred types. This explicit check will be removed and made part of Op verification instead. 2. Test the creation of Ops without specifying the return type explicitly in function `testCreateFunctions` by creating new binary Ops (Op classes Loading mlir/include/mlir/Analysis/InferTypeOpInterface.h +4 −4 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ LogicalResult inferReturnTensorTypes( componentTypeFn, MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes); SmallVectorImpl<Type> &inferredReturnTypes); /// Verifies that the inferred result types match the actual result types for /// the op. Precondition: op implements InferTypeOpInterface. Loading @@ -98,7 +98,7 @@ LogicalResult verifyInferredResultTypes(Operation *op); namespace OpTrait { /// Tensor type inference trait that constructs a tensor from the infered /// Tensor type inference trait that constructs a tensor from the inferred /// shape and elemental types. /// Requires: Op implements functions of InferShapedTypeOpInterface. template <typename ConcreteType> Loading @@ -108,10 +108,10 @@ public: inferReturnTypes(MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes) { SmallVectorImpl<Type> &inferredReturnTypes) { return ::mlir::detail::inferReturnTensorTypes( ConcreteType::inferReturnTypeComponents, context, location, operands, attributes, regions, inferedReturnTypes); attributes, regions, inferredReturnTypes); } }; Loading mlir/include/mlir/Analysis/InferTypeOpInterface.td +2 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { "ValueRange":$operands, "ArrayRef<NamedAttribute>":$attributes, "RegionRange":$regions, "SmallVectorImpl<Type>&":$inferedReturnTypes) "SmallVectorImpl<Type>&":$inferredReturnTypes) >, StaticInterfaceMethod< /*desc=*/"Returns whether two array of types are compatible result types" Loading Loading @@ -95,7 +95,7 @@ def InferShapedTypeOpInterface : OpInterface<"InferShapedTypeOpInterface"> { "ArrayRef<NamedAttribute>":$attributes, "RegionRange":$regions, "SmallVectorImpl<ShapedTypeComponents>&": $inferedReturnShapes) $inferredReturnShapes) >, InterfaceMethod< /*desc=*/[{Reify the shape computation for the operation. Loading mlir/lib/Analysis/InferTypeOpInterface.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ LogicalResult mlir::detail::inferReturnTensorTypes( componentTypeFn, MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes) { SmallVectorImpl<Type> &inferredReturnTypes) { SmallVector<ShapedTypeComponents, 2> retComponents; if (failed(componentTypeFn(context, location, operands, attributes, regions, retComponents))) Loading @@ -37,23 +37,23 @@ LogicalResult mlir::detail::inferReturnTensorTypes( for (auto shapeAndType : retComponents) { assert(shapeAndType.getAttribute() == nullptr && "attribute not supported"); if (shapeAndType.hasRank()) inferedReturnTypes.push_back(RankedTensorType::get( inferredReturnTypes.push_back(RankedTensorType::get( shapeAndType.getDims(), shapeAndType.getElementType())); else inferedReturnTypes.push_back( inferredReturnTypes.push_back( UnrankedTensorType::get(shapeAndType.getElementType())); } return success(); } LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) { SmallVector<Type, 4> inferedReturnTypes; SmallVector<Type, 4> inferredReturnTypes; auto retTypeFn = cast<InferTypeOpInterface>(op); if (failed(retTypeFn.inferReturnTypes(op->getContext(), op->getLoc(), op->getOperands(), op->getAttrs(), op->getRegions(), inferedReturnTypes))) op->getRegions(), inferredReturnTypes))) return failure(); if (!retTypeFn.isCompatibleReturnTypes(inferedReturnTypes, if (!retTypeFn.isCompatibleReturnTypes(inferredReturnTypes, op->getResultTypes())) return op->emitOpError( "inferred type incompatible with return type of operation"); Loading mlir/test/lib/TestDialect/TestDialect.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -300,20 +300,20 @@ LogicalResult TestOpWithVariadicResultsAndFolder::fold( LogicalResult mlir::OpWithInferTypeInterfaceOp::inferReturnTypes( MLIRContext *, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes) { SmallVectorImpl<Type> &inferredReturnTypes) { if (operands[0].getType() != operands[1].getType()) { return emitOptionalError(location, "operand type mismatch ", operands[0].getType(), " vs ", operands[1].getType()); } inferedReturnTypes.assign({operands[0].getType()}); inferredReturnTypes.assign({operands[0].getType()}); return success(); } LogicalResult OpWithShapedTypeInferTypeInterfaceOp::inferReturnTypeComponents( MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<ShapedTypeComponents> &inferedReturnShapes) { SmallVectorImpl<ShapedTypeComponents> &inferredReturnShapes) { // Create return type consisting of the last element of the first operand. auto operandType = *operands.getTypes().begin(); auto sval = operandType.dyn_cast<ShapedType>(); Loading @@ -323,7 +323,7 @@ LogicalResult OpWithShapedTypeInferTypeInterfaceOp::inferReturnTypeComponents( int64_t dim = sval.hasRank() ? sval.getShape().front() : ShapedType::kDynamicSize; auto type = IntegerType::get(17, context); inferedReturnShapes.push_back(ShapedTypeComponents({dim}, type)); inferredReturnShapes.push_back(ShapedTypeComponents({dim}, type)); return success(); } Loading Loading
mlir/docs/ShapeInference.md +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ exceptional case. Shape inference is currently tested alongside type inference by `TestReturnTypeDriver` in the test dialect. This driver performs two checks: 1. Verification that the return types specified matches the infered types. This 1. Verification that the return types specified matches the inferred types. This explicit check will be removed and made part of Op verification instead. 2. Test the creation of Ops without specifying the return type explicitly in function `testCreateFunctions` by creating new binary Ops (Op classes Loading
mlir/include/mlir/Analysis/InferTypeOpInterface.h +4 −4 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ LogicalResult inferReturnTensorTypes( componentTypeFn, MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes); SmallVectorImpl<Type> &inferredReturnTypes); /// Verifies that the inferred result types match the actual result types for /// the op. Precondition: op implements InferTypeOpInterface. Loading @@ -98,7 +98,7 @@ LogicalResult verifyInferredResultTypes(Operation *op); namespace OpTrait { /// Tensor type inference trait that constructs a tensor from the infered /// Tensor type inference trait that constructs a tensor from the inferred /// shape and elemental types. /// Requires: Op implements functions of InferShapedTypeOpInterface. template <typename ConcreteType> Loading @@ -108,10 +108,10 @@ public: inferReturnTypes(MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes) { SmallVectorImpl<Type> &inferredReturnTypes) { return ::mlir::detail::inferReturnTensorTypes( ConcreteType::inferReturnTypeComponents, context, location, operands, attributes, regions, inferedReturnTypes); attributes, regions, inferredReturnTypes); } }; Loading
mlir/include/mlir/Analysis/InferTypeOpInterface.td +2 −2 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { "ValueRange":$operands, "ArrayRef<NamedAttribute>":$attributes, "RegionRange":$regions, "SmallVectorImpl<Type>&":$inferedReturnTypes) "SmallVectorImpl<Type>&":$inferredReturnTypes) >, StaticInterfaceMethod< /*desc=*/"Returns whether two array of types are compatible result types" Loading Loading @@ -95,7 +95,7 @@ def InferShapedTypeOpInterface : OpInterface<"InferShapedTypeOpInterface"> { "ArrayRef<NamedAttribute>":$attributes, "RegionRange":$regions, "SmallVectorImpl<ShapedTypeComponents>&": $inferedReturnShapes) $inferredReturnShapes) >, InterfaceMethod< /*desc=*/[{Reify the shape computation for the operation. Loading
mlir/lib/Analysis/InferTypeOpInterface.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ LogicalResult mlir::detail::inferReturnTensorTypes( componentTypeFn, MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes) { SmallVectorImpl<Type> &inferredReturnTypes) { SmallVector<ShapedTypeComponents, 2> retComponents; if (failed(componentTypeFn(context, location, operands, attributes, regions, retComponents))) Loading @@ -37,23 +37,23 @@ LogicalResult mlir::detail::inferReturnTensorTypes( for (auto shapeAndType : retComponents) { assert(shapeAndType.getAttribute() == nullptr && "attribute not supported"); if (shapeAndType.hasRank()) inferedReturnTypes.push_back(RankedTensorType::get( inferredReturnTypes.push_back(RankedTensorType::get( shapeAndType.getDims(), shapeAndType.getElementType())); else inferedReturnTypes.push_back( inferredReturnTypes.push_back( UnrankedTensorType::get(shapeAndType.getElementType())); } return success(); } LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) { SmallVector<Type, 4> inferedReturnTypes; SmallVector<Type, 4> inferredReturnTypes; auto retTypeFn = cast<InferTypeOpInterface>(op); if (failed(retTypeFn.inferReturnTypes(op->getContext(), op->getLoc(), op->getOperands(), op->getAttrs(), op->getRegions(), inferedReturnTypes))) op->getRegions(), inferredReturnTypes))) return failure(); if (!retTypeFn.isCompatibleReturnTypes(inferedReturnTypes, if (!retTypeFn.isCompatibleReturnTypes(inferredReturnTypes, op->getResultTypes())) return op->emitOpError( "inferred type incompatible with return type of operation"); Loading
mlir/test/lib/TestDialect/TestDialect.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -300,20 +300,20 @@ LogicalResult TestOpWithVariadicResultsAndFolder::fold( LogicalResult mlir::OpWithInferTypeInterfaceOp::inferReturnTypes( MLIRContext *, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<Type> &inferedReturnTypes) { SmallVectorImpl<Type> &inferredReturnTypes) { if (operands[0].getType() != operands[1].getType()) { return emitOptionalError(location, "operand type mismatch ", operands[0].getType(), " vs ", operands[1].getType()); } inferedReturnTypes.assign({operands[0].getType()}); inferredReturnTypes.assign({operands[0].getType()}); return success(); } LogicalResult OpWithShapedTypeInferTypeInterfaceOp::inferReturnTypeComponents( MLIRContext *context, Optional<Location> location, ValueRange operands, ArrayRef<NamedAttribute> attributes, RegionRange regions, SmallVectorImpl<ShapedTypeComponents> &inferedReturnShapes) { SmallVectorImpl<ShapedTypeComponents> &inferredReturnShapes) { // Create return type consisting of the last element of the first operand. auto operandType = *operands.getTypes().begin(); auto sval = operandType.dyn_cast<ShapedType>(); Loading @@ -323,7 +323,7 @@ LogicalResult OpWithShapedTypeInferTypeInterfaceOp::inferReturnTypeComponents( int64_t dim = sval.hasRank() ? sval.getShape().front() : ShapedType::kDynamicSize; auto type = IntegerType::get(17, context); inferedReturnShapes.push_back(ShapedTypeComponents({dim}, type)); inferredReturnShapes.push_back(ShapedTypeComponents({dim}, type)); return success(); } Loading