MLIR 24.0.0git
mlir::xevm::SerializeGPUModuleBase Class Reference

Base class for all XeVM serializations from GPU modules into binary strings. More...

#include "mlir/Target/LLVM/XeVM/Utils.h"

Inheritance diagram for mlir::xevm::SerializeGPUModuleBase:

Public Member Functions

 SerializeGPUModuleBase (Operation &module, XeVMTargetAttr target, const gpu::TargetOptions &targetOptions={})
XeVMTargetAttr getTarget () const
 Returns the target attribute.
std::optional< SmallVector< std::unique_ptr< llvm::Module > > > loadBitcodeFiles (llvm::Module &module) override
 Loads the bitcode files in librariesToLink.
gpu::GPUModuleOp getGPUModuleOp ()
 Returns the gpu module being serialized.
FailureOr< SmallVector< char, 0 > > compileToBinary (StringRef asmStr, StringRef inputFormat)
 Compiles to native code using ocloc (API or tool).
Public Member Functions inherited from mlir::LLVM::ModuleToObject
 ModuleToObject (Operation &module, StringRef triple, StringRef chip, StringRef features={}, int optLevel=3, function_ref< void(llvm::Module &)> initialLlvmIRCallback={}, function_ref< void(llvm::Module &)> linkedLlvmIRCallback={}, function_ref< void(llvm::Module &)> optimizedLlvmIRCallback={}, function_ref< void(StringRef)> isaCallback={}, const llvm::cl::LibraryOptionsContext *libraryOptions=nullptr)
virtual ~ModuleToObject ()
Operation & getOperation ()
 Returns the operation being serialized.
virtual std::optional< SmallVector< char, 0 > > run ()
 Runs the serialization pipeline, returning std::nullopt on error.

Static Public Member Functions

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.
Static Public Member Functions inherited from mlir::LLVM::ModuleToObject
static FailureOr< SmallString< 0 > > translateModuleToISA (llvm::Module &llvmModule, llvm::TargetMachine &targetMachine, function_ref< InFlightDiagnostic()> emitError)
 Translate LLVM module to textual ISA.

Protected Member Functions

std::optional< std::string > findTool (StringRef tool)
 Returns the path to the tool used for serialization.
FailureOr< SmallVector< char, 0 > > compileToBinaryViaOclocTool (StringRef asmStr, StringRef inputFormat)
 Compiles to native code using the ocloc command-line tool, communicating through temporary files.
FailureOr< SmallVector< char, 0 > > compileToBinaryViaLibocloc (StringRef asmStr, StringRef inputFormat)
 Compiles to native code using the ocloc shared library API, in-process, without temporary files.
Protected Member Functions inherited from mlir::LLVM::ModuleToObject
virtual void setupLLVMContext (llvm::LLVMContext &llvmContext)
 Hook for configuring the LLVM context, called by run before translating the operation.
virtual void setDataLayoutAndTriple (llvm::Module &module)
 Hook for computing the Datalayout.
virtual LogicalResult handleBitcodeFile (llvm::Module &module)
 Hook for performing additional actions on a loaded bitcode file.
virtual void handleModulePreLink (llvm::Module &module)
 Hook for performing additional actions on the llvmModule pre linking.
virtual void handleModulePostLink (llvm::Module &module)
 Hook for performing additional actions on the llvmModule post linking.
virtual FailureOr< SmallVector< char, 0 > > moduleToObject (llvm::Module &llvmModule)
 Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode.
FailureOr< llvm::TargetMachine * > getOrCreateTargetMachine ()
 Create the target machine based on the target triple and chip.
std::unique_ptr< llvm::Module > loadBitcodeFile (llvm::LLVMContext &context, StringRef path)
 Loads a bitcode file from path.
LogicalResult loadBitcodeFilesFromList (llvm::LLVMContext &context, ArrayRef< Attribute > librariesToLink, SmallVector< std::unique_ptr< llvm::Module > > &llvmModules, bool failureOnError=true)
 Loads multiple bitcode files.
std::unique_ptr< llvm::Module > translateToLLVMIR (llvm::LLVMContext &llvmContext)
 Translates the operation to LLVM IR.
LogicalResult linkFiles (llvm::Module &module, SmallVector< std::unique_ptr< llvm::Module > > &&libs)
 Link the llvmModule to other bitcode file.
virtual LogicalResult optimizeModule (llvm::Module &module, int optL)
 Optimize the module.

Static Protected Member Functions

static std::optional< std::string > findTool (StringRef tool, const gpu::TargetOptions &targetOptions)

Protected Attributes

XeVMTargetAttr xeTarget
 XeVM Target attribute.
SmallVector< Attribute > librariesToLink
 List of LLVM bitcode to link into after translation to LLVM IR.
gpu::TargetOptions targetOptions
 GPU compilation target options.
Protected Attributes inherited from mlir::LLVM::ModuleToObject
Operation & module
 Module to transform to a binary object.
StringRef triple
 Target triple.
StringRef chip
 Target chip.
StringRef features
 Target features.
int optLevel
 Optimization level.
function_ref< void(llvm::Module &)> initialLlvmIRCallback
 Callback invoked with the initial LLVM IR for the device module.
function_ref< void(llvm::Module &)> linkedLlvmIRCallback
 Callback invoked with LLVM IR for the device module after linking the device libraries.
