[Mlir-commits] [mlir] Reimplementing target description concept using DLTI attribute (PR #92138)

Niranjan Hasabnis llvmlistbot at llvm.org
Tue Jun 18 18:25:23 PDT 2024


================
@@ -744,6 +821,56 @@ LogicalResult mlir::detail::verifyDataLayoutSpec(DataLayoutSpecInterface spec,
   return success();
 }
 
+LogicalResult
+mlir::detail::verifyTargetSystemSpec(TargetSystemSpecInterface spec,
+                                     Location loc) {
+  DenseMap<StringAttr, DataLayoutEntryInterface> device_desc_keys;
+  DenseSet<TargetSystemSpecInterface::DeviceID> device_ids;
+  for (const auto &entry : spec.getEntries()) {
+    TargetDeviceSpecInterface tdd_spec = entry.second;
+    // First, verify individual target device desc specs.
+    if (failed(tdd_spec.verifyEntry(loc)))
+      return failure();
+
+    // Check that device IDs are unique across all entries.
+    TargetSystemSpecInterface::DeviceID device_id = entry.first;
+    if (!device_ids.insert(device_id).second) {
+      return failure();
+    }
+
+    // collect all the keys used by all the tdd_specs.
+    for (DataLayoutEntryInterface entry : tdd_spec.getEntries()) {
+      if (auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
+        // tdd_spec does not support Type as a key.
+        return failure();
+      } else {
+        device_desc_keys[entry.getKey().get<StringAttr>()] = entry;
+      }
+    }
+  }
+
+  for (const auto &kvp : device_desc_keys) {
+    StringAttr identifier = kvp.second.getKey().get<StringAttr>();
+    Dialect *dialect = identifier.getReferencedDialect();
+
+    // Ignore attributes that belong to an unknown dialect, the dialect may
+    // actually implement the relevant interface but we don't know about that.
+    if (!dialect)
+      continue;
----------------
nhasabni wrote:

I was following the logic from earlier parts of DLTI. I've fixed it though.

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


More information about the Mlir-commits mailing list