LLVM 23.0.0git
llvm::offloading Namespace Reference

Namespaces

namespace  amdgpu
namespace  intel
namespace  sycl

Classes

struct  EntryTy
 This is the record of an object that just be registered with the offloading runtime. More...
struct  InputDesc
 Description of a single input (file or library). More...
struct  ResolvedInputs
 Result of archive member resolution. More...
struct  SYCLJITOptions
struct  Symbol
 A minimum symbol interface that provides the necessary information to extract archive members and resolve LTO symbols. More...

Typedefs

using EntryArrayTy = std::pair<GlobalVariable *, GlobalVariable *>
using ByteArray = SmallVector<unsigned char, 0>
using PropertyValue = std::variant<uint32_t, ByteArray>
using PropertySet = std::map<std::string, PropertyValue>
using PropertySetRegistry = std::map<std::string, PropertySet>

Enumerations

enum  OffloadEntryKindFlag : uint32_t {
  OffloadGlobalEntry = 0x0 , OffloadGlobalManagedEntry = 0x1 , OffloadGlobalSurfaceEntry = 0x2 , OffloadGlobalTextureEntry = 0x3 ,
  OffloadGlobalExtern = 0x1 << 3 , OffloadGlobalConstant = 0x1 << 4 , OffloadGlobalNormalized = 0x1 << 5
}
 Offloading entry flags for CUDA / HIP. More...

Functions

Expected< ResolvedInputsresolveArchiveMembers (ArrayRef< InputDesc > Order, ArrayRef< StringRef > SearchPaths, ArrayRef< StringRef > ForcedUndefs={}, StringRef Root="", ArrayRef< Triple::ArchType > DeviceArchs={})
 Resolve archive members from the given inputs using a symbol-driven fixed-point algorithm.
LLVM_ABI llvm::Error wrapOpenMPBinaries (llvm::Module &M, llvm::ArrayRef< llvm::ArrayRef< char > > Images, EntryArrayTy EntryArray, llvm::StringRef Suffix="", bool Relocatable=false)
 Wraps the input device images into the module M as global symbols and registers the images with the OpenMP Offloading runtime libomptarget.
LLVM_ABI llvm::Error wrapCudaBinary (llvm::Module &M, llvm::ArrayRef< char > Images, EntryArrayTy EntryArray, llvm::StringRef Suffix="", bool EmitSurfacesAndTextures=true)
 Wraps the input fatbinary image into the module M as global symbols and registers the images with the CUDA runtime.
LLVM_ABI llvm::Error wrapHIPBinary (llvm::Module &M, llvm::ArrayRef< char > Images, EntryArrayTy EntryArray, llvm::StringRef Suffix="", bool EmitSurfacesAndTextures=true)
 Wraps the input bundled image into the module M as global symbols and registers the images with the HIP runtime.
LLVM_ABI llvm::Error wrapSYCLBinaries (llvm::Module &M, llvm::ArrayRef< char > Buffer, SYCLJITOptions Options=SYCLJITOptions())
 Wraps OffloadBinaries in the given Buffers into the module M as global symbols and registers the images with the SYCL Runtime.
LLVM_ABI void writePropertiesToJSON (const PropertySetRegistry &P, raw_ostream &O)
LLVM_ABI Expected< PropertySetRegistryreadPropertiesFromJSON (MemoryBufferRef Buf)
LLVM_ABI StructTypegetEntryTy (Module &M)
 Returns the type of the offloading entry we use to store kernels and globals that will be registered with the offloading runtime.
LLVM_ABI StringRef getOffloadEntrySection (Module &M)
 Create an offloading section struct used to register this global at runtime.
LLVM_ABI GlobalVariableemitOffloadingEntry (Module &M, object::OffloadKind Kind, Constant *Addr, StringRef Name, uint64_t Size, uint32_t Flags, uint64_t Data, Constant *AuxAddr=nullptr)
LLVM_ABI std::pair< Constant *, GlobalVariable * > getOffloadingEntryInitializer (Module &M, object::OffloadKind Kind, Constant *Addr, StringRef Name, uint64_t Size, uint32_t Flags, uint64_t Data, Constant *AuxAddr)
 Create a constant struct initializer used to register this global at runtime.
