[Mlir-commits] [mlir] [mlir][linalg] Add runtime verification for linalg ops (PR #89342)
Ryan Holt
llvmlistbot at llvm.org
Mon Apr 22 06:55:44 PDT 2024
================
@@ -0,0 +1,126 @@
+//===- RuntimeOpVerification.cpp - Op Verification ------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Linalg/Transforms/RuntimeOpVerification.h"
+
+#include "mlir/Dialect/Affine/IR/AffineOps.h"
+#include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Arith/Utils/Utils.h"
+#include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h"
+#include "mlir/Dialect/Index/IR/IndexAttrs.h"
+#include "mlir/Dialect/Index/IR/IndexDialect.h"
+#include "mlir/Dialect/Index/IR/IndexOps.h"
+#include "mlir/Dialect/Linalg/IR/Linalg.h"
+#include "mlir/Dialect/MemRef/IR/MemRef.h"
+#include "mlir/Dialect/Tensor/IR/Tensor.h"
+#include "mlir/Interfaces/RuntimeVerifiableOpInterface.h"
+
+namespace mlir {
+namespace linalg {
+namespace {
+/// Verify that the runtime sizes of the operands to linalg.generic are
+/// compatible with the runtime sizes inferred by composing the loop ranges with
+/// the generic's indexing maps. This is similar to the verifier except that
+/// here we insert IR to perform the verification at runtime.
+struct GenericOpInterface
+ : public RuntimeVerifiableOpInterface::ExternalModel<GenericOpInterface,
+ linalg::GenericOp> {
+ void generateRuntimeVerification(Operation *op, OpBuilder &builder,
+ Location loc) const {
+ auto linalgOp = llvm::cast<LinalgOp>(op);
----------------
ryan-holt-1 wrote:
I cannot attach it to `LinalgOp` but I was able to do this:
```
template <typename... OpTs>
void attachInterface(MLIRContext *ctx) {
(OpTs::template attachInterface<StructuredOpInterface<OpTs>>(*ctx), ...);
}
```
```
attachInterface<
#define GET_OP_LIST
#include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.cpp.inc"
>(ctx);
```
https://github.com/llvm/llvm-project/pull/89342
More information about the Mlir-commits
mailing list