[Mlir-commits] [mlir] [mlir][tosa] Add dialect version. (PR #79514)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Jan 25 14:25:30 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Jacques Pienaar (jpienaar)

<details>
<summary>Changes</summary>

This adds a singular number for the bytecode version. Considered adding spec related
version, but decided that against that as

1) I think one may want to capture the minimum spec to execute
   separately (and it may be function of the ops in the module);
2) Its unrelated to reading the bytecode or upgrade/downgrade. So
   linking these together felt like linking error domains.

---
Full diff: https://github.com/llvm/llvm-project/pull/79514.diff


2 Files Affected:

- (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h (+7) 
- (modified) mlir/lib/Dialect/Tosa/IR/TosaOps.cpp (+17-5) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h
index a9bc3351f4cff05..062fb28f5ebe3cb 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.h
@@ -34,6 +34,13 @@ class PatternRewriter;
 
 namespace tosa {
 
+struct TosaDialectVersion : public mlir::DialectVersion {
+  TosaDialectVersion() = default;
+  TosaDialectVersion(uint32_t dialectVersion)
+      : dialectVersion(dialectVersion){};
+  uint32_t dialectVersion = 0;
+};
+
 ParseResult parseTypeOrAttr(OpAsmParser &parser, TypeAttr &typeAttr,
                             Attribute &attr);
 void printTypeOrAttr(OpAsmPrinter &p, Operation *op, TypeAttr type,
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
index 729116da45e47dc..b4035cadce331a8 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
@@ -97,18 +97,30 @@ struct TosaDialectBytecodeInterface : public BytecodeDialectInterface {
   }
 
   void writeVersion(DialectBytecodeWriter &writer) const final {
-    // TODO: Populate.
+    // This is currently not being written currently to allow readers to update
+    // first.
+#if 0
+    // TODO: This could be refined to not just pick current version.
+    auto version = TosaDialectVersion();
+    writer.writeVarInt(version.dialectVersion);
+#endif
   }
 
   std::unique_ptr<DialectVersion>
   readVersion(DialectBytecodeReader &reader) const final {
-    // TODO: Populate
-    reader.emitError("Dialect does not support versioning");
-    return nullptr;
+    uint64_t dialectVersion;
+    if (failed(reader.readVarInt(dialectVersion)))
+      return nullptr;
+    auto version = std::make_unique<TosaDialectVersion>();
+    version->dialectVersion = dialectVersion;
+    return version;
   }
 
   LogicalResult upgradeFromVersion(Operation *topLevelOp,
-                                   const DialectVersion &version_) const final {
+                                   const DialectVersion &version) const final {
+    const auto &tosaVersion = static_cast<const TosaDialectVersion &>(version);
+    // No upgrades currently defined.
+    (void)tosaVersion;
     return success();
   }
 };

``````````

</details>


https://github.com/llvm/llvm-project/pull/79514


More information about the Mlir-commits mailing list