Skip to content

Commit 919922b

Browse files
limo1996ftynse
authored andcommitted
[mlir] Added verification check for linalg.conv to ensure memrefs are of rank > 2
linalg.conv does not support memrefs with rank smaller than 3 as stated here: https://www.tensorflow.org/versions/r2.0/api_docs/python/tf/nn/convolution However it does not verify it and thus crashes with "LLVM ERROR: out of memory" error for 1D case and "nWin > 0 && "expected at least one window dimension"" assertion for 2D case. This commit adds check for that in the verification method. Differential Revision: https://reviews.llvm.org/D84317
1 parent 722e5d6 commit 919922b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,8 @@ static LogicalResult verify(ConvOp op) {
995995
return op.emitOpError("expects memref elemental types to match");
996996
if (oType.getRank() != iType.getRank() || oType.getRank() != fType.getRank())
997997
return op.emitOpError("expects memref ranks to match");
998+
if (oType.getRank() <= 2)
999+
return op.emitOpError("expects memref ranks to be greater than 2");
9981000
if (auto strides = op.strides()) {
9991001
if (failed(
10001002
verifyStrideOrDilation(op, strides->getValue(), /*isStride=*/true)))

mlir/test/Dialect/Linalg/invalid.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@ func @generic_result_0_element_type(%arg0: memref<?xf32>) {
428428

429429
// -----
430430

431+
func @conv_rank_limit(%arg0: memref<?xf32>, %arg1: memref<?xf32>, %arg2: memref<?xf32>) {
432+
// expected-error @+1 {{expects memref ranks to be greater than 2}}
433+
linalg.conv(%arg0, %arg1, %arg2) : memref<?xf32>, memref<?xf32>, memref<?xf32>
434+
}
435+
436+
// -----
437+
431438
// expected-error @+1 {{unknown Linalg type}}
432439
!invalid_type = type !linalg.unknown
433440

0 commit comments

Comments
 (0)