forked from OSchip/llvm-project
[mlir][linalg] Check the iterator types are valid.
Improve the LinalgOp verification to ensure the iterator types is known. Previously, unknown iterator types have been ignored without warning, which can lead to confusing bugs. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D120649
This commit is contained in:
parent
cbaac14734
commit
11d144c576
|
@ -573,6 +573,15 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
|
|||
<< ") to be equal to the number of output tensors ("
|
||||
<< linalgOp.getOutputTensorOperands().size() << ")";
|
||||
|
||||
// Check all iterator types are known.
|
||||
auto iteratorTypesRange =
|
||||
linalgOp.iterator_types().getAsValueRange<StringAttr>();
|
||||
for (StringRef iteratorType : iteratorTypesRange) {
|
||||
if (!llvm::is_contained(getAllIteratorTypeNames(), iteratorType))
|
||||
return op->emitOpError("unexpected iterator_type (")
|
||||
<< iteratorType << ")";
|
||||
}
|
||||
|
||||
// Before checking indexing maps, we need to make sure the attributes
|
||||
// referenced by it are valid.
|
||||
if (linalgOp.hasDynamicIndexingMaps())
|
||||
|
|
|
@ -95,6 +95,19 @@ func @generic_wrong_dim_in_map(%arg0: memref<1xi32>) {
|
|||
|
||||
// -----
|
||||
|
||||
func @generic_wrong_iterator(%arg0: memref<1xi32>) {
|
||||
// expected-error @+1 {{op unexpected iterator_type (random)}}
|
||||
linalg.generic {
|
||||
indexing_maps = [ affine_map<(i) -> (i)> ],
|
||||
iterator_types = ["random"]}
|
||||
outs(%arg0 : memref<1xi32>) {
|
||||
^bb(%i : i32):
|
||||
linalg.yield %i : i32
|
||||
}
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
func @generic_one_d_view(%arg0: memref<?xf32, affine_map<(i)[off]->(off + i)>>) {
|
||||
// expected-error @+1 {{expected operand rank (1) to match the result rank of indexing_map #0 (2)}}
|
||||
linalg.generic {
|
||||
|
|
Loading…
Reference in New Issue