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/// Offloading entry flags for CUDA / HIP. The first three bits indicate the
25/// type of entry while the others are a bit field for additional information.
27 /// Mark the entry as a global entry. This indicates the presense of a
28 /// kernel if the size size field is zero and a variable otherwise.
30 /// Mark the entry as a managed global variable.
32 /// Mark the entry as a surface variable.
34 /// Mark the entry as a texture variable.
36 /// Mark the entry as being extern.
38 /// Mark the entry as being constant.
40 /// Mark the entry as being a normalized surface.
42};
43
44/// Returns the type of the offloading entry we use to store kernels and
45/// globals that will be registered with the offloading runtime.
47
48/// Create an offloading section struct used to register this global at
49/// runtime.
50///
51/// Type struct __tgt_offload_entry {
52/// void *addr; // Pointer to the offload entry info.
53/// // (function or global)
54/// char *name; // Name of the function or global.
55/// size_t size; // Size of the entry info (0 if it a function).
56/// int32_t flags;
57/// int32_t data;
58/// };
59///
60/// \param M The module to be used
61/// \param Addr The pointer to the global being registered.
62/// \param Name The symbol name associated with the global.
63/// \param Size The size in bytes of the global (0 for functions).
64/// \param Flags Flags associated with the entry.
65/// \param Data Extra data storage associated with the entry.
66/// \param SectionName The section this entry will be placed at.
68 uint64_t Size, int32_t Flags, int32_t Data,
70/// Create a constant struct initializer used to register this global at
71/// runtime.
72/// \return the constant struct and the global variable holding the symbol name.
73std::pair<Constant *, GlobalVariable *>
75 uint64_t Size, int32_t Flags, int32_t Data);
76
77/// Creates a pair of globals used to iterate the array of offloading entries by
78/// accessing the section variables provided by the linker.
79std::pair<GlobalVariable *, GlobalVariable *>
81
82namespace amdgpu {
83/// Check if an image is compatible with current system's environment. The
84/// system environment is given as a 'target-id' which has the form:
85///
86/// <target-id> := <processor> ( ":" <target-feature> ( "+" | "-" ) )*
87///
88/// If a feature is not specific as '+' or '-' it is assumed to be in an 'any'
89/// and is compatible with either '+' or '-'. The HSA runtime returns this
90/// information using the target-id, while we use the ELF header to determine
91/// these features.
92bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags,
93 StringRef EnvTargetID);
94
95/// Struct for holding metadata related to AMDGPU kernels, for more information
96/// about the metadata and its meaning see:
97/// https://llvm.org/docs/AMDGPUUsage.html#code-object-v3
99 /// Constant indicating that a value is invalid.
100 static constexpr uint32_t KInvalidValue =
101 std::numeric_limits<uint32_t>::max();
102 /// The amount of group segment memory required by a work-group in bytes.
104 /// The amount of fixed private address space memory required for a work-item
105 /// in bytes.
107 /// Number of scalar registers required by a wavefront.
109 /// Number of vector registers required by each work-item.
111 /// Number of stores from a scalar register to a register allocator created
112 /// spill location.
114 /// Number of stores from a vector register to a register allocator created
115 /// spill location.
117 /// Number of accumulator registers required by each work-item.
119 /// Corresponds to the OpenCL reqd_work_group_size attribute.
122 /// Corresponds to the OpenCL work_group_size_hint attribute.
124 /// Wavefront size.
126 /// Maximum flat work-group size supported by the kernel in work-items.
128};
129
130/// Reads AMDGPU specific metadata from the ELF file and propagates the
131/// KernelInfoMap.
133 StringMap<AMDGPUKernelMetaData> &KernelInfoMap,
134 uint16_t &ELFABIVersion);
135} // namespace amdgpu
136} // namespace offloading
137} // namespace llvm
138
139#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:335
bool isImageCompatibleWithEnv(StringRef ImageArch, uint32_t ImageFlags, StringRef EnvTargetID)
Check if an image is compatible with current system's environment.
Definition: Utility.cpp:143
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:38
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:26
@ OffloadGlobalSurfaceEntry
Mark the entry as a surface variable.
Definition: Utility.h:33
@ OffloadGlobalTextureEntry
Mark the entry as a texture variable.
Definition: Utility.h:35
@ OffloadGlobalNormalized
Mark the entry as being a normalized surface.
Definition: Utility.h:41
@ OffloadGlobalEntry
Mark the entry as a global entry.
Definition: Utility.h:29
@ OffloadGlobalManagedEntry
Mark the entry as a managed global variable.
Definition: Utility.h:31
@ OffloadGlobalExtern
Mark the entry as being extern.
Definition: Utility.h:37
@ OffloadGlobalConstant
Mark the entry as being constant.
Definition: Utility.h:39
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:77
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:102
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Struct for holding metadata related to AMDGPU kernels, for more information about the metadata and it...
Definition: Utility.h:98
uint32_t SGPRSpillCount
Number of stores from a scalar register to a register allocator created spill location.
Definition: Utility.h:113
uint32_t SGPRCount
Number of scalar registers required by a wavefront.
Definition: Utility.h:108
static constexpr uint32_t KInvalidValue
Constant indicating that a value is invalid.
Definition: Utility.h:100
uint32_t VGPRSpillCount
Number of stores from a vector register to a register allocator created spill location.
Definition: Utility.h:116
uint32_t VGPRCount
Number of vector registers required by each work-item.
Definition: Utility.h:110
uint32_t PrivateSegmentSize
The amount of fixed private address space memory required for a work-item in bytes.
Definition: Utility.h:106
uint32_t GroupSegmentList
The amount of group segment memory required by a work-group in bytes.
Definition: Utility.h:103
uint32_t MaxFlatWorkgroupSize
Maximum flat work-group size supported by the kernel in work-items.
Definition: Utility.h:127
uint32_t WorkgroupSizeHint[3]
Corresponds to the OpenCL work_group_size_hint attribute.
Definition: Utility.h:123
uint32_t AGPRCount
Number of accumulator registers required by each work-item.
Definition: Utility.h:118
uint32_t RequestedWorkgroupSize[3]
Corresponds to the OpenCL reqd_work_group_size attribute.
Definition: Utility.h:120