brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 77c756e Raw
81 lines · c
1//===----RTLs/amdgpu/utils/UtilitiesRTL.h ------------------------- C++ -*-===//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-exception6//7//===----------------------------------------------------------------------===//8//9// RTL Utilities for AMDGPU plugins10//11//===----------------------------------------------------------------------===//12 13#include <cstdint>14 15#include "Shared/Debug.h"16#include "Shared/Utils.h"17#include "Utils/ELF.h"18 19#include "omptarget.h"20 21#include "llvm/Frontend/Offloading/Utility.h"22 23namespace llvm {24namespace omp {25namespace target {26namespace plugin {27namespace hsa_utils {28 29// The implicit arguments of COV5 AMDGPU kernels.30struct alignas(alignof(void *)) AMDGPUImplicitArgsTy {31  uint32_t BlockCountX;32  uint32_t BlockCountY;33  uint32_t BlockCountZ;34  uint16_t GroupSizeX;35  uint16_t GroupSizeY;36  uint16_t GroupSizeZ;37  uint8_t Unused0[46]; // 46 byte offset.38  uint16_t GridDims;39  uint8_t Unused1[54]; // 54 byte offset.40  uint32_t DynamicLdsSize;41  uint8_t Unused2[132]; // 132 byte offset.42};43 44/// Returns the size in bytes of the implicit arguments of AMDGPU kernels.45/// `Version` is the ELF ABI version, e.g. COV5.46inline uint32_t getImplicitArgsSize(uint16_t Version) {47  return sizeof(AMDGPUImplicitArgsTy);48}49 50/// Reads the AMDGPU specific metadata from the ELF file and propagates the51/// KernelInfoMap52inline Error readAMDGPUMetaDataFromImage(53    MemoryBufferRef MemBuffer,54    StringMap<offloading::amdgpu::AMDGPUKernelMetaData> &KernelInfoMap,55    uint16_t &ELFABIVersion) {56  Error Err = llvm::offloading::amdgpu::getAMDGPUMetaDataFromImage(57      MemBuffer, KernelInfoMap, ELFABIVersion);58  if (!Err)59    return Err;60  DP("ELFABIVERSION Version: %u\n", ELFABIVersion);61  return Err;62}63 64/// Initializes the HSA implicit argument if the struct size permits it. This is65/// necessary because optimizations can modify the size of the struct if66/// portions of it are unused.67template <typename MemberTy, typename T>68void initImplArg(AMDGPUImplicitArgsTy *Base,69                 MemberTy AMDGPUImplicitArgsTy::*Member, size_t AvailableSize,70                 T Value) {71  uint64_t Offset = utils::getPtrDiff(&(Base->*Member), Base);72  if (Offset + sizeof(MemberTy) <= AvailableSize)73    Base->*Member = static_cast<MemberTy>(Value);74}75 76} // namespace hsa_utils77} // namespace plugin78} // namespace target79} // namespace omp80} // namespace llvm81