[Mlir-commits] [mlir] [MLIR][docs] Mention declarePromisedInterface in Interfaces doc (PR #88689)

Frederik Harwath llvmlistbot at llvm.org
Tue Apr 16 00:16:04 PDT 2024


https://github.com/frederik-h updated https://github.com/llvm/llvm-project/pull/88689

>From 6994d7c96b2e345e83e300d2259679ac690f3043 Mon Sep 17 00:00:00 2001
From: Frederik Harwath <fharwath at amd.com>
Date: Mon, 15 Apr 2024 09:19:33 +0200
Subject: [PATCH 1/4] [MLIR][docs] Mention declarePromisedInterface in
 Interfaces doc

---
 mlir/docs/Interfaces.md | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mlir/docs/Interfaces.md b/mlir/docs/Interfaces.md
index 536e7613e50936..4fb6f8a88bfa8d 100644
--- a/mlir/docs/Interfaces.md
+++ b/mlir/docs/Interfaces.md
@@ -299,6 +299,19 @@ owner of the dialect containing the object nor the owner of the interface are
 aware of an interface implementation, which can lead to duplicate or
 diverging implementations.
 
+Forgetting to register an external model can lead to bugs which are hard
+to track down. The `declarePromisedInterface` function can be used
+to declare that an external model implementation for an operation
+must eventually be provided.
+```
+  void MyDialect::initialize() {
+    declarePromisedInterface<SomeInterface, SomeOp>();
+     ...
+  }
+```
+Now attempting to use the interface, e.g in a cast, without a prior
+registration of the external model will lead to a runtime error.
+
 #### Dialect Fallback for OpInterface
 
 Some dialects have an open ecosystem and don't register all of the possible

>From dad1abfa1507c6d8b8243535d88e0b76f581ee6b Mon Sep 17 00:00:00 2001
From: Frederik Harwath <fharwath at amd.com>
Date: Mon, 15 Apr 2024 14:29:41 +0200
Subject: [PATCH 2/4] [MLIR][docs] Add example of error message for declared
 but unregistered interface

---
 mlir/docs/Interfaces.md | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mlir/docs/Interfaces.md b/mlir/docs/Interfaces.md
index 4fb6f8a88bfa8d..ec1ccc84685284 100644
--- a/mlir/docs/Interfaces.md
+++ b/mlir/docs/Interfaces.md
@@ -310,7 +310,11 @@ must eventually be provided.
   }
 ```
 Now attempting to use the interface, e.g in a cast, without a prior
-registration of the external model will lead to a runtime error.
+registration of the external model will lead to a runtime error that will
+look similar to this:
+```
+LLVM ERROR: checking for an interface (`SomeInterface`) that was promised by dialect 'mydialect' but never implemented. This is generally an indication that the dialect extension implementing the interface was never registered.
+```
 
 #### Dialect Fallback for OpInterface
 

>From 96ffac3e3c82b354a3c3af175734944a8fb493d0 Mon Sep 17 00:00:00 2001
From: Frederik Harwath <fharwath at amd.com>
Date: Mon, 15 Apr 2024 19:48:06 +0200
Subject: [PATCH 3/4] Trigger CI


>From a39468a8d08b0488d2e6bb405d5617ad19f23f59 Mon Sep 17 00:00:00 2001
From: Frederik Harwath <frederik at harwath.name>
Date: Tue, 16 Apr 2024 09:15:56 +0200
Subject: [PATCH 4/4] Update mlir/docs/Interfaces.md

Co-authored-by: Mehdi Amini <joker.eph at gmail.com>
---
 mlir/docs/Interfaces.md | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mlir/docs/Interfaces.md b/mlir/docs/Interfaces.md
index ec1ccc84685284..cd260674c1981e 100644
--- a/mlir/docs/Interfaces.md
+++ b/mlir/docs/Interfaces.md
@@ -314,7 +314,8 @@ registration of the external model will lead to a runtime error that will
 look similar to this:
 ```
 LLVM ERROR: checking for an interface (`SomeInterface`) that was promised by dialect 'mydialect' but never implemented. This is generally an indication that the dialect extension implementing the interface was never registered.
-```
+
+If you encounter this error for a dialect and an interface provided by MLIR, you may look for a method that will be named like `register<Dialect><Interface>ExternalModels(DialectRegistry &registry);` ; try to find it with `git grep 'register.*SomeInterface.*Model' mlir`. 
 
 #### Dialect Fallback for OpInterface
 



More information about the Mlir-commits mailing list