[Mlir-commits] [mlir] [mlir][CAPI][python] expose the python bindings for linalg::isaContractionOpInterface and linalg::inferContractionDims (PR #134935)
Bangtian Liu
llvmlistbot at llvm.org
Wed Apr 9 12:58:36 PDT 2025
================
@@ -6,12 +6,45 @@
//
//===----------------------------------------------------------------------===//
+#include "mlir-c/BuiltinAttributes.h"
#include "mlir-c/Dialect/Linalg.h"
#include "mlir-c/IR.h"
-#include "mlir/Bindings/Python/NanobindAdaptors.h"
#include "mlir/Bindings/Python/Nanobind.h"
+#include "mlir/Bindings/Python/NanobindAdaptors.h"
namespace nb = nanobind;
+using namespace mlir::python::nanobind_adaptors;
+
+struct PyContractionDimensions {
+ MlirLinalgContractionDimensions value;
+
+ PyContractionDimensions() = default;
+ PyContractionDimensions(const MlirLinalgContractionDimensions &v)
+ : value(v) {}
+};
+
+static std::optional<PyContractionDimensions>
+mlirLinalgInferContractionDimensionsBinding(MlirOperation op) {
+ MlirLinalgContractionDimensions dims =
+ mlirLinalgInferContractionDimensions(op);
+
+ // Detect "empty" result.
+ if (mlirAttributeIsNull(dims.batch) && mlirAttributeIsNull(dims.m) &&
+ mlirAttributeIsNull(dims.n) && mlirAttributeIsNull(dims.k)) {
+ return std::nullopt;
----------------
bangtianliu wrote:
This case happens when the op is not contraction. Yes, it is covered by testing `linalg.fill` in the test.
https://github.com/llvm/llvm-project/pull/134935
More information about the Mlir-commits
mailing list