Skip to content

Commit

Permalink
Verify subview op result has dynamic shape, when sizes are specified.
Browse files Browse the repository at this point in the history
If the sizes are specified as arguments to the subview op, then the
shape must be dynamic as well.

PiperOrigin-RevId: 281591608
  • Loading branch information
Mahesh Ravishankar authored and tensorflower-gardener committed Nov 20, 2019
1 parent 84f4bbc commit 1145ceb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 14 additions & 0 deletions mlir/lib/Dialect/StandardOps/Ops.cpp
Expand Up @@ -2663,6 +2663,20 @@ static LogicalResult verify(SubViewOp op) {
return op.emitError("invalid to specify dynamic sizes when subview result "
"type is statically shaped and viceversa");
}
if (op.getNumSizes() > 0) {
// Verify that non if the shape values of the result type are static.
if (llvm::any_of(subViewType.getShape(), [](int64_t dim) {
return dim != ShapedType::kDynamicSize;
})) {
// TODO: This is based on the assumption that number of size arguments are
// either 0, or the rank of the result type. It is possible to have more
// fine-grained verification where only particular dimensions are
// dynamic. That probably needs further changes to the shape op
// specification.
return op.emitError("expected shape of result type to be fully dynamic "
"when sizes are specified");
}
}

// Verify that if dynamic offsets are specified or base memref has dynamic
// offset or base memref has dynamic strides, then the subview offset is
Expand Down
12 changes: 11 additions & 1 deletion mlir/test/IR/invalid-ops.mlir
Expand Up @@ -848,7 +848,7 @@ func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) {
// expected-error@+1 {{expected result type to have dynamic strides}}
%1 = subview %0[%arg0, %arg1, %arg2][%arg0, %arg1, %arg2][%arg0, %arg1, %arg2]
: memref<8x16x4xf32> to
memref<?x?x4xf32, offset: ?, strides: [64, 4, 1]>
memref<?x?x?xf32, offset: ?, strides: [64, 4, 1]>
return
}

Expand Down Expand Up @@ -941,3 +941,13 @@ func @invalid_subview(%arg0 : index, %arg1 : memref<16x4xf32, offset: 0, strides
// expected-error@+1 {{expected result type to have dynamic stride along a dimension if the base memref type has dynamic stride along that dimension}}
%0 = subview %arg1[][][] : memref<16x4xf32, offset: 0, strides:[?, ?]> to memref<4x2xf32, offset:?, strides:[2, 1]>
}

// -----

func @invalid_subview(%arg0 : index, %arg1 : memref<?x8x?xf32>) {
%c0 = constant 0 : index
%c1 = constant 1 : index
// expected-error@+1 {{expected shape of result type to be fully dynamic when sizes are specified}}
%0 = subview %arg1[%c0, %c0, %c0][%c1, %arg0, %c1][%c1, %c1, %c1] : memref<?x8x?xf32> to memref<?x8x?xf32, offset:?, strides:[?, ?, ?]>
return
}

0 comments on commit 1145ceb

Please sign in to comment.