Repository navigation
Closed
Labels
codegenShared code generation infrastructure and dialectscompiler/dialectsRelating to the IREE compiler dialects (flow, hal, vm)
Description
Talked to @MaheshRavishankar , rank-reducing subtensor op can't be lowered to Flow::TensorSliceOp. Instead, it should be Flow::TensorReshapeOp.
I have a local patch to work with my issue in ASR, but I don't know if it is a proper fix. Since @MaheshRavishankar is working on related things and it's probably related to #5392. I'll leave it to him.
This is my workaround snippet, which is modified from above snippet.
Value source = subTensorOp.source();
if (subTensorOp.getSourceType().getRank() !=
subTensorOp.getType().getRank()) {
SmallVector<Value, 4> sourceDynSizes, resultDynSizes;
auto sourceType = subTensorOp.getSourceType();
for (auto i : llvm::seq<unsigned>(0, sourceType.getNumDynamicDims())) {
sourceDynSizes.push_back(rewriter.create<ConstantIndexOp>(
loc, sourceType.getDynamicDimIndex(i)));
}
auto resultType = subTensorOp.getType();
for (auto i : llvm::seq<unsigned>(0, resultType.getNumDynamicDims())) {
resultDynSizes.push_back(rewriter.create<ConstantIndexOp>(
loc, resultType.getDynamicDimIndex(i)));
}
rewriter.replaceOpWithNewOp<TensorReshapeOp>(
subTensorOp, resultType, source, sourceDynSizes, resultDynSizes);
} else {
SmallVector<Value, 4> sourceSizesVals = sizesVals;
sourceSizesVals[0] = rewriter.createOrFold<memref::DimOp>(loc, source, 0);
rewriter.replaceOpWithNewOp<TensorSliceOp>(
subTensorOp, subTensorOp.getType(), subTensorOp.source(),
sourceSizesVals, offsetVals, sizesVals, sizesVals);
}To repro:
func @dynamic_slice(%arg: tensor<2x513xi16>, %start1: tensor<i64>, %start2: tensor<i64>) -> tensor<513xi16> {
%0 = "mhlo.dynamic-slice"(%arg, %start1, %start2) {
slice_sizes = dense<[1, 513]> : tensor<2xi64>
} : (tensor<2x513xi16>, tensor<i64>, tensor<i64>) -> tensor<513xi16>
return %0 : tensor<513xi16>
}$ iree-translate --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=vulkan-spirv dynamic_slice.mlir
Metadata
Metadata
Assignees
Labels
codegenShared code generation infrastructure and dialectscompiler/dialectsRelating to the IREE compiler dialects (flow, hal, vm)
Activity
MaheshRavishankar commentedon Apr 16, 2021
I am fine with adding the reshape for now that will unblock you. I can clean it up when I have all other things plumbed through. But I am not sure I follow the logic here. Can you add some comments here.
hanhanW commentedon Apr 19, 2021
After thinking a bit more, I think I was wrong.
This is something comping from:
The prototype was wrong. I directly lowered the
subtensorop toflow.tensor.reshape. It is not a reshape op. The rank-reducing subtensor op basically issubtensor (with same rank) + reshape. With this way, I can address the issue I hit later.I think rank-reducing feature is part of subtensor op and it is the proper way to connect it to flow ops. I will send out the PR soon.
MaheshRavishankar commentedon Apr 19, 2021
Ok. Thanks. I am currently looking into a revamp of bufferization, so for now this makes sense. Let me know if you want to chat about this some more.