Hey all,
I am trying to lower the following affine to LLVM
// affine.mlir :-
module attributes {tf.versions = {bad_consumers = , min_consumer = 0 : i32, producer = 1459 : i32}} {
func.func @__inference_conv2d_34(%arg0: memref<1x224x224x3xf32> {tf._user_specified_name = “input”}, %arg1: memref<5x5x3x3xf32> {tf._user_specified_name = “filters”}, %arg2: memref<1x112x112x3xf32>) attributes {tf.entry_function = {control_outputs = “”, inputs = “input,filters”, outputs = “identity_RetVal”}} {
%cst = arith.constant 0.000000e+00 : f32
%0 = bufferization.to_tensor %arg0 : memref<1x224x224x3xf32>
%alloc = memref.alloc() {alignment = 64 : i64} : memref<1x112x112x3xf32>
affine.for %arg3 = 0 to 1 {
affine.for %arg4 = 0 to 112 {
affine.for %arg5 = 0 to 112 {
affine.for %arg6 = 0 to 3 {
affine.store %cst, %alloc[%arg3, %arg4, %arg5, %arg6] : memref<1x112x112x3xf32>
}
}
}
}
%padded = tensor.pad %0 low[0, 1, 1, 0] high[0, 2, 2, 0] {
^bb0(%arg3: index, %arg4: index, %arg5: index, %arg6: index):
tensor.yield %cst : f32
} : tensor<1x224x224x3xf32> to tensor<1x227x227x3xf32>
%1 = bufferization.to_memref %padded : memref<1x227x227x3xf32>
%alloc_0 = memref.alloc() {alignment = 64 : i64} : memref<1x112x112x3xf32>
memref.copy %alloc, %alloc_0 : memref<1x112x112x3xf32> to memref<1x112x112x3xf32>
affine.for %arg3 = 0 to 1 {
affine.for %arg4 = 0 to 112 {
affine.for %arg5 = 0 to 112 {
affine.for %arg6 = 0 to 3 {
affine.for %arg7 = 0 to 5 {
affine.for %arg8 = 0 to 5 {
affine.for %arg9 = 0 to 3 {
%2 = affine.load %1[%arg3, %arg4 * 2 + %arg7, %arg5 * 2 + %arg8, %arg9] : memref<1x227x227x3xf32>
%3 = affine.load %arg1[%arg7, %arg8, %arg9, %arg6] : memref<5x5x3x3xf32>
%4 = affine.load %alloc_0[%arg3, %arg4, %arg5, %arg6] : memref<1x112x112x3xf32>
%5 = arith.mulf %2, %3 : f32
%6 = arith.addf %4, %5 : f32
affine.store %6, %alloc_0[%arg3, %arg4, %arg5, %arg6] : memref<1x112x112x3xf32>
}
}
}
}
}
}
}
memref.copy %alloc_0, %arg2 : memref<1x112x112x3xf32> to memref<1x112x112x3xf32>
return
}
}
using
mlir-opt affine.mlir --lower-affine --convert-scf-to-cf --finalize-memref-to-llvm --convert-cf-to-llvm --convert-func-to-llvm --convert-arith-to-llvm --reconcile-unrealized-casts
But I am getting the error
affine.mlir:2:36: note: see current operation: %12 = “builtin.unrealized_conversion_cast”(%11) : (!llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)>) → memref<1x224x224x3xf32>
After some debugging, I think the issue is with bufferization.to_tensor
operation. But from [MLIR] lower bufferization.to_memref to LLVM - #2 by matthias-springer the bufferization.to_tensor
need restrict attribute which is not generated when it got lowered. So how do I deal with this? I am trying to lower it to LLVM IR at the end.
Thank you.