forked from OSchip/llvm-project
[mlir][tensor] Add a custom builder for pack op.
The `paddingValue` and `outerDimsPerm` are optional to the op; `innerTiles` can be variadic in terms of static sizes and dynamic sizes. Add a custom builder for building pack op easier. Reviewed By: mravishankar Differential Revision: https://reviews.llvm.org/D138860
This commit is contained in:
parent
fa06d4d3e2
commit
e86169f090
|
@ -1761,6 +1761,14 @@ def Tensor_PackOp : Tensor_RelayoutOp<"pack", [
|
||||||
`into` $dest attr-dict `:` type($source) `->` type($dest)
|
`into` $dest attr-dict `:` type($source) `->` type($dest)
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
let builders = [
|
||||||
|
OpBuilder<(ins "Value":$source, "Value":$dest,
|
||||||
|
"ArrayRef<int64_t>":$innerDimsPos,
|
||||||
|
"ArrayRef<OpFoldResult>":$innerTiles,
|
||||||
|
CArg<"Optional<Value>", "llvm::None">:$paddingValue,
|
||||||
|
CArg<"ArrayRef<int64_t>", "{}">:$outerDimsPerm)>
|
||||||
|
];
|
||||||
|
|
||||||
let extraClassDeclaration = commonExtraClassDeclaration # [{
|
let extraClassDeclaration = commonExtraClassDeclaration # [{
|
||||||
// Method to get the `ShapedType` of the result based on the inner tiles,
|
// Method to get the `ShapedType` of the result based on the inner tiles,
|
||||||
// position of the inner tiles (innerDimsPos) and interchange vector of
|
// position of the inner tiles (innerDimsPos) and interchange vector of
|
||||||
|
|
|
@ -3238,6 +3238,26 @@ void PackOp::getAsmResultNames(function_ref<void(Value, StringRef)> setNameFn) {
|
||||||
setNameFn(getResult(), "pack");
|
setNameFn(getResult(), "pack");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PackOp::build(OpBuilder &builder, OperationState &state, Value source,
|
||||||
|
Value dest, ArrayRef<int64_t> innerDimsPos,
|
||||||
|
ArrayRef<OpFoldResult> innerTiles,
|
||||||
|
Optional<Value> paddingValue,
|
||||||
|
ArrayRef<int64_t> outerDimsPerm) {
|
||||||
|
assert(innerDimsPos.size() == innerTiles.size() &&
|
||||||
|
"number of tile sizes specified must match the specified number of "
|
||||||
|
"original dimensions to be tiled");
|
||||||
|
SmallVector<int64_t> staticTileSizes;
|
||||||
|
SmallVector<Value> dynamicTileSizes;
|
||||||
|
dispatchIndexOpFoldResults(innerTiles, dynamicTileSizes, staticTileSizes,
|
||||||
|
ShapedType::kDynamic);
|
||||||
|
build(builder, state, dest.getType(), source, dest,
|
||||||
|
paddingValue ? paddingValue.value() : nullptr,
|
||||||
|
outerDimsPerm.empty() ? nullptr
|
||||||
|
: builder.getDenseI64ArrayAttr(outerDimsPerm),
|
||||||
|
builder.getDenseI64ArrayAttr(innerDimsPos), dynamicTileSizes,
|
||||||
|
builder.getDenseI64ArrayAttr(staticTileSizes));
|
||||||
|
}
|
||||||
|
|
||||||
LogicalResult
|
LogicalResult
|
||||||
PackOp::reifyResultShapes(OpBuilder &builder,
|
PackOp::reifyResultShapes(OpBuilder &builder,
|
||||||
ReifiedRankedShapedTypeDims &reifiedReturnShapes) {
|
ReifiedRankedShapedTypeDims &reifiedReturnShapes) {
|
||||||
|
|
Loading…
Reference in New Issue