|
| 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 | + |
| 16 | +#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h" |
| 17 | +#include "mlir/Dialect/LLVMIR/XeVMDialect.h" |
| 18 | +#include "mlir/IR/Attributes.h" |
| 19 | +#include "mlir/Target/LLVM/ModuleToObject.h" |
| 20 | + |
| 21 | +namespace mlir { |
| 22 | +namespace xevm { |
| 23 | + |
| 24 | +/// Base class for all XeVM serializations from GPU modules into binary strings. |
| 25 | +/// By default this class serializes into LLVM bitcode. |
| 26 | +class SerializeGPUModuleBase : public LLVM::ModuleToObject { |
| 27 | +public: |
| 28 | + SerializeGPUModuleBase(Operation &module, XeVMTargetAttr target, |
| 29 | + const gpu::TargetOptions &targetOptions = {}); |
| 30 | + |
| 31 | + /// Returns the target attribute. |
| 32 | + XeVMTargetAttr getTarget() const; |
| 33 | + |
| 34 | + /// Loads the bitcode files in `librariesToLink`. |
| 35 | + std::optional<SmallVector<std::unique_ptr<llvm::Module>>> |
| 36 | + loadBitcodeFiles(llvm::Module &module) override; |
| 37 | + |
| 38 | + /// Returns the gpu module being serialized. |
| 39 | + gpu::GPUModuleOp getGPUModuleOp(); |
| 40 | + |
| 41 | + /// Compiles to native code using `ocloc`. |
| 42 | + std::optional<SmallVector<char, 0>> compileToBinary(const std::string &asmStr, |
| 43 | + StringRef inputFormat); |
| 44 | + |
| 45 | +protected: |
| 46 | + /// XeVM Target attribute. |
| 47 | + XeVMTargetAttr xeTarget; |
| 48 | + /// List of LLVM bitcode to link into after translation to LLVM IR. |
| 49 | + /// The attributes can be StringAttr pointing to a file path, or |
| 50 | + /// a Resource blob pointing to the LLVM bitcode in-memory. |
| 51 | + SmallVector<Attribute> librariesToLink; |
| 52 | + |
| 53 | + /// Returns the path to the tool used for serialization. |
| 54 | + std::optional<std::string> findTool(StringRef tool); |
| 55 | + |
| 56 | + /// GPU compilation target options. |
| 57 | + gpu::TargetOptions targetOptions; |
| 58 | +}; |
| 59 | +} // namespace xevm |
| 60 | +} // namespace mlir |
| 61 | + |
| 62 | +#endif // MLIR_TARGET_LLVM_XEVM_UTILS_H |
0 commit comments