MLIR 22.0.0git
Utils.h
Go to the documentation of this file.
1//===-- Utils.h - MLIR XeVM target utils ------------------------*- C++ -*-===//
2//
3// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This files declares XeVM target related utility classes and functions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_TARGET_LLVM_XEVM_UTILS_H
14#define MLIR_TARGET_LLVM_XEVM_UTILS_H
15
19#include "mlir/IR/Attributes.h"
21
22namespace mlir {
23namespace xevm {
24
25/// Base class for all XeVM serializations from GPU modules into binary strings.
26/// By default this class serializes into LLVM bitcode.
28public:
31
32 /// Returns the target attribute.
33 XeVMTargetAttr getTarget() const;
34
35 /// Loads the bitcode files in `librariesToLink`.
36 std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
37 loadBitcodeFiles(llvm::Module &module) override;
38
39 /// Returns the gpu module being serialized.
40 gpu::GPUModuleOp getGPUModuleOp();
41
42 /// Compiles to native code using `ocloc`.
43 std::optional<SmallVector<char, 0>> compileToBinary(const std::string &asmStr,
44 StringRef inputFormat);
45
46protected:
47 /// XeVM Target attribute.
48 XeVMTargetAttr xeTarget;
49 /// List of LLVM bitcode to link into after translation to LLVM IR.
50 /// The attributes can be StringAttr pointing to a file path, or
51 /// a Resource blob pointing to the LLVM bitcode in-memory.
53
54 /// Returns the path to the tool used for serialization.
55 std::optional<std::string> findTool(StringRef tool);
56
57 /// GPU compilation target options.
59};
60} // namespace xevm
61} // namespace mlir
62
63#endif // MLIR_TARGET_LLVM_XEVM_UTILS_H
Utility base class for transforming operations into binary objects, by default it returns the seriali...
Operation & module
Module to transform to a binary object.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
This class serves as an opaque interface for passing options to the TargetAttrInterface methods.
gpu::TargetOptions targetOptions
GPU compilation target options.
Definition Utils.h:58
XeVMTargetAttr getTarget() const
Returns the target attribute.
Definition Target.cpp:89
std::optional< SmallVector< std::unique_ptr< llvm::Module > > > loadBitcodeFiles(llvm::Module &module) override
Loads the bitcode files in librariesToLink.
Definition Target.cpp:92
std::optional< SmallVector< char, 0 > > compileToBinary(const std::string &asmStr, StringRef inputFormat)
Compiles to native code using ocloc.
Definition Target.cpp:111
SmallVector< Attribute > librariesToLink
List of LLVM bitcode to link into after translation to LLVM IR.
Definition Utils.h:52
SerializeGPUModuleBase(Operation &module, XeVMTargetAttr target, const gpu::TargetOptions &targetOptions={})
Definition Target.cpp:78
XeVMTargetAttr xeTarget
XeVM Target attribute.
Definition Utils.h:48
std::optional< std::string > findTool(StringRef tool)
Returns the path to the tool used for serialization.
Definition Target.cpp:215
gpu::GPUModuleOp getGPUModuleOp()
Returns the gpu module being serialized.
Definition Target.cpp:102
Include the generated interface declarations.