17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/Frontend/Offloading/Utility.h"
23 std::optional<DenseMap<StringAttr, NamedAttrList>>
26 uint16_t elfABIVersion;
27 llvm::StringMap<llvm::offloading::amdgpu::AMDGPUKernelMetaData> kernels;
28 llvm::MemoryBufferRef buffer(StringRef(elfData.data(), elfData.size()),
31 llvm::Error error = llvm::offloading::amdgpu::getAMDGPUMetaDataFromImage(
32 buffer, kernels, elfABIVersion);
35 llvm::consumeError(std::move(error));
39 auto getI32Array = [&builder](
const uint32_t *array) {
41 static_cast<int32_t
>(array[1]),
42 static_cast<int32_t
>(array[2])});
45 for (
const auto &[name, kernel] : kernels) {
51 attrs.
append(
"sgpr_spill_count",
53 attrs.
append(
"vgpr_spill_count",
55 attrs.
append(
"wavefront_size",
57 attrs.
append(
"max_flat_workgroup_size",
59 attrs.
append(
"group_segment_fixed_size",
61 attrs.
append(
"private_segment_fixed_size",
63 attrs.
append(
"reqd_workgroup_size",
64 getI32Array(kernel.RequestedWorkgroupSize));
65 attrs.
append(
"workgroup_size_hint", getI32Array(kernel.WorkgroupSizeHint));
68 return std::move(kernelMD);
73 auto module = cast<gpu::GPUModuleOp>(gpuModule);
74 Builder builder(module.getContext());
76 std::optional<DenseMap<StringAttr, NamedAttrList>> mdMapOrNull =
78 for (
auto funcOp : module.getBody()->getOps<LLVM::LLVMFuncOp>()) {
79 if (!funcOp->getDiscardableAttr(
"rocdl.kernel"))
83 mdMapOrNull->lookup(funcOp.getNameAttr()))
This class is a general helper class for creating context-global objects like types,...
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
IntegerAttr getI64IntegerAttr(int64_t value)
StringAttr getStringAttr(const Twine &bytes)
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
void append(StringRef name, Attribute attr)
Add an attribute with the specified name.
Operation is the basic unit of execution within MLIR.
MLIRContext * getContext()
Return the context this operation is associated with.
std::optional< DenseMap< StringAttr, NamedAttrList > > getAMDHSAKernelsELFMetadata(Builder &builder, ArrayRef< char > elfData)
Returns a map containing the amdhsa.kernels ELF metadata for each of the kernels in the binary,...
gpu::KernelTableAttr getKernelMetadata(Operation *gpuModule, ArrayRef< char > elfData={})
Returns a #gpu.kernel_table containing kernel metadata for each of the kernels in gpuModule.
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...