MLIR  20.0.0git
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mlir::ROCDL::SerializeGPUModuleBase Class Reference

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

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

+ Inheritance diagram for mlir::ROCDL::SerializeGPUModuleBase:

Public Member Functions

 SerializeGPUModuleBase (Operation &module, ROCDLTargetAttr target, const gpu::TargetOptions &targetOptions={})
 Initializes the toolkitPath with the path in targetOptions or if empty with the path in getROCMPath. More...
 
ROCDLTargetAttr getTarget () const
 Returns the target attribute. More...
 
StringRef getToolkitPath () const
 Returns the ROCM toolkit path. More...
 
ArrayRef< std::string > getFileList () const
 Returns the bitcode files to be loaded. More...
 
LogicalResult appendStandardLibs (AMDGCNLibraries libs)
 Appends standard ROCm device libraries to fileList. More...
 
virtual std::optional< SmallVector< std::unique_ptr< llvm::Module > > > loadBitcodeFiles (llvm::Module &module) override
 Loads the bitcode files in fileList. More...
 
void handleModulePreLink (llvm::Module &module) override
 Determines required Device Libraries and adds oclc control variables to the LLVM Module if needed. More...
 
LogicalResult handleBitcodeFile (llvm::Module &module) override
 Removes unnecessary metadata from the loaded bitcode files. More...
 
- 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={})
 
virtual ~ModuleToObject ()
 
OperationgetOperation ()
 Returns the operation being serialized. More...
 
virtual std::optional< SmallVector< char, 0 > > run ()
 Runs the serialization pipeline, returning std::nullopt on error. More...
 

Static Public Member Functions

static void init ()
 Initializes the LLVM AMDGPU target by safely calling LLVMInitializeAMDGPU* methods if available. More...
 

Protected Member Functions

void addControlVariables (llvm::Module &module, AMDGCNLibraries libs, bool wave64, bool daz, bool finiteOnly, bool unsafeMath, bool fastMath, bool correctSqrt, StringRef abiVer)
 Adds oclc control variables to the LLVM Module if needed. More...
 
virtual std::optional< SmallVector< char, 0 > > compileToBinary (const std::string &serializedISA)
 Compiles assembly to a binary. More...
 
std::optional< SmallVector< char, 0 > > moduleToObjectImpl (const gpu::TargetOptions &targetOptions, llvm::Module &llvmModule)
 Default implementation of ModuleToObject::moduleToObject. More...
 
std::optional< SmallVector< char, 0 > > assembleIsa (StringRef isa)
 Returns the assembled ISA. More...
 
- Protected Member Functions inherited from mlir::LLVM::ModuleToObject
virtual void setDataLayoutAndTriple (llvm::Module &module)
 Hook for computing the Datalayout. More...
 
virtual void handleModulePostLink (llvm::Module &module)
 Hook for performing additional actions on the llvmModule post linking. More...
 
virtual std::optional< SmallVector< char, 0 > > moduleToObject (llvm::Module &llvmModule)
 Serializes the LLVM IR bitcode to an object file, by default it serializes to LLVM bitcode. More...
 
std::optional< llvm::TargetMachine * > getOrCreateTargetMachine ()
 Create the target machine based on the target triple and chip. More...
 
std::unique_ptr< llvm::Module > loadBitcodeFile (llvm::LLVMContext &context, StringRef path)
 Loads a bitcode file from path. More...
 
LogicalResult loadBitcodeFilesFromList (llvm::LLVMContext &context, ArrayRef< std::string > fileList, SmallVector< std::unique_ptr< llvm::Module >> &llvmModules, bool failureOnError=true)
 Loads multiple bitcode files. More...
 
std::unique_ptr< llvm::Module > translateToLLVMIR (llvm::LLVMContext &llvmContext)
 Translates the operation to LLVM IR. More...
 
LogicalResult linkFiles (llvm::Module &module, SmallVector< std::unique_ptr< llvm::Module >> &&libs)
 Link the llvmModule to other bitcode file. More...
 
virtual LogicalResult optimizeModule (llvm::Module &module, int optL)
 Optimize the module. More...
 

Protected Attributes

ROCDLTargetAttr target
 ROCDL target attribute. More...
 
std::string toolkitPath
 ROCM toolkit path. More...
 
SmallVector< std::string > fileList
 List of LLVM bitcode files to link to. More...
 
AMDGCNLibraries deviceLibs = AMDGCNLibraries::None
 AMD GCN libraries to use when linking, the default is using none. More...
 
- Protected Attributes inherited from mlir::LLVM::ModuleToObject
Operationmodule
 Module to transform to a binary object. More...
 
StringRef triple
 Target triple. More...
 
StringRef chip
 Target chip. More...
 
StringRef features
 Target features. More...
 
int optLevel
 Optimization level. More...
 
function_ref< void(llvm::Module &)> initialLlvmIRCallback
 Callback invoked with the initial LLVM IR for the device module. More...
 
function_ref< void(llvm::Module &)> linkedLlvmIRCallback
 Callback invoked with LLVM IR for the device module after linking the device libraries. More...
 
function_ref< void(llvm::Module &)> optimizedLlvmIRCallback
 Callback invoked with LLVM IR for the device module after LLVM optimizations but before codegen. More...
 
function_ref< void(StringRef)> isaCallback
 Callback invoked with the target ISA for the device, for example PTX assembly. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from mlir::LLVM::ModuleToObject
static std::optional< std::string > translateToISA (llvm::Module &llvmModule, llvm::TargetMachine &targetMachine)
 Utility function for translating to ISA, returns std::nullopt on failure. More...
 

