[Mlir-commits] [mlir] [DRAFT] Generalize expand_shape to take shape as explicit input (PR #69267)

James Newling llvmlistbot at llvm.org
Mon Nov 13 09:29:56 PST 2023


================
@@ -230,24 +309,17 @@ LogicalResult mlir::reshapeLikeShapesAreCompatible(
     ArrayRef<ReassociationIndices> reassociationMaps, bool isExpandingReshape) {
   unsigned expandedDimStart = 0;
   for (const auto &map : llvm::enumerate(reassociationMaps)) {
-    std::optional<int64_t> dynamicShape;
+    bool foundDynamicShape = false;
     int64_t linearizedStaticShape = 1;
+
     for (const auto &dim : llvm::enumerate(
              expandedShape.slice(expandedDimStart, map.value().size()))) {
-      if (ShapedType::isDynamic(dim.value())) {
-        if (isExpandingReshape && dynamicShape) {
-          return emitError("invalid to have a single dimension (" +
-                           Twine(map.index()) +
----------------
newling wrote:

I think I understand the main idea better now.

You can have multiple dynamic dimensions in the expanded shape, but they must all be expressed in terms of existing values. Before this diff, it was possible to have a single kDynamic value per association group, which would be inferred from the other known dimension sizes. With this diff, multiple kDynamic values are allowed, as long as how they are expressed is provided in output_shape. output_shape is optional -- if the number of dynamic dimensions is still less than 1 per group, this inference function fills in the gaps.



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


More information about the Mlir-commits mailing list