[Mlir-commits] [mlir] [mlir][linalg] Add maps-based inferConvolutionDims overload (PR #203323)

Federico Bruzzone llvmlistbot at llvm.org
Fri Jun 12 00:57:11 PDT 2026


================

----------------
FedericoBruzzone wrote:

This section of code provides an opportunity for healthy code reuse, which extends to the rest of the file as well :D
I'll try to explain what I mean.

We could create two new static helpers (`toContractionDimensions` and `toConvolutionDimensions`) which incapsulate the conversion `ConvolutionDimensions/ContractionDimensions`.

Something like:
```cpp
static MlirLinalgContractionDimensions toContractionDimensions(MLIRContext *ctx,
                        const linalg::ContractionDimensions &dims) {
  auto toAttr = [ctx](ArrayRef<unsigned> vals) -> MlirAttribute {
    return wrap(DenseI32ArrayAttr::get(ctx, llvm::to_vector_of<int32_t>(vals)));
  };
  return {toAttr(dims.batch), toAttr(dims.m), toAttr(dims.n), toAttr(dims.k)};
}
```
and
```cpp
static MlirLinalgConvolutionDimensions toConvolutionDimensions(MLIRContext *ctx,
                        const linalg::ConvolutionDimensions &dims) {
  auto toI32 = [ctx](const SmallVector<unsigned, 2> &v) -> MlirAttribute {
    return wrap(DenseI32ArrayAttr::get(ctx, llvm::to_vector_of<int32_t>(v)));
  };
  auto toI64 = [ctx](const SmallVector<int64_t, 2> &v) -> MlirAttribute {
    return wrap(DenseI64ArrayAttr::get(ctx, v));
  };
  return {toI32(dims.batch),       toI32(dims.outputImage),
          toI32(dims.outputChannel), toI32(dims.filterLoop),
          toI32(dims.inputChannel),  toI32(dims.depth),
          toI64(dims.strides),       toI64(dims.dilations)};
}
```

And reuse them in: `mlirLinalgInferContractionDimensions`, `mlirLinalgInferContractionDimensionsFromMaps`, `mlirLinalgInferConvolutionDimensions`, and your new `mlirLinalgInferConvolutionDimensionsFromMaps`.



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


More information about the Mlir-commits mailing list