LLVM_ABI std::pair< GlobalVariable *, GlobalVariable * > getOffloadEntryArray (Module &M)
 Creates a pair of globals used to iterate the array of offloading entries by accessing the section variables provided by the linker.
LLVM_ABI Error containerizeImage (std::unique_ptr< MemoryBuffer > &Binary, llvm::Triple Triple, object::ImageKind ImageKind, object::OffloadKind OffloadKind, int32_t ImageFlags, MapVector< StringRef, StringRef > &MetaData)
 Containerizes an image within an OffloadBinary image.
static std::optional< std::string > findFile (StringRef Dir, StringRef Root, const Twine &Name)
static std::optional< std::string > findFromSearchPaths (StringRef Name, StringRef Root, ArrayRef< StringRef > SearchPaths)
static std::optional< std::string > searchLibrary (StringRef Input, StringRef Root, ArrayRef< StringRef > SearchPaths)
 Search for static libraries in the linker's library path given input like -lfoo or -l:libfoo.a.
static Expected< boolgetSymbolsFromBitcode (MemoryBufferRef Buffer, StringMap< Symbol > &SymTab, bool IsLazy)
static Expected< boolgetSymbolsFromObject (ObjectFile &ObjFile, StringMap< Symbol > &SymTab, bool IsLazy)
static bool isFatBinary (MemoryBufferRef Buffer, ArrayRef< Triple::ArchType > DeviceArchs)
 Identify "fat binary" inputs that should be passed through to the linker without symbol-driven extraction.
static Expected< boolgetSymbols (MemoryBufferRef Buffer, StringMap< Symbol > &SymTab, bool IsLazy)

Typedef Documentation

◆ ByteArray

Definition at line 25 of file PropertySet.h.

◆ EntryArrayTy

Definition at line 20 of file OffloadWrapper.h.

◆ PropertySet

using llvm::offloading::PropertySet = std::map<std::string, PropertyValue>

Definition at line 27 of file PropertySet.h.

◆ PropertySetRegistry

using llvm::offloading::PropertySetRegistry = std::map<std::string, PropertySet>

Definition at line 28 of file PropertySet.h.

◆ PropertyValue

Definition at line 26 of file PropertySet.h.

Enumeration Type Documentation

◆ OffloadEntryKindFlag

Offloading entry flags for CUDA / HIP.

The first three bits indicate the type of entry while the others are a bit field for additional information.

Enumerator
OffloadGlobalEntry 

Mark the entry as a global entry.

This indicates the presense of a kernel if the size size field is zero and a variable otherwise.

OffloadGlobalManagedEntry 

Mark the entry as a managed global variable.

OffloadGlobalSurfaceEntry 

Mark the entry as a surface variable.

OffloadGlobalTextureEntry 

Mark the entry as a texture variable.

OffloadGlobalExtern 

Mark the entry as being extern.

OffloadGlobalConstant 

Mark the entry as being constant.

OffloadGlobalNormalized 

Mark the entry as being a normalized surface.

Definition at line 54 of file Utility.h.

Function Documentation

◆ containerizeImage()

Error llvm::offloading::containerizeImage ( std::unique_ptr< MemoryBuffer > & Binary,
llvm::Triple Triple,
object::ImageKind ImageKind,
object::OffloadKind OffloadKind,
int32_t ImageFlags,
MapVector< StringRef, StringRef > & MetaData )

Containerizes an image within an OffloadBinary image.

Creates a nested OffloadBinary structure where the inner binary contains the raw image and associated metadata (version, format, triple, etc.).

Parameters
BinaryThe image to containerize.
TripleThe target triple to be associated with the image.
ImageKindThe format of the image, e.g. SPIR-V or CUBIN.
OffloadKindThe expected consuming runtime of the image, e.g. CUDA or OpenMP.
ImageFlagsFlags associated with the image, e.g. for AMDGPU the features.
MetaDataThe key-value map of metadata to be associated with the image.

Definition at line 432 of file Utility.cpp.

References llvm::MemoryBuffer::getMemBufferCopy(), llvm::Triple::getTriple(), llvm::InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key, and llvm::Error::success().

Referenced by llvm::offloading::intel::containerizeOpenMPSPIRVImage().

◆ emitOffloadingEntry()

