Skip to content

Commit f1efac7

Browse files
akshaybaviskarbondhugula
authored andcommitted
Add verifier for gpu.alloc op
Add verifier for gpu.alloc op to verify if the dimension operand counts and symbol operand counts are same as their memref counterparts. Differential Revision: https://reviews.llvm.org/D117427
1 parent 695c341 commit f1efac7

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

mlir/include/mlir/Dialect/GPU/GPUOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ def GPU_AllocOp : GPU_Op<"alloc", [
901901
`(` $dynamicSizes `)` (`` `[` $symbolOperands^ `]`)? attr-dict `:` type($memref)
902902
}];
903903

904+
let verifier = [{ return ::verify(*this); }];
904905
let hasCanonicalizer = 1;
905906
}
906907

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,25 @@ LogicalResult MemsetOp::fold(ArrayRef<Attribute> operands,
11731173
//===----------------------------------------------------------------------===//
11741174
// GPU_AllocOp
11751175
//===----------------------------------------------------------------------===//
1176+
1177+
static LogicalResult verify(AllocOp op) {
1178+
auto memRefType = op.memref().getType().cast<MemRefType>();
1179+
1180+
if (static_cast<int64_t>(op.dynamicSizes().size()) !=
1181+
memRefType.getNumDynamicDims())
1182+
return op.emitOpError("dimension operand count does not equal memref "
1183+
"dynamic dimension count");
1184+
1185+
unsigned numSymbols = 0;
1186+
if (!memRefType.getLayout().isIdentity())
1187+
numSymbols = memRefType.getLayout().getAffineMap().getNumSymbols();
1188+
if (op.symbolOperands().size() != numSymbols)
1189+
return op.emitOpError("symbol operand count does not equal memref symbol "
1190+
"count");
1191+
1192+
return success();
1193+
}
1194+
11761195
namespace {
11771196

11781197
/// Folding of memref.dim(gpu.alloc(%size), %idx) -> %size similar to

mlir/test/Dialect/GPU/invalid.mlir

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,4 +610,43 @@ func @async_cp_num_dst_stride(
610610
gpu.device_async_copy %src[%i, %i], %dst[%i, %i], 16 :
611611
memref<200x100xf32> to memref<200x100xf32, affine_map<(d0, d1) -> (200*d0 + 2*d1)>, 3>
612612
return
613-
}
613+
}
614+
615+
// -----
616+
617+
// Number of symbol operand count less than memref symbol count.
618+
func @alloc() {
619+
// expected-error@+1 {{symbol operand count does not equal memref symbol count}}
620+
%1 = gpu.alloc() : memref<2x4xf32, affine_map<(d0, d1)[s0] -> ((d0 + s0), d1)>, 1>
621+
return
622+
}
623+
624+
// -----
625+
626+
// Number of symbol operand count greater than memref symbol count.
627+
func @alloc() {
628+
%0 = arith.constant 7 : index
629+
// expected-error@+1 {{symbol operand count does not equal memref symbol count}}
630+
%1 = gpu.alloc()[%0] : memref<2x4xf32, 1>
631+
return
632+
}
633+
634+
// -----
635+
636+
// Number of dynamic dimension operand count greater than memref dynamic dimension count.
637+
func @alloc() {
638+
%0 = arith.constant 7 : index
639+
// expected-error@+1 {{dimension operand count does not equal memref dynamic dimension count}}
640+
%1 = gpu.alloc(%0, %0) : memref<2x?xf32, 1>
641+
return
642+
}
643+
644+
// -----
645+
646+
// Number of dynamic dimension operand count less than memref dynamic dimension count.
647+
func @alloc() {
648+
%0 = arith.constant 7 : index
649+
// expected-error@+1 {{dimension operand count does not equal memref dynamic dimension count}}
650+
%1 = gpu.alloc(%0) : memref<2x?x?xf32, 1>
651+
return
652+
}

0 commit comments

Comments
 (0)