Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | def Shape_FromExtentTensorOp : Shape_Op<"from_extent_tensor", [NoSideEffect]> { | ||||
}]; | }]; | ||||
let arguments = (ins 1DTensorOf<[Index]>:$input); | let arguments = (ins 1DTensorOf<[Index]>:$input); | ||||
let results = (outs Shape_ShapeType:$result); | let results = (outs Shape_ShapeType:$result); | ||||
let assemblyFormat = "$input attr-dict `:` type($input)"; | let assemblyFormat = "$input attr-dict `:` type($input)"; | ||||
} | } | ||||
def Shape_IsBroadcastableOp : Shape_Op<"is_broadcastable", [Commutative]> { | def Shape_IsBroadcastableOp : Shape_Op<"is_broadcastable", | ||||
let summary = "Determines if 2 shapes can be successfully broadcasted"; | [Commutative, InferTypeOpInterface]> { | ||||
let summary = "Determines if 2+ shapes can be successfully broadcasted"; | |||||
let description = [{ | let description = [{ | ||||
Given two input shapes or extent tensors, return a predicate specifying if | Given multiple input shapes or extent tensors, return a predicate specifying | ||||
they are broadcastable. This broadcastable follows the same logic as what | if they are broadcastable. This broadcastable follows the same logic as what | ||||
shape.broadcast documents. | shape.broadcast documents. | ||||
Concretely, shape.is_broadcastable returning true implies that | Concretely, shape.is_broadcastable returning true implies that | ||||
shape.broadcast will not give an error, and shape.cstr_broadcastable will | shape.broadcast will not give an error, and shape.cstr_broadcastable will | ||||
not result in an assertion failure. Similarly, false implies an error or | not result in an assertion failure. Similarly, false implies an error or | ||||
assertion failure. | assertion failure. | ||||
Example: | Example: | ||||
```mlir | ```mlir | ||||
%true = shape.is_broadcastable [2,2], [3,1,2] | %true = shape.is_broadcastable [2,2], [3,1,2] | ||||
%false = shape.is_broadcastable [2,2], [3,2] | %false = shape.is_broadcastable [2,2], [3,2] | ||||
``` | ``` | ||||
}]; | }]; | ||||
let arguments = (ins Shape_ShapeOrExtentTensorType:$lhs, | let arguments = (ins Variadic<Shape_ShapeOrExtentTensorType>:$shapes); | ||||
Shape_ShapeOrExtentTensorType:$rhs); | |||||
let results = (outs I1:$result); | let results = (outs I1:$result); | ||||
let assemblyFormat = "$lhs `,` $rhs attr-dict `:` type($lhs) `,` type($rhs)"; | let builders = [ | ||||
OpBuilderDAG<(ins "::mlir::Value":$lhs, "::mlir::Value":$rhs), | |||||
[{ build($_builder, $_state, ::llvm::makeArrayRef({lhs, rhs})); }]>, | |||||
]; | |||||
let extraClassDeclaration = [{ | |||||
// TODO: This should really be automatic. Figure out how to not need this defined. | |||||
frgossen: Is the error something like type not buildable? In that case you could add the missing C++ for… | |||||
Not Done ReplyInline ActionsI was just getting compile time errors right after the table-gen'ed code. It wasn't at runtime. Any pointers to code snippets would be welcomed though. I couldn't figure out what to do. tpopp: I was just getting compile time errors right after the table-gen'ed code. It wasn't at runtime. | |||||
Not Done ReplyInline ActionsI meant BuildableType in mlir/include/mlir/IR/OpBase.td. frgossen: I meant `BuildableType` in `mlir/include/mlir/IR/OpBase.td`.
The `I` type in the same file is… | |||||
static ::mlir::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, | |||||
::llvm::Optional<::mlir::Location> location, ::mlir::ValueRange operands, | |||||
::mlir::DictionaryAttr attributes, ::mlir::RegionRange regions, | |||||
::llvm::SmallVectorImpl<::mlir::Type>&inferredReturnTypes) { | |||||
inferredReturnTypes.push_back(::mlir::IntegerType::get(context, | |||||
/*width=*/1)); | |||||
return success(); | |||||
}; | |||||
}]; | |||||
let assemblyFormat = "$shapes attr-dict `:` type($shapes)"; | |||||
let verifier = [{ return ::verify(*this); }]; | |||||
This should be emitting an error if there is a failure. Otherwise, it is silent with no indication to the user what is wrong. This points to a lack of test coverage. rriddle: This should be emitting an error if there is a failure. Otherwise, it is silent with no… | |||||
} | } | ||||
def Shape_RankOp : Shape_Op<"rank", [NoSideEffect]> { | def Shape_RankOp : Shape_Op<"rank", [NoSideEffect]> { | ||||
let summary = "Gets the rank of a shape"; | let summary = "Gets the rank of a shape"; | ||||
let description = [{ | let description = [{ | ||||
Returns the rank of the shape or extent tensor, i.e. the number of extents. | Returns the rank of the shape or extent tensor, i.e. the number of extents. | ||||
}]; | }]; | ||||
▲ Show 20 Lines • Show All 462 Lines • ▼ Show 20 Lines | def Shape_AssumingYieldOp : Shape_Op<"assuming_yield", | ||||
let arguments = (ins Variadic<AnyType>:$operands); | let arguments = (ins Variadic<AnyType>:$operands); | ||||
let builders = [OpBuilderDAG<(ins), [{ /* nothing to do */ }]>]; | let builders = [OpBuilderDAG<(ins), [{ /* nothing to do */ }]>]; | ||||
let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?"; | let assemblyFormat = "attr-dict ($operands^ `:` type($operands))?"; | ||||
} | } | ||||
def Shape_CstrBroadcastableOp : Shape_Op<"cstr_broadcastable", [Commutative]> { | def Shape_CstrBroadcastableOp : Shape_Op<"cstr_broadcastable", | ||||
let summary = "Determines if 2 shapes can be successfully broadcasted"; | [Commutative, InferTypeOpInterface]> { | ||||
let summary = "Determines if 2+ shapes can be successfully broadcasted"; | |||||
let description = [{ | let description = [{ | ||||
Given two input shapes or extent tensors, return a witness specifying if | Given input shapes or extent tensors, return a witness specifying if they | ||||
they are broadcastable. This broadcastable follows the same logic as what | are broadcastable. This broadcastable follows the same logic as what | ||||
shape.broadcast documents. | shape.broadcast documents. | ||||
"cstr" operations represent runtime assertions. | "cstr" operations represent runtime assertions. | ||||
Example: | Example: | ||||
```mlir | ```mlir | ||||
%w0 = shape.cstr_broadcastable [2,2], [3,1,2] // Passing | %w0 = shape.cstr_broadcastable [2,2], [3,1,2] // Passing | ||||
%w1 = shape.cstr_broadcastable [2,2], [3,2] // Failure | %w1 = shape.cstr_broadcastable [2,2], [3,2] // Failure | ||||
``` | ``` | ||||
}]; | }]; | ||||
let arguments = (ins Shape_ShapeOrExtentTensorType:$lhs, | let arguments = (ins Variadic<Shape_ShapeOrExtentTensorType>:$shapes); | ||||
Shape_ShapeOrExtentTensorType:$rhs); | |||||
let results = (outs Shape_WitnessType:$result); | let results = (outs Shape_WitnessType:$result); | ||||
let assemblyFormat = "$lhs `,` $rhs attr-dict `:` type($lhs) `,` type($rhs)"; | let assemblyFormat = "$shapes attr-dict `:` type($shapes)"; | ||||
let builders = [ | |||||
OpBuilderDAG<(ins "::mlir::Value":$lhs, "::mlir::Value":$rhs), | |||||
[{ build($_builder, $_state, ::llvm::makeArrayRef({lhs, rhs})); }]>, | |||||
]; | |||||
let extraClassDeclaration = [{ | |||||
// TODO: This should really be automatic. Figure out how to not need this defined. | |||||
static ::mlir::LogicalResult inferReturnTypes(::mlir::MLIRContext *context, | |||||
::llvm::Optional<::mlir::Location> location, ::mlir::ValueRange operands, | |||||
::mlir::DictionaryAttr attributes, ::mlir::RegionRange regions, | |||||
::llvm::SmallVectorImpl<::mlir::Type>&inferredReturnTypes) { | |||||
inferredReturnTypes.push_back(::mlir::shape::WitnessType::get(context)); | |||||
return success(); | |||||
}; | |||||
}]; | |||||
let hasCanonicalizer = 1; | let hasCanonicalizer = 1; | ||||
let hasFolder = 1; | let hasFolder = 1; | ||||
let verifier = [{ return ::verify(*this); }]; | |||||
} | } | ||||
Same here. rriddle: Same here. | |||||
def Shape_CstrEqOp : Shape_Op<"cstr_eq", [Commutative]> { | def Shape_CstrEqOp : Shape_Op<"cstr_eq", [Commutative]> { | ||||
let summary = "Determines if all input shapes are equal"; | let summary = "Determines if all input shapes are equal"; | ||||
let description = [{ | let description = [{ | ||||
Given 1 or more input shapes, determine if all shapes are the exact same. | Given 1 or more input shapes, determine if all shapes are the exact same. | ||||
"cstr" operations represent runtime assertions. | "cstr" operations represent runtime assertions. | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |
Is the error something like type not buildable? In that case you could add the missing C++ for the type, I think.