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

Fabian Mora llvmlistbot at llvm.org
Tue Aug 27 12:01:45 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:

You're right, I'm touching `CompilationAttrs.td`. I'll merge that other one, create a patch with the docs and then revisit if we can change Operation* to GPUModuleOp.

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


More information about the Mlir-commits mailing list