LLVM 20.0.0git
Utility.h
Go to the documentation of this file.
1//===- Utility.h - Collection of geneirc offloading utilities -------------===//
2//
3// Part of the LLVM Project, 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#ifndef LLVM_FRONTEND_OFFLOADING_UTILITY_H
10#define LLVM_FRONTEND_OFFLOADING_UTILITY_H
11
12#include <cstdint>
13
14#include "llvm/ADT/StringMap.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/IR/Module.h"
18#include "llvm/Support/Error.h"
20
21namespace llvm {
22namespace offloading {
23
24/// This is the record of an object that just be registered with the offloading
25/// runtime.
26struct EntryTy {
27 void *Address;
29 size_t Size;
30 int32_t Flags;
31 int32_t Data;
32};
33
34/// Offloading entry flags for CUDA / HIP. The first three bits indicate the
35/// type of entry while the others are a bit field for additional information.
37 /// Mark the entry as a global entry. This indicates the presense of a
38 /// kernel if the size size field is zero and a variable otherwise.
40 /// Mark the entry as a managed global variable.
42 /// Mark the entry as a surface variable.
44 /// Mark the entry as a texture variable.
46 /// Mark the entry as being extern.
48 /// Mark the entry as being constant.
50 /// Mark the entry as being a normalized surface.
52};
53
54/// Returns the type of the offloading entry we use to store kernels and
55/// globals that will be registered with the offloading runtime.
57
58/// Returns the struct type we store the two pointers for CUDA / HIP managed
59/// variables in. Necessary until we widen the offload entry struct.
61
62/// Create an offloading section struct used to register this global at
63/// runtime.
64///
65/// \param M The module to be used
66/// \param Addr The pointer to the global being registered.
67/// \param Name The symbol name associated with the global.
68/// \param Size The size in bytes of the global (0 for functions).
69/// \param Flags Flags associated with the entry.
70/// \param Data Extra data storage associated with the entry.
71/// \param SectionName The section this entry will be placed at.
73 uint64_t Size, int32_t Flags, int32_t Data,
75/// Create a constant struct initializer used to register this global at
76/// runtime.
77/// \return the constant struct and the global variable holding the symbol name.
78std::pair<Constant *, GlobalVariable *>
80 uint64_t Size, int32_t Flags, int32_t Data);
81
82/// Creates a pair of globals used to iterate the array of offloading entries by
83/// accessing the section variables provided by the linker.
84std::pair<GlobalVariable *, GlobalVariable *>
86
87namespace amdgpu {
88/// Check if an image is compatible with current system's environment. The
89/// system environment is given as a 'target-id' which has the form:
90///
91/// <target-id> := <processor> ( ":" <target-feature> ( "+" | "-" ) )*
92///
93/// If a feature is not specific as '+' or '-' it is assumed to be in an 'any'
94/// and is compatible with either '+' or '-'. The HSA runtime returns this
95/// information using the target-id, while we use the ELF header to determine
96/// these features.
97bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags,
98 StringRef EnvTargetID);
99
100/// Struct for holding metadata related to AMDGPU kernels, for more information
101/// about the metadata and its meaning see:
102/// https://llvm.org/docs/AMDGPUUsage.html#code-object-v3
104 /// Constant indicating that a value is invalid.
105 static constexpr uint32_t KInvalidValue =
106 std::numeric_limits<uint32_t>::max();
107 /// The amount of group segment memory required by a work-group in bytes.
109 /// The amount of fixed private address space memory required for a work-item
110 /// in bytes.
112 /// Number of scalar registers required by a wavefront.
114 /// Number of vector registers required by each work-item.
116 /// Number of stores from a scalar register to a register allocator created
117 /// spill location.
119 /// Number of stores from a vector register to a register allocator created
120 /// spill location.
122 /// Number of accumulator registers required by each work-item.
124 /// Corresponds to the OpenCL reqd_work_group_size attribute.
127 /// Corresponds to the OpenCL work_group_size_hint attribute.
129 /// Wavefront size.
131 /// Maximum flat work-group size supported by the kernel in work-items.
133};
134
135/// Reads AMDGPU specific metadata from the ELF file and propagates the
136/// KernelInfoMap.
138 StringMap<AMDGPUKernelMetaData> &KernelInfoMap,
139 uint16_t &ELFABIVersion);
140} // namespace amdgpu
141} // namespace offloading
142} // namespace llvm
143
144#endif // LLVM_FRONTEND_OFFLOADING_UTILITY_H
This file defines the StringMap class.
uint64_t Addr
std::string Name
uint64_t Size
Module.h This file contains the declarations for the Module class.
This is an important base class in LLVM.
Definition: Constant.h:42
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Class to represent struct types.
Definition: DerivedTypes.h:218
Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer, StringMap< AMDGPUKernelMetaData > &KernelInfoMap, uint16_t &ELFABIVersion)
Reads AMDGPU specific metadata from the ELF file and propagates the KernelInfoMap.
Definition: Utility.cpp:345
bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags, StringRef EnvTargetID)
Check if an image is compatible with current system's environment.
Definition: Utility.cpp:153
StructType * getManagedTy(Module &M)
Returns the struct type we store the two pointers for CUDA / HIP managed variables in.
Definition: Utility.cpp:36
std::pair< Constant *, GlobalVariable * > getOffloadingEntryInitializer(Module &M, Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, int32_t Data)
Create a constant struct initializer used to register this global at runtime.
Definition: Utility.cpp:48
StructType * getEntryTy(Module &M)
Returns the type of the offloading entry we use to store kernels and globals that will be registered ...
Definition: Utility.cpp:24
OffloadEntryKindFlag
Offloading entry flags for CUDA / HIP.
Definition: Utility.h:36
@ OffloadGlobalSurfaceEntry
Mark the entry as a surface variable.
Definition: Utility.h:43
@ OffloadGlobalTextureEntry
Mark the entry as a texture variable.
Definition: Utility.h:45
@ OffloadGlobalNormalized
Mark the entry as being a normalized surface.
Definition: Utility.h:51
@ OffloadGlobalEntry
Mark the entry as a global entry.
Definition: Utility.h:39
@ OffloadGlobalManagedEntry
Mark the entry as a managed global variable.
Definition: Utility.h:41
@ OffloadGlobalExtern
Mark the entry as being extern.
Definition: Utility.h:47
@ OffloadGlobalConstant
Mark the entry as being constant.
Definition: Utility.h:49
void emitOffloadingEntry(Module &M, Constant *Addr, StringRef Name, uint64_t Size, int32_t Flags, int32_t Data, StringRef SectionName)
Create an offloading section struct used to register this global at runtime.
Definition: Utility.cpp:87
std::pair< GlobalVariable *, GlobalVariable * > getOffloadEntryArray(Module &M, StringRef SectionName)
Creates a pair of globals used to iterate the array of offloading entries by accessing the section va...
Definition: Utility.cpp:112
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This is the record of an object that just be registered with the offloading runtime.
Definition: Utility.h:26
Struct for holding metadata related to AMDGPU kernels, for more information about the metadata and it...
Definition: Utility.h:103
uint32_t SGPRSpillCount
Number of stores from a scalar register to a register allocator created spill location.
Definition: Utility.h:118
uint32_t SGPRCount
Number of scalar registers required by a wavefront.
Definition: Utility.h:113
static constexpr uint32_t KInvalidValue
Constant indicating that a value is invalid.
Definition: Utility.h:105
uint32_t VGPRSpillCount
Number of stores from a vector register to a register allocator created spill location.
Definition: Utility.h:121
uint32_t VGPRCount
Number of vector registers required by each work-item.
Definition: Utility.h:115
uint32_t PrivateSegmentSize
The amount of fixed private address space memory required for a work-item in bytes.
Definition: Utility.h:111
uint32_t GroupSegmentList
The amount of group segment memory required by a work-group in bytes.
Definition: Utility.h:108
uint32_t MaxFlatWorkgroupSize
Maximum flat work-group size supported by the kernel in work-items.
Definition: Utility.h:132
uint32_t WorkgroupSizeHint[3]
Corresponds to the OpenCL work_group_size_hint attribute.
Definition: Utility.h:128
uint32_t AGPRCount
Number of accumulator registers required by each work-item.
Definition: Utility.h:123
uint32_t RequestedWorkgroupSize[3]
Corresponds to the OpenCL reqd_work_group_size attribute.
Definition: Utility.h:125