Repository navigation
Closed
Labels
codegenShared code generation infrastructure and dialects
Description
Different from other cases, the subtensor would be replaced with flow.tensor.slice in this case. In this case, they won't get dispatched and tensor.extract would be remained outside dispatches.
func @dynamic_1d_slice() -> tensor<2xi32> attributes { iree.module.export } {
%input = iree.unfoldable_constant dense<[1, 2, 3, 4]> : tensor<4xi32>
%start1 = iree.unfoldable_constant dense<1> : tensor<i64>
%result = "mhlo.dynamic-slice"(%input, %start1) {
slice_sizes = dense<[2]> : tensor<1xi64>
} : (tensor<4xi32>, tensor<i64>) -> tensor<2xi32>
return %result : tensor<2xi32>
}To repro:
$ iree-translate --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=dylib-llvm-aot dynamic_slice.mlir
IR before ConvertToFlowTensorsOps:
// *** IR Dump Before ConvertToFlowTensorOps ***
func @dynamic_1d_slice() -> tensor<2xi32> attributes {iree.module.export, iree.reflection = {f = "I1!R8!B5!t6d2", fv = "1"}} {
%cst = constant dense<[1, 2, 3, 4]> : tensor<4xi32>
%cst_0 = constant dense<1> : tensor<i32>
%c0_i32 = constant 0 : i32
%c2_i32 = constant 2 : i32
%0 = iree.do_not_optimize(%cst) : tensor<4xi32>
%1 = iree.do_not_optimize(%cst_0) : tensor<i32>
%2 = tensor.extract %1[] : tensor<i32>
%3 = cmpi slt, %2, %c2_i32 : i32
%4 = select %3, %2, %c2_i32 : i32
%5 = cmpi sgt, %4, %c0_i32 : i32
%6 = select %5, %4, %c0_i32 : i32
%7 = index_cast %6 : i32 to index
%8 = subtensor %0[%7] [2] [1] : tensor<4xi32> to tensor<2xi32>
return %8 : tensor<2xi32>
}IR after ConvertToFlowTensorsOps:
// *** IR Dump Before CSE ***
func @dynamic_1d_slice() -> tensor<2xi32> attributes {iree.module.export, iree.reflection = {f = "I1!R8!B5!t6d2", fv = "1"}} {
%cst = constant dense<[1, 2, 3, 4]> : tensor<4xi32>
%cst_0 = constant dense<1> : tensor<i32>
%c0_i32 = constant 0 : i32
%c2_i32 = constant 2 : i32
%c2 = constant 2 : index
%0 = iree.do_not_optimize(%cst) : tensor<4xi32>
%1 = iree.do_not_optimize(%cst_0) : tensor<i32>
%2 = tensor.extract %1[] : tensor<i32>
%3 = cmpi slt, %2, %c2_i32 : i32
%4 = select %3, %2, %c2_i32 : i32
%5 = cmpi sgt, %4, %c0_i32 : i32
%6 = select %5, %4, %c0_i32 : i32
%7 = index_cast %6 : i32 to index
%8 = flow.tensor.slice %0[%7 for %c2] : tensor<4xi32> -> tensor<2xi32>
return %8 : tensor<2xi32>
}Metadata
Metadata
Assignees
Labels
codegenShared code generation infrastructure and dialects
Activity
MaheshRavishankar commentedon May 13, 2021
Is this on ToT?
MaheshRavishankar commentedon May 13, 2021
Making the check here https://github.com/google/iree/blob/dd2a8def906e67ec8e8c66cb58372e21ab01ec92/iree/compiler/Dialect/Flow/Transforms/ConvertToFlowTensorOps.cpp#L55
should fix the issue
hanhanW commentedon May 13, 2021
Yes, it's on ToT. I will give it a shot.
hanhanW commentedon May 13, 2021
I think this works:
side note:
I probably did it wrong, I will hit other issues like
orderedOps.size() == ops.size() && "ordering of inlined operations failed"in ASR model. Will file another issue for it later.hanhanW commentedon May 13, 2021
I'll leave it to you and work on other things.
MaheshRavishankar commentedon May 13, 2021
ok, ill take a look
Rework the lowering of subtensor/subtensor_insert to flow.dispatch.sl…
Rework the lowering of subtensor/subtensor_insert to flow.dispatch.sl…