|
9 | 9 | #ifndef LLVM_FRONTEND_OFFLOADING_UTILITY_H
|
10 | 10 | #define LLVM_FRONTEND_OFFLOADING_UTILITY_H
|
11 | 11 |
|
| 12 | +#include <cstdint> |
| 13 | + |
| 14 | +#include "llvm/ADT/StringMap.h" |
| 15 | +#include "llvm/ADT/StringRef.h" |
12 | 16 | #include "llvm/IR/Module.h"
|
13 | 17 | #include "llvm/Object/OffloadBinary.h"
|
| 18 | +#include "llvm/Support/Error.h" |
| 19 | +#include "llvm/Support/MemoryBufferRef.h" |
14 | 20 |
|
15 | 21 | namespace llvm {
|
16 | 22 | namespace offloading {
|
@@ -73,6 +79,60 @@ getOffloadingEntryInitializer(Module &M, Constant *Addr, StringRef Name,
|
73 | 79 | std::pair<GlobalVariable *, GlobalVariable *>
|
74 | 80 | getOffloadEntryArray(Module &M, StringRef SectionName);
|
75 | 81 |
|
| 82 | +namespace 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. |
| 92 | +bool 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 |
| 98 | +struct AMDGPUKernelMetaData { |
| 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. |
| 103 | + uint32_t GroupSegmentList = KInvalidValue; |
| 104 | + /// The amount of fixed private address space memory required for a work-item |
| 105 | + /// in bytes. |
| 106 | + uint32_t PrivateSegmentSize = KInvalidValue; |
| 107 | + /// Number of scalar registers required by a wavefront. |
| 108 | + uint32_t SGPRCount = KInvalidValue; |
| 109 | + /// Number of vector registers required by each work-item. |
| 110 | + uint32_t VGPRCount = KInvalidValue; |
| 111 | + /// Number of stores from a scalar register to a register allocator created |
| 112 | + /// spill location. |
| 113 | + uint32_t SGPRSpillCount = KInvalidValue; |
| 114 | + /// Number of stores from a vector register to a register allocator created |
| 115 | + /// spill location. |
| 116 | + uint32_t VGPRSpillCount = KInvalidValue; |
| 117 | + /// Number of accumulator registers required by each work-item. |
| 118 | + uint32_t AGPRCount = KInvalidValue; |
| 119 | + /// Corresponds to the OpenCL reqd_work_group_size attribute. |
| 120 | + uint32_t RequestedWorkgroupSize[3] = {KInvalidValue, KInvalidValue, |
| 121 | + KInvalidValue}; |
| 122 | + /// Corresponds to the OpenCL work_group_size_hint attribute. |
| 123 | + uint32_t WorkgroupSizeHint[3] = {KInvalidValue, KInvalidValue, KInvalidValue}; |
| 124 | + /// Wavefront size. |
| 125 | + uint32_t WavefrontSize = KInvalidValue; |
| 126 | + /// Maximum flat work-group size supported by the kernel in work-items. |
| 127 | + uint32_t MaxFlatWorkgroupSize = KInvalidValue; |
| 128 | +}; |
| 129 | + |
| 130 | +/// Reads AMDGPU specific metadata from the ELF file and propagates the |
| 131 | +/// KernelInfoMap. |
| 132 | +Error getAMDGPUMetaDataFromImage(MemoryBufferRef MemBuffer, |
| 133 | + StringMap<AMDGPUKernelMetaData> &KernelInfoMap, |
| 134 | + uint16_t &ELFABIVersion); |
| 135 | +} // namespace amdgpu |
76 | 136 | } // namespace offloading
|
77 | 137 | } // namespace llvm
|
78 | 138 |
|
|
0 commit comments