Closed chhzh123 closed 2 years ago
It seems the issue is caused by unrealized_conversion_cast
op generated in an intermediate pass:
#set = affine_set<(d0) : (d0 - 2 >= 0)>
module {
func @top(%arg0: memref<4x6x8x8x!hcl.Fixed<24, 12>>, %arg1: memref<16x6x3x3x!hcl.Fixed<24, 12>>) -> memref<4x16x6x6x!hcl.Fixed<24, 12>> attributes {itypes = "__", otypes = "_"} {
%0 = memref.alloc() {name = "B"} : memref<4x16x6x6x!hcl.Fixed<24, 12>>
%1 = memref.alloc() {name = "B_reuse_2"} : memref<6x3x8x!hcl.Fixed<24, 12>>
%2 = memref.alloc() {name = "B_reuse_3"} : memref<6x3x3x!hcl.Fixed<24, 12>>
affine.for %arg2 = 0 to 4 {
affine.for %arg3 = 0 to 16 {
affine.for %arg4 = 0 to 8 {
affine.for %arg5 = 0 to 8 {
affine.for %arg6 = 0 to 6 {
%3 = affine.load %1[%arg6, 1, %arg5] : memref<6x3x8x!hcl.Fixed<24, 12>>
affine.store %3, %1[%arg6, 0, %arg5] : memref<6x3x8x!hcl.Fixed<24, 12>>
%4 = affine.load %1[%arg6, 2, %arg5] : memref<6x3x8x!hcl.Fixed<24, 12>>
affine.store %4, %1[%arg6, 1, %arg5] : memref<6x3x8x!hcl.Fixed<24, 12>>
%5 = affine.load %arg0[%arg2, %arg6, %arg4, %arg5] : memref<4x6x8x8x!hcl.Fixed<24, 12>>
affine.store %5, %1[%arg6, 2, %arg5] : memref<6x3x8x!hcl.Fixed<24, 12>>
} {spatial}
affine.if #set(%arg4) {
affine.for %arg6 = 0 to 6 {
affine.for %arg7 = 0 to 3 {
%3 = affine.load %2[%arg6, %arg7, 1] : memref<6x3x3x!hcl.Fixed<24, 12>>
affine.store %3, %2[%arg6, %arg7, 0] : memref<6x3x3x!hcl.Fixed<24, 12>>
%4 = affine.load %2[%arg6, %arg7, 2] : memref<6x3x3x!hcl.Fixed<24, 12>>
affine.store %4, %2[%arg6, %arg7, 1] : memref<6x3x3x!hcl.Fixed<24, 12>>
%5 = affine.load %1[%arg6, %arg7, %arg5] : memref<6x3x8x!hcl.Fixed<24, 12>>
affine.store %5, %2[%arg6, %arg7, 2] : memref<6x3x3x!hcl.Fixed<24, 12>>
} {spatial}
} {spatial}
affine.if #set(%arg5) {
%3 = memref.alloc() {name = "sum_rv"} : memref<1x!hcl.Fixed<24, 12>>
%c0 = arith.constant 0 : index
%c0_i32 = arith.constant 0 : i32
%4 = builtin.unrealized_conversion_cast %c0_i32 : i32 to !hcl.Fixed<24, 12> // THIS cast
affine.store %4, %3[%c0] {to = "sum_rv"} : memref<1x!hcl.Fixed<24, 12>>
affine.for %arg6 = 0 to 6 {
affine.for %arg7 = 0 to 3 {
affine.for %arg8 = 0 to 3 {
%6 = affine.load %2[%arg6, %arg7, %arg8] : memref<6x3x3x!hcl.Fixed<24, 12>>
%7 = affine.load %arg1[%arg3, %arg6, %arg7, %arg8] {from = "compute_1"} : memref<16x6x3x3x!hcl.Fixed<24, 12>>
%8 = "hcl.mul_fixed"(%6, %7) : (!hcl.Fixed<24, 12>, !hcl.Fixed<24, 12>) -> !hcl.Fixed<24, 12>
%9 = affine.load %3[%c0] {from = "sum_rv"} : memref<1x!hcl.Fixed<24, 12>>
%10 = "hcl.add_fixed"(%8, %9) : (!hcl.Fixed<24, 12>, !hcl.Fixed<24, 12>) -> !hcl.Fixed<24, 12>
affine.store %10, %3[%c0] {to = "sum_rv"} : memref<1x!hcl.Fixed<24, 12>>
} {loop_name = "rx_2", reduction}
} {loop_name = "rx_1", reduction}
} {loop_name = "rx_0", reduction}
%5 = affine.load %3[%c0] {from = "sum_rv"} : memref<1x!hcl.Fixed<24, 12>>
affine.store %5, %0[%arg2, %arg3, %arg4 - 2, %arg5 - 2] : memref<4x16x6x6x!hcl.Fixed<24, 12>>
}
}
} {loop_name = "w"}
} {loop_name = "h"}
} {loop_name = "c"}
} {loop_name = "n", stage_name = "B"}
return %0 : memref<4x16x6x6x!hcl.Fixed<24, 12>>
}
}
This unrealized conversion cast is probably generated in LoopTrasformation, it should be changed to int_to_fixed op
Also the dtype
should change to hcl.Fixed(26,20)
in order to pass the test.
See the following conv example.
Got the error.