[Mlir-commits] [mlir] [mlir][gpu] Pass GPU module to `TargetAttrInterface::createObject`. (PR #94910)

Mehdi Amini llvmlistbot at llvm.org
Tue Aug 27 09:04:43 PDT 2024


================
@@ -74,3 +98,52 @@ TEST_F(MLIRTargetLLVM, SKIP_WITHOUT_NATIVE(SerializeToLLVMBitcode)) {
   // Check that it has a function named `foo`.
   ASSERT_TRUE((*llvmModule)->getFunction("foo") != nullptr);
 }
+
+std::optional<SmallVector<char, 0>>
+TargetAttrImpl::serializeToObject(Attribute attribute, Operation *module,
+                                  const gpu::TargetOptions &options) const {
+  module->setAttr("serialize_attr", UnitAttr::get(module->getContext()));
+  std::string targetTriple = llvm::sys::getProcessTriple();
+  LLVM::ModuleToObject serializer(*module, targetTriple, "", "");
+  return serializer.run();
+}
+
+Attribute
+TargetAttrImpl::createObject(Attribute attribute, Operation *module,
+                             const SmallVector<char, 0> &object,
+                             const gpu::TargetOptions &options) const {
+  return gpu::ObjectAttr::get(
+      module->getContext(), attribute, gpu::CompilationTarget::Offload,
+      StringAttr::get(module->getContext(),
+                      StringRef(object.data(), object.size())),
+      module->getAttrDictionary());
+}
----------------
joker-eph wrote:

Can you also add more documentation to the tests, out of the context of this PR it wouldn't be straightforward to understand the intent of all this I believe.

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


More information about the Mlir-commits mailing list