[Mlir-commits] [mlir] [mlir][linalg] Propagate filter tensor encoding in im2col (PR #160099)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Sep 24 12:18:25 PDT 2025


================
@@ -124,6 +125,10 @@ rewriteInIm2Col(RewriterBase &rewriter, linalg::Conv2DNhwcHwcfOp convOp) {
   auto filterType = cast<ShapedType>(convOp.getInputs()[1].getType());
   auto outputType = cast<ShapedType>(convOp.getOutputs()[0].getType());
 
+  if (!convOp.hasPureTensorSemantics())
+    return rewriter.notifyMatchFailure(
+        convOp, "expected op to have pure tensor semantics");
+
----------------
fabrizio-indirli wrote:

Yes, the current implementation doesn't work on Memrefs: the transformation creates ops from the Tensor dialect (e.g. [`tensor::CollapseShape` on the filter](https://github.com/llvm/llvm-project/blob/6e904e89cb97fa113c95f746942e04226a7d2207/mlir/lib/Dialect/Linalg/Transforms/ConvertConv2DToImg2Col.cpp#L162)  and [on the output tensor](https://github.com/llvm/llvm-project/blob/6e904e89cb97fa113c95f746942e04226a7d2207/mlir/lib/Dialect/Linalg/Transforms/ConvertConv2DToImg2Col.cpp#L168), and [`tensor::Empty` to initialize the intermediate output](https://github.com/llvm/llvm-project/blob/6e904e89cb97fa113c95f746942e04226a7d2207/mlir/lib/Dialect/Linalg/Transforms/ConvertConv2DToImg2Col.cpp#L172). These ops from the Tensor dialect are not compatible with MemRefs. 
Moreover, the linalg::generic ops created by this transform return a result, [thus the result type is specified when they are built](https://github.com/llvm/llvm-project/blob/6e904e89cb97fa113c95f746942e04226a7d2207/mlir/lib/Dialect/Linalg/Transforms/ConvertConv2DToImg2Col.cpp#L207) (this cannot work with Memref semantics, where linalg ops don't return results).
Finally, I cannot see any test case with Memrefs

https://github.com/llvm/llvm-project/pull/160099


More information about the Mlir-commits mailing list