Detailed Description

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

By default this class serializes into LLVM bitcode.

Definition at line 47 of file Utils.h.

Constructor & Destructor Documentation

◆ SerializeGPUModuleBase()

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

Initializes the toolkitPath with the path in targetOptions or if empty with the path in getROCMPath.

Definition at line 94 of file Target.cpp.

References fileList, mlir::ROCDL::getROCMPath(), target, and toolkitPath.

Member Function Documentation

◆ addControlVariables()

void SerializeGPUModuleBase::addControlVariables ( llvm::Module &  module,
AMDGCNLibraries  libs,
bool  wave64,
bool  daz,
bool  finiteOnly,
bool  unsafeMath,
bool  fastMath,
bool  correctSqrt,
StringRef  abiVer 
)
protected

Adds oclc control variables to the LLVM Module if needed.

It also sets amdhsa_code_object_version module flag which is equal to ABI version and it uses "llvm::Module::Error" to set that flag.

Definition at line 230 of file Target.cpp.

References mlir::LLVM::ModuleToObject::chip, Error, mlir::get(), mlir::Operation::getContext(), mlir::LLVM::ModuleToObject::module, mlir::ROCDL::None, mlir::ROCDL::Ockl, and mlir::ROCDL::Ocml.

Referenced by handleModulePreLink().

◆ appendStandardLibs()

LogicalResult SerializeGPUModuleBase::appendStandardLibs ( AMDGCNLibraries  libs)

◆ assembleIsa()

std::optional< SmallVector< char, 0 > > SerializeGPUModuleBase::assembleIsa ( StringRef  isa)
protected

◆ compileToBinary()

std::optional< SmallVector< char, 0 > > SerializeGPUModuleBase::compileToBinary ( const std::string &  serializedISA)
protectedvirtual

Compiles assembly to a binary.

Definition at line 346 of file Target.cpp.

References assembleIsa(), mlir::Operation::emitError(), mlir::LLVM::ModuleToObject::getOperation(), and toolkitPath.

Referenced by moduleToObjectImpl().

◆ getFileList()

ArrayRef< std::string > SerializeGPUModuleBase::getFileList ( ) const

Returns the bitcode files to be loaded.

Definition at line 131 of file Target.cpp.

References fileList.

◆ getTarget()

ROCDLTargetAttr SerializeGPUModuleBase::getTarget ( ) const

Returns the target attribute.

Definition at line 127 of file Target.cpp.

References target.

◆ getToolkitPath()

StringRef SerializeGPUModuleBase::getToolkitPath ( ) const

Returns the ROCM toolkit path.

Definition at line 129 of file Target.cpp.

References toolkitPath.

Referenced by appendStandardLibs(), and moduleToObjectImpl().

◆ handleBitcodeFile()

LogicalResult SerializeGPUModuleBase::handleBitcodeFile ( llvm::Module &  module)
overridevirtual

Removes unnecessary metadata from the loaded bitcode files.

Reimplemented from mlir::LLVM::ModuleToObject.

Definition at line 192 of file Target.cpp.

References mlir::LLVM::ModuleToObject::module, and mlir::LLVM::ModuleToObject::setDataLayoutAndTriple().

◆ handleModulePreLink()

void SerializeGPUModuleBase::handleModulePreLink ( llvm::Module &  module)
overridevirtual

Determines required Device Libraries and adds oclc control variables to the LLVM Module if needed.

Also sets amdhsa_code_object_version module flag.

Reimplemented from mlir::LLVM::ModuleToObject.

Definition at line 205 of file Target.cpp.

References addControlVariables(), mlir::ROCDL::All, deviceLibs, mlir::ROCDL::Hip, mlir::LLVM::ModuleToObject::module, mlir::ROCDL::Ockl, mlir::ROCDL::Ocml, mlir::ROCDL::OpenCL, and target.

◆ init()

void SerializeGPUModuleBase::init ( )
static

Initializes the LLVM AMDGPU target by safely calling LLVMInitializeAMDGPU* methods if available.

Definition at line 113 of file Target.cpp.

◆ loadBitcodeFiles()

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

◆ moduleToObjectImpl()

std::optional< SmallVector< char, 0 > > SerializeGPUModuleBase::moduleToObjectImpl ( const gpu::TargetOptions targetOptions,
llvm::Module &  llvmModule 
)
protected

Member Data Documentation

◆ deviceLibs

AMDGCNLibraries mlir::ROCDL::SerializeGPUModuleBase::deviceLibs = AMDGCNLibraries::None
protected

AMD GCN libraries to use when linking, the default is using none.

Definition at line 113 of file Utils.h.

Referenced by handleModulePreLink(), and loadBitcodeFiles().

◆ fileList

SmallVector<std::string> mlir::ROCDL::SerializeGPUModuleBase::fileList
protected

List of LLVM bitcode files to link to.

Definition at line 110 of file Utils.h.

Referenced by appendStandardLibs(), getFileList(), loadBitcodeFiles(), and SerializeGPUModuleBase().

◆ target

ROCDLTargetAttr mlir::ROCDL::SerializeGPUModuleBase::target
protected

ROCDL target attribute.

Definition at line 104 of file Utils.h.

Referenced by assembleIsa(), getTarget(), handleModulePreLink(), and SerializeGPUModuleBase().

◆ toolkitPath

std::string mlir::ROCDL::SerializeGPUModuleBase::toolkitPath
protected

ROCM toolkit path.

Definition at line 107 of file Utils.h.

Referenced by compileToBinary(), getToolkitPath(), and SerializeGPUModuleBase().


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