function_ref< void(llvm::Module &)> optimizedLlvmIRCallback
 Callback invoked with LLVM IR for the device module after LLVM optimizations but before codegen.
function_ref< void(StringRef)> isaCallback
 Callback invoked with the target ISA for the device, for example PTX assembly.
const llvm::cl::LibraryOptionsContext * libraryOptions
 LLVM library options for the LLVMContext and TargetMachine that serialization creates, or nullptr for their defaults.

Detailed Description

Base class for all XeVM serializations from GPU modules into binary strings.

By default this class serializes into LLVM bitcode.

Definition at line 27 of file Utils.h.

Constructor & Destructor Documentation

◆ SerializeGPUModuleBase()

SerializeGPUModuleBase::SerializeGPUModuleBase ( Operation & module,
XeVMTargetAttr target,
const gpu::TargetOptions & targetOptions = {} )

Member Function Documentation

◆ compileToBinary()

FailureOr< SmallVector< char, 0 > > SerializeGPUModuleBase::compileToBinary ( StringRef asmStr,
StringRef inputFormat )

Compiles to native code using ocloc (API or tool).

Definition at line 395 of file Target.cpp.

References compileToBinaryViaLibocloc(), and compileToBinaryViaOclocTool().

◆ compileToBinaryViaLibocloc()

FailureOr< SmallVector< char, 0 > > mlir::xevm::SerializeGPUModuleBase::compileToBinaryViaLibocloc ( StringRef asmStr,
StringRef inputFormat )
protected

Compiles to native code using the ocloc shared library API, in-process, without temporary files.

Only defined when the library is linked in.

Referenced by compileToBinary().

◆ compileToBinaryViaOclocTool()

FailureOr< SmallVector< char, 0 > > SerializeGPUModuleBase::compileToBinaryViaOclocTool ( StringRef asmStr,
StringRef inputFormat )
protected

Compiles to native code using the ocloc command-line tool, communicating through temporary files.

Definition at line 288 of file Target.cpp.

References mlir::emitError(), findTool(), getGPUModuleOp(), getTarget(), and targetOptions.

Referenced by compileToBinary().

◆ findTool() [1/2]

std::optional< std::string > SerializeGPUModuleBase::findTool ( StringRef tool)
protected

Returns the path to the tool used for serialization.

Definition at line 478 of file Target.cpp.

References findTool(), getGPUModuleOp(), and targetOptions.

Referenced by compileToBinaryViaOclocTool(), findTool(), and getCompilerInfo().

◆ findTool() [2/2]

std::optional< std::string > SerializeGPUModuleBase::findTool ( StringRef tool,
const gpu::TargetOptions & targetOptions )
staticprotected

Definition at line 461 of file Target.cpp.

References targetOptions.

◆ getCompilerInfo()

std::string SerializeGPUModuleBase::getCompilerInfo ( const gpu::TargetOptions & targetOptions = {})
static

Returns the GPU compiler version info, or an empty string if the version can't be determined.

Definition at line 404 of file Target.cpp.

References findTool(), and targetOptions.

◆ getGPUModuleOp()

gpu::GPUModuleOp SerializeGPUModuleBase::getGPUModuleOp ( )

Returns the gpu module being serialized.

Definition at line 192 of file Target.cpp.

References mlir::LLVM::ModuleToObject::getOperation().

Referenced by compileToBinaryViaOclocTool(), and findTool().

◆ getTarget()

XeVMTargetAttr SerializeGPUModuleBase::getTarget ( ) const

Returns the target attribute.

Definition at line 179 of file Target.cpp.

References xeTarget.

Referenced by compileToBinaryViaOclocTool().

◆ loadBitcodeFiles()

std::optional< SmallVector< std::unique_ptr< llvm::Module > > > SerializeGPUModuleBase::loadBitcodeFiles ( llvm::Module & module)
overridevirtual

Loads the bitcode files in librariesToLink.

Reimplemented from mlir::LLVM::ModuleToObject.

Definition at line 182 of file Target.cpp.

References librariesToLink, mlir::LLVM::ModuleToObject::loadBitcodeFilesFromList(), and mlir::LLVM::ModuleToObject::module.

Member Data Documentation

◆ librariesToLink

SmallVector<Attribute> mlir::xevm::SerializeGPUModuleBase::librariesToLink
protected

List of LLVM bitcode to link into after translation to LLVM IR.

The attributes can be StringAttr pointing to a file path, or a Resource blob pointing to the LLVM bitcode in-memory.

Definition at line 57 of file Utils.h.

Referenced by loadBitcodeFiles().

◆ targetOptions

gpu::TargetOptions mlir::xevm::SerializeGPUModuleBase::targetOptions
protected

GPU compilation target options.

Definition at line 75 of file Utils.h.

Referenced by compileToBinaryViaOclocTool(), findTool(), findTool(), getCompilerInfo(), and SerializeGPUModuleBase().

◆ xeTarget

XeVMTargetAttr mlir::xevm::SerializeGPUModuleBase::xeTarget
protected

XeVM Target attribute.

Definition at line 53 of file Utils.h.

Referenced by getTarget(), and SerializeGPUModuleBase().


The documentation for this class was generated from the following files: