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

Fabian Mora llvmlistbot at llvm.org
Tue Aug 27 09:14:38 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());
+}
----------------
fabianmcg wrote:

Ok, wrt docs everywhere, would you prefer a fresh patch, or can I bundle the changes into this patch https://github.com/llvm/llvm-project/pull/95292 ? (they are related)

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


More information about the Mlir-commits mailing list