MLIR 24.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
46 /// Returns the GPU compiler version info, or an empty string if the version
47 /// can't be determined.
48 static std::string
50
51protected:
52 /// XeVM Target attribute.
53 XeVMTargetAttr xeTarget;
54 /// List of LLVM bitcode to link into after translation to LLVM IR.
55 /// The attributes can be StringAttr pointing to a file path, or
56 /// a Resource blob pointing to the LLVM bitcode in-memory.
58
59 /// Returns the path to the tool used for serialization.
60 std::optional<std::string> findTool(StringRef tool);
61 static std::optional<std::string>
62 findTool(StringRef tool, const gpu::TargetOptions &targetOptions);
63
64 /// Compiles to native code using the `ocloc` command-line tool, communicating
65 /// through temporary files.
66 FailureOr<SmallVector<char, 0>>
67 compileToBinaryViaOclocTool(StringRef asmStr, StringRef inputFormat);
68
69 /// Compiles to native code using the `ocloc` shared library API, in-process,
70 /// without temporary files. Only defined when the library is linked in.
71 FailureOr<SmallVector<char, 0>>
72 compileToBinaryViaLibocloc(StringRef asmStr, StringRef inputFormat);
73
74 /// GPU compilation target options.
76};
77} // namespace xevm
78} // namespace mlir
79
80#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:87
This class serves as an opaque interface for passing options to the TargetAttrInterface methods.
gpu::TargetOptions targetOptions
GPU compilation target options.
Definition Utils.h:75
FailureOr< SmallVector< char, 0 > > compileToBinaryViaLibocloc(StringRef asmStr, StringRef inputFormat)
Compiles to native code using the ocloc shared library API, in-process, without temporary files.
XeVMTargetAttr getTarget() const
Returns the target attribute.
Definition Target.cpp:179
FailureOr< SmallVector< char, 0 > > compileToBinary(StringRef asmStr, StringRef inputFormat)
Compiles to native code using ocloc (API or tool).
Definition Target.cpp:395
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:288
std::optional< SmallVector< std::unique_ptr< llvm::Module > > > loadBitcodeFiles(llvm::Module &module) override
Loads the bitcode files in librariesToLink.
Definition Target.cpp:182
SmallVector< Attribute > librariesToLink
List of LLVM bitcode to link into after translation to LLVM IR.
Definition Utils.h:57
SerializeGPUModuleBase(Operation &module, XeVMTargetAttr target, const gpu::TargetOptions &targetOptions={})
Definition Target.cpp:167
XeVMTargetAttr xeTarget
XeVM Target attribute.
Definition Utils.h:53
std::optional< std::string > findTool(StringRef tool)
Returns the path to the tool used for serialization.
Definition Target.cpp:478
gpu::GPUModuleOp getGPUModuleOp()
Returns the gpu module being serialized.
Definition Target.cpp:192
static std::string getCompilerInfo(const gpu::TargetOptions &targetOptions={})
Returns the GPU compiler version info, or an empty string if the version can't be determined.
Definition Target.cpp:404
Include the generated interface declarations.