◆ findFile()

std::optional< std::string > llvm::offloading::findFile ( StringRef Dir,
StringRef Root,
const Twine & Name )
static

◆ findFromSearchPaths()

std::optional< std::string > llvm::offloading::findFromSearchPaths ( StringRef Name,
StringRef Root,
ArrayRef< StringRef > SearchPaths )
static

Definition at line 64 of file ArchiveLinker.cpp.

References findFile().

Referenced by searchLibrary().

◆ getEntryTy()

StructType * llvm::offloading::getEntryTy ( Module & M)

Returns the type of the offloading entry we use to store kernels and globals that will be registered with the offloading runtime.

Definition at line 28 of file Utility.cpp.

References llvm::CallingConv::C, llvm::StructType::create(), llvm::Type::getInt16Ty(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::StructType::getTypeByName(), and llvm::PointerType::getUnqual().

Referenced by emitOffloadingEntry(), getOffloadEntryArray(), and getOffloadingEntryInitializer().

◆ getOffloadEntryArray()

◆ getOffloadEntrySection()

StringRef llvm::offloading::getOffloadEntrySection ( Module & M)

Create an offloading section struct used to register this global at runtime.

Parameters
MThe module to be used
AddrThe pointer to the global being registered.
KindThe offloading language expected to consume this.
NameThe symbol name associated with the global.
SizeThe size in bytes of the global (0 for functions).
FlagsFlags associated with the entry.
DataExtra data storage associated with the entry.
SectionNameThe section this entry will be placed at.
AuxAddrAn extra pointer if needed. Returns the section name for offloading entries based on the target triple. ELF: "llvm_offload_entries", COFF: "llvm_offload_entries", Mach-O: "__LLVM,offload_entries".

Definition at line 87 of file Utility.cpp.

Referenced by emitOffloadingEntry(), and getOffloadEntryArray().

◆ getOffloadingEntryInitializer()

◆ getSymbols()

◆ getSymbolsFromBitcode()

◆ getSymbolsFromObject()

◆ isFatBinary()

bool llvm::offloading::isFatBinary ( MemoryBufferRef Buffer,
ArrayRef< Triple::ArchType > DeviceArchs )
static

Identify "fat binary" inputs that should be passed through to the linker without symbol-driven extraction.

An input is a fat binary if DeviceArchs is non-empty and the input is an ELF object whose architecture is not one of the device architectures (or which fails to parse as an object file).

Definition at line 162 of file ArchiveLinker.cpp.

References llvm::consumeError(), llvm::ObjectFile::createObjectFile(), llvm::file_magic::elf_relocatable, llvm::ArrayRef< T >::empty(), llvm::MemoryBufferRef::getBuffer(), llvm::identify_magic(), llvm::is_contained(), and llvm::Expected< T >::takeError().

Referenced by resolveArchiveMembers().

◆ readPropertiesFromJSON()

◆ resolveArchiveMembers()

Expected< ResolvedInputs > llvm::offloading::resolveArchiveMembers ( ArrayRef< InputDesc > Order,
ArrayRef< StringRef > SearchPaths,
ArrayRef< StringRef > ForcedUndefs = {},
StringRef Root = "",
ArrayRef< Triple::ArchType > DeviceArchs = {} )

Resolve archive members from the given inputs using a symbol-driven fixed-point algorithm.

For each input:

  • If it's a Library, search for lib<name>.a or :<name> in SearchPaths
  • If it's a File, use the path directly
  • Archives are expanded and members are lazily extracted based on symbol references unless WholeArchive is true
  • Non-archive inputs (bitcode, ELF objects) are always included

Returns the buffers to link and the symbol table for LTO resolution.

Parameters
OrderPositional inputs + -l libraries in order.
SearchPaths-L paths for library search.
ForcedUndefs-u symbols (may be empty).
RootSysroot for "=" prefixed paths ("" if none).
DeviceArchsArchitectures of the device code being linked. When non-empty, any ELF input whose architecture is not in this list (or which cannot be parsed as an object) is treated as a "fat binary" and passed through without symbol scanning (e.g., nvlink's cubin detection). When empty, all inputs are scanned normally.

Definition at line 198 of file ArchiveLinker.cpp.

References llvm::file_magic::archive, llvm::file_magic::bitcode, llvm::object::Archive::create(), llvm::createFileError(), llvm::createStringError(), llvm::file_magic::elf_relocatable, llvm::SmallVectorImpl< T >::emplace_back(), llvm::errorOrToExpected(), llvm::sys::fs::exists(), Filename, llvm::MemoryBufferRef::getBuffer(), llvm::MemoryBuffer::getFileOrSTDIN(), llvm::MemoryBuffer::getMemBufferCopy(), getSymbols(), llvm::identify_magic(), llvm::sys::fs::is_directory(), isFatBinary(), llvm::offloading::InputDesc::Library, searchLibrary(), llvm::Error::success(), llvm::Expected< T >::takeError(), and llvm::offloading::Symbol::Undefined.

◆ searchLibrary()

std::optional< std::string > llvm::offloading::searchLibrary ( StringRef Input,
StringRef Root,
ArrayRef< StringRef > SearchPaths )
static

Search for static libraries in the linker's library path given input like -lfoo or -l:libfoo.a.

Definition at line 75 of file ArchiveLinker.cpp.

References findFromSearchPaths().

Referenced by resolveArchiveMembers().

◆ wrapCudaBinary()

Error llvm::offloading::wrapCudaBinary ( llvm::Module & M,
llvm::ArrayRef< char > Images,
EntryArrayTy EntryArray,
llvm::StringRef Suffix = "",
bool EmitSurfacesAndTextures = true )

Wraps the input fatbinary image into the module M as global symbols and registers the images with the CUDA runtime.

Parameters
EntryArrayOptional pair pointing to the __start and __stop symbols holding the __tgt_offload_entry array.
SuffixAn optional suffix appended to the emitted symbols.
EmitSurfacesAndTexturesWhether to emit surface and textures registration code. It defaults to false.

Definition at line 724 of file OffloadWrapper.cpp.

References llvm::createStringError(), llvm::inconvertibleErrorCode(), and llvm::Error::success().

◆ wrapHIPBinary()

Error llvm::offloading::wrapHIPBinary ( llvm::Module & M,
llvm::ArrayRef< char > Images,
EntryArrayTy EntryArray,
llvm::StringRef Suffix = "",
bool EmitSurfacesAndTextures = true )

Wraps the input bundled image into the module M as global symbols and registers the images with the HIP runtime.

Parameters
EntryArrayOptional pair pointing to the __start and __stop symbols holding the __tgt_offload_entry array.
SuffixAn optional suffix appended to the emitted symbols.
EmitSurfacesAndTexturesWhether to emit surface and textures registration code. It defaults to false.

Definition at line 738 of file OffloadWrapper.cpp.

References llvm::createStringError(), llvm::inconvertibleErrorCode(), and llvm::Error::success().

◆ wrapOpenMPBinaries()

Error llvm::offloading::wrapOpenMPBinaries ( llvm::Module & M,
llvm::ArrayRef< llvm::ArrayRef< char > > Images,
EntryArrayTy EntryArray,
llvm::StringRef Suffix = "",
bool Relocatable = false )

Wraps the input device images into the module M as global symbols and registers the images with the OpenMP Offloading runtime libomptarget.

Parameters
EntryArrayOptional pair pointing to the __start and __stop symbols holding the __tgt_offload_entry array.
SuffixAn optional suffix appended to the emitted symbols.
RelocatableIndicate if we need to change the offloading section to create a relocatable object.

Definition at line 712 of file OffloadWrapper.cpp.

References llvm::createStringError(), llvm::inconvertibleErrorCode(), and llvm::Error::success().

◆ wrapSYCLBinaries()

Error llvm::offloading::wrapSYCLBinaries ( llvm::Module & M,
llvm::ArrayRef< char > Buffer,
SYCLJITOptions Options = SYCLJITOptions() )

Wraps OffloadBinaries in the given Buffers into the module M as global symbols and registers the images with the SYCL Runtime.

Parameters
OptionsCompiler and linker options to be encoded for the later use by a runtime for JIT compilation. Not used for AOT.

Definition at line 751 of file OffloadWrapper.cpp.

References Options, Size, and llvm::Error::success().

◆ writePropertiesToJSON()