MLIR 23.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` (API or tool).
43 FailureOr<SmallVector<char, 0>> compileToBinary(StringRef 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 /// Compiles to native code using the `ocloc` command-line tool, communicating
58 /// through temporary files.
59 FailureOr<SmallVector<char, 0>>
60 compileToBinaryViaOclocTool(StringRef asmStr, StringRef inputFormat);
61
62 /// Compiles to native code using the `ocloc` shared library API, in-process,
63 /// without temporary files. Only available when the library is linked in.
64#if MLIR_XEVM_OCLOC_LIB_AVAILABLE
65 FailureOr<SmallVector<char, 0>>
66 compileToBinaryViaLibocloc(StringRef asmStr, StringRef inputFormat);
67#endif // MLIR_XEVM_OCLOC_LIB_AVAILABLE
68
69 /// GPU compilation target options.
71};
72} // namespace xevm
73} // namespace mlir
74
75#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
Compiles to native code using the ocloc shared library API, in-process, without temporary files.
Definition Utils.h:70
XeVMTargetAttr getTarget() const
Returns the target attribute.
Definition Target.cpp:178
FailureOr< SmallVector< char, 0 > > compileToBinary(StringRef asmStr, StringRef inputFormat)
Compiles to native code using ocloc (API or tool).
Definition Target.cpp:394
FailureOr< SmallVector< char, 0 > > compileToBinaryViaOclocTool(StringRef asmStr, StringRef inputFormat)
Compiles to native code using the ocloc command-line tool, communicating through temporary files.
Definition Target.cpp:287
std::optional< SmallVector< std::unique_ptr< llvm::Module > > > loadBitcodeFiles(llvm::Module &module) override
Loads the bitcode files in librariesToLink.
Definition Target.cpp:181
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:167
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:403
gpu::GPUModuleOp getGPUModuleOp()
Returns the gpu module being serialized.
Definition Target.cpp:191
Include the generated interface declarations.