P4 to Git Change 1362323 by kzhuravl@kzhuravl-fiji-cl-on-lc on 2017/01/16 14:21:45
SWDEV-102713 - Update Runtime to Metadata 2.0.
ReviewBoardURL: http://ocltc/reviews/r/11965/
Testing: some OCL SDK samples.
Change by Nikolay Haustov
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palkernel.cpp#30 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palkernel.hpp#8 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#29 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#15 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/amdgpu_metadata.cpp#7 delete
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/amdgpu_metadata.hpp#6 delete
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.cpp#19 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.hpp#12 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#52 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#19 edit
[ROCm/clr commit: c513ed5207]
Этот коммит содержится в:
@@ -11,10 +11,6 @@
|
||||
|
||||
#include "acl.h"
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
#include "libamdhsacode/amdgpu_metadata.hpp"
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
@@ -1378,9 +1374,9 @@ LightningKernel::initPrintf(const std::vector<std::string>& printfInfoStrings)
|
||||
}
|
||||
|
||||
static inline HSAIL_ARG_TYPE
|
||||
GetKernelArgType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgType(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
switch (lcArg.Kind()) {
|
||||
switch (lcArg.Kind) {
|
||||
case AMDGPU::RuntimeMD::KernelArg::GlobalBuffer:
|
||||
case AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer:
|
||||
return HSAIL_ARGTYPE_POINTER;
|
||||
@@ -1410,16 +1406,16 @@ GetKernelArgType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
GetKernelArgAlignment(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgAlignment(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
return lcArg.Align();
|
||||
return lcArg.Align;
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
GetKernelArgPointeeAlignment(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgPointeeAlignment(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
uint32_t align = lcArg.PointeeAlign();
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
uint32_t align = lcArg.PointeeAlign;
|
||||
if (align == 0) {
|
||||
LogWarning("Missing DynamicSharedPointer alignment");
|
||||
align = 128; /* worst case alignment */;
|
||||
@@ -1430,11 +1426,11 @@ GetKernelArgPointeeAlignment(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
}
|
||||
|
||||
static inline HSAIL_ACCESS_TYPE
|
||||
GetKernelArgAccessType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgAccessType(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::Image) {
|
||||
switch (lcArg.AccQual()) {
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::Image) {
|
||||
switch (lcArg.AccQual) {
|
||||
case AMDGPU::RuntimeMD::KernelArg::ReadOnly:
|
||||
return HSAIL_ACCESS_TYPE_RO;
|
||||
case AMDGPU::RuntimeMD::KernelArg::WriteOnly:
|
||||
@@ -1448,36 +1444,36 @@ GetKernelArgAccessType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
}
|
||||
|
||||
static inline HSAIL_ADDRESS_QUALIFIER
|
||||
GetKernelAddrQual(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelAddrQual(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
return HSAIL_ADDRESS_LOCAL;
|
||||
}
|
||||
else if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer) {
|
||||
if (lcArg.AddrQual() == AMDGPU::RuntimeMD::KernelArg::Global) {
|
||||
else if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer) {
|
||||
if (lcArg.AddrQual == AMDGPU::RuntimeMD::KernelArg::Global) {
|
||||
return HSAIL_ADDRESS_GLOBAL;
|
||||
}
|
||||
else if (lcArg.AddrQual() == AMDGPU::RuntimeMD::KernelArg::Constant) {
|
||||
else if (lcArg.AddrQual == AMDGPU::RuntimeMD::KernelArg::Constant) {
|
||||
return HSAIL_ADDRESS_CONSTANT;
|
||||
}
|
||||
LogError("Unsupported address type");
|
||||
return HSAIL_ADDRESS_ERROR;
|
||||
}
|
||||
else if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::Image
|
||||
|| lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::Sampler) {
|
||||
else if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::Image
|
||||
|| lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::Sampler) {
|
||||
return HSAIL_ADDRESS_GLOBAL;
|
||||
}
|
||||
return HSAIL_ADDRESS_ERROR;
|
||||
}
|
||||
|
||||
static inline HSAIL_DATA_TYPE
|
||||
GetKernelDataType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelDataType(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
if (lcArg.Kind() != AMDGPU::RuntimeMD::KernelArg::ByValue) {
|
||||
if (lcArg.Kind != AMDGPU::RuntimeMD::KernelArg::ByValue) {
|
||||
return HSAIL_DATATYPE_ERROR;
|
||||
}
|
||||
|
||||
switch (lcArg.ValueType()) {
|
||||
switch (lcArg.ValueType) {
|
||||
case AMDGPU::RuntimeMD::KernelArg::I8:
|
||||
return HSAIL_DATATYPE_S8;
|
||||
case AMDGPU::RuntimeMD::KernelArg::I16:
|
||||
@@ -1508,18 +1504,18 @@ GetKernelDataType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
}
|
||||
|
||||
static inline cl_kernel_arg_type_qualifier
|
||||
GetOclTypeQual(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetOclTypeQual(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
cl_kernel_arg_type_qualifier rv = CL_KERNEL_ARG_TYPE_NONE;
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
if (lcArg.IsVolatile()) {
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
if (lcArg.IsVolatile) {
|
||||
rv |= CL_KERNEL_ARG_TYPE_VOLATILE;
|
||||
}
|
||||
if (lcArg.IsRestrict()) {
|
||||
if (lcArg.IsRestrict) {
|
||||
rv |= CL_KERNEL_ARG_TYPE_RESTRICT;
|
||||
}
|
||||
if (lcArg.IsConst()) {
|
||||
if (lcArg.IsConst) {
|
||||
rv |= CL_KERNEL_ARG_TYPE_CONST;
|
||||
}
|
||||
}
|
||||
@@ -1527,21 +1523,21 @@ GetOclTypeQual(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
}
|
||||
|
||||
void
|
||||
LightningKernel::initArgList(const amd::hsa::code::Kernel::Metadata& kernelMD)
|
||||
LightningKernel::initArgList(const AMDGPU::RuntimeMD::Kernel::Metadata& kernelMD)
|
||||
{
|
||||
device::Kernel::parameters_t params;
|
||||
|
||||
size_t offset = 0;
|
||||
|
||||
for (size_t i = 0; i < kernelMD.KernelArgCount(); ++i) {
|
||||
const amd::hsa::code::KernelArg::Metadata& lcArg =
|
||||
kernelMD.GetKernelArgMetadata(i);
|
||||
for (size_t i = 0; i < kernelMD->KernelArgCount(); ++i) {
|
||||
const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg =
|
||||
kernelMD.Args[i];
|
||||
|
||||
// Initialize HSAIL kernel argument
|
||||
auto arg = new HSAILKernel::Argument;
|
||||
arg->name_ = lcArg.Name();
|
||||
arg->typeName_ = lcArg.TypeName();
|
||||
arg->size_ = lcArg.Size();
|
||||
arg->name_ = lcArg.Name;
|
||||
arg->typeName_ = lcArg.TypeName;
|
||||
arg->size_ = lcArg.Size;
|
||||
arg->type_ = GetKernelArgType(lcArg);
|
||||
arg->addrQual_ = GetKernelAddrQual(lcArg);
|
||||
arg->dataType_ = GetKernelDataType(lcArg);
|
||||
@@ -1567,12 +1563,12 @@ LightningKernel::initArgList(const amd::hsa::code::Kernel::Metadata& kernelMD)
|
||||
// Initialize Device kernel parameters
|
||||
amd::KernelParameterDescriptor desc;
|
||||
|
||||
desc.name_ = lcArg.Name().c_str();
|
||||
desc.name_ = lcArg.Name.c_str();
|
||||
desc.type_ = GetOclType(arg);
|
||||
desc.addressQualifier_ = GetOclAddrQual(arg);
|
||||
desc.accessQualifier_ = GetOclAccessQual(arg);
|
||||
desc.typeQualifier_ = GetOclTypeQual(lcArg);
|
||||
desc.typeName_ = lcArg.TypeName().c_str();
|
||||
desc.typeName_ = lcArg.TypeName.c_str();
|
||||
|
||||
// Make a check if it is local or global
|
||||
if (desc.addressQualifier_ == CL_KERNEL_ARG_ADDRESS_LOCAL) {
|
||||
@@ -1600,6 +1596,13 @@ LightningKernel::initArgList(const amd::hsa::code::Kernel::Metadata& kernelMD)
|
||||
createSignature(params);
|
||||
}
|
||||
|
||||
static const AMDGPU::RuntimeMD::Kernel::Metadata* FindKernelMetadata(const AMDGPU::RuntimeMD::Program::Metadata* programMD, const std::string& name) {
|
||||
for (const AMDGPU::RuntimeMD::Kernel::Metadata& kernelMD : programMD->Kernels) {
|
||||
if (kernelMD.Name == name) { return &kernelMD; }
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
LightningKernel::init(amd::hsa::loader::Symbol* symbol)
|
||||
{
|
||||
@@ -1608,32 +1611,35 @@ LightningKernel::init(amd::hsa::loader::Symbol* symbol)
|
||||
|
||||
aqlCreateHWInfo(symbol);
|
||||
|
||||
const amd::hsa::code::Program::Metadata* runtimeMD = prog().metadata();
|
||||
if (!runtimeMD) {
|
||||
const AMDGPU::RuntimeMD::Program::Metadata* programMD = prog().metadata();
|
||||
assert(programMD != nullptr);
|
||||
|
||||
const AMDGPU::RuntimeMD::Kernel::Metadata* kernelMD =
|
||||
FindKernelMetadata(programMd, name());
|
||||
|
||||
if (kernelMD == nullptr) {
|
||||
return false;
|
||||
}
|
||||
const amd::hsa::code::Kernel::Metadata& kernelMD =
|
||||
runtimeMD->GetKernelMetadata(runtimeMD->KernelIndexByName(name()));
|
||||
|
||||
// Set the argList
|
||||
initArgList(kernelMD);
|
||||
initArgList(*kernelMD);
|
||||
|
||||
if (kernelMD.HasRequiredWorkgroupSize()) {
|
||||
const uint32_t* requiredWorkgroupSize = kernelMD.RequiredWorkgroupSize();
|
||||
if (!kernelMD->ReqdWorkGroupSize.empty()) {
|
||||
const auto& requiredWorkgroupSize = kernelMD->ReqdWorkGroupSize;
|
||||
workGroupInfo_.compileSize_[0] = requiredWorkgroupSize[0];
|
||||
workGroupInfo_.compileSize_[1] = requiredWorkgroupSize[1];
|
||||
workGroupInfo_.compileSize_[2] = requiredWorkgroupSize[2];
|
||||
}
|
||||
|
||||
if (kernelMD.HasWorkgroupSizeHint()) {
|
||||
const uint32_t* workgroupSizeHint = kernelMD.WorkgroupSizeHint();
|
||||
if (!kernelMD->WorkGroupSizeHint.empty()) {
|
||||
const auto& workgroupSizeHint = kernelMD->WorkGroupSizeHint;
|
||||
workGroupInfo_.compileSizeHint_[0] = workgroupSizeHint[0];
|
||||
workGroupInfo_.compileSizeHint_[1] = workgroupSizeHint[1];
|
||||
workGroupInfo_.compileSizeHint_[2] = workgroupSizeHint[2];
|
||||
}
|
||||
|
||||
if (kernelMD.HasVecTypeHint()) {
|
||||
workGroupInfo_.compileVecTypeHint_ = kernelMD.VecTypeHint().c_str();
|
||||
if (!kernelMD->VecTypeHint.empty()) {
|
||||
workGroupInfo_.compileVecTypeHint_ = kernelMD->VecTypeHint.c_str();
|
||||
}
|
||||
|
||||
// Copy wavefront size
|
||||
@@ -1650,7 +1656,7 @@ LightningKernel::init(amd::hsa::loader::Symbol* symbol)
|
||||
workGroupInfo_.size_ = dev().info().maxWorkGroupSize_;
|
||||
}
|
||||
|
||||
initPrintf(runtimeMD->PrintfInfo());
|
||||
initPrintf(programMD->PrintfInfo());
|
||||
|
||||
/*FIXME_lmoriche:
|
||||
size_t sizeOfWavesPerSimdHint = sizeof(workGroupInfo_.wavesPerSimdHint_);
|
||||
|
||||
@@ -279,7 +279,7 @@ public:
|
||||
bool init(amd::hsa::loader::Symbol* symbol);
|
||||
|
||||
//! Initializes Hsail Argument metadata and info for LC
|
||||
void initArgList(const amd::hsa::code::Kernel::Metadata& kernelMD);
|
||||
void initArgList(const AMDGPU::RuntimeMD::Kernel::Metadata& kernelMD);
|
||||
|
||||
//! Initializes HSAIL Printf metadata and info for LC
|
||||
void initPrintf(const std::vector<std::string>& printfInfoStrings);
|
||||
|
||||
@@ -1606,16 +1606,11 @@ LightningProgram::setKernels(
|
||||
if (note->n_type == 7 /*NT_AMDGPU_HSA_RUNTIME_METADATA_1_0*/
|
||||
&& note->n_namesz == sizeof "AMD"
|
||||
&& !memcmp(name, "AMD", note->n_namesz)) {
|
||||
metadata_ = new amd::hsa::code::Program::Metadata();
|
||||
if (metadata_ && metadata_->ReadFrom(desc,note->n_descsz)) {
|
||||
// We've found and loaded the runtime metadata, exit the
|
||||
// note record loop now.
|
||||
break;
|
||||
}
|
||||
|
||||
buildLog_ += "Error while parsing ELF program binary " \
|
||||
"runtime metadata section\n";
|
||||
return false;
|
||||
std::string metadataStr((const char *) desc, (size_t) note->n_descsz);
|
||||
metadata_ = new AMDGPU::RuntimeMD::Program::Metadata(metadataStr);
|
||||
// We've found and loaded the runtime metadata, exit the
|
||||
// note record loop now.
|
||||
break;
|
||||
}
|
||||
ptr += sizeof(*note)
|
||||
+ amd::alignUp(note->n_namesz, sizeof(int))
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "amd_hsa_loader.hpp"
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
#include "libamdhsacode/amdgpu_metadata.hpp"
|
||||
#include "AMDGPURuntimeMetadata.h"
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
namespace amd {
|
||||
@@ -301,7 +301,7 @@ public:
|
||||
metadata_(nullptr)
|
||||
{}
|
||||
|
||||
const amd::hsa::code::Program::Metadata* metadata() const {
|
||||
const AMDGPU::RuntimeMD::Program::Metadata* metadata() const {
|
||||
return metadata_;
|
||||
}
|
||||
private:
|
||||
@@ -340,7 +340,7 @@ protected:
|
||||
static std::auto_ptr<amd::opencl_driver::Compiler> newCompilerInstance();
|
||||
|
||||
private:
|
||||
amd::hsa::code::Program::Metadata* metadata_; //!< Runtime metadata
|
||||
AMDGPU::RuntimeMD::Program::Metadata* metadata_; //!< Runtime metadata
|
||||
};
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
|
||||
@@ -1,518 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// The University of Illinois/NCSA
|
||||
// Open Source License (NCSA)
|
||||
//
|
||||
// Copyright (c) 2014-2016, Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// Developed by:
|
||||
//
|
||||
// AMD Research and AMD HSA Software Development
|
||||
//
|
||||
// Advanced Micro Devices, Inc.
|
||||
//
|
||||
// www.amd.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal with the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimers.
|
||||
// - Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimers in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// - Neither the names of Advanced Micro Devices, Inc,
|
||||
// nor the names of its contributors may be used to endorse or promote
|
||||
// products derived from this Software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS WITH THE SOFTWARE.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
#include "amdgpu_metadata.hpp"
|
||||
|
||||
namespace amd {
|
||||
namespace hsa {
|
||||
namespace code {
|
||||
|
||||
template <typename T>
|
||||
bool Read(std::istream& in, T& v);
|
||||
|
||||
template<>
|
||||
bool Read<uint32_t>(std::istream& in, uint32_t& v) {
|
||||
in.read((char *)&v, sizeof(v));
|
||||
return (in.tellg() != (std::streampos) -1 ) && !in.eof() && !in.fail() && !in.bad();
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<uint16_t>(std::istream& in, uint16_t& v) {
|
||||
in.read((char *)&v, sizeof(v));
|
||||
return !in.eof() && !in.fail() && !in.bad();
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<uint8_t>(std::istream& in, uint8_t& v) {
|
||||
in.read((char *)&v, sizeof(v));
|
||||
return !in.eof() && !in.fail() && !in.bad();
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<std::string>(std::istream& in, std::string& v) {
|
||||
uint32_t len;
|
||||
if (!Read(in, len)) { return false; }
|
||||
v.resize(len);
|
||||
if (!in.read(&v[0], len)) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Read3(std::istream& in, T* v) {
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
if (!Read(in, v[i])) { return false; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T1, typename T>
|
||||
bool ReadConvert(std::istream& in, T& v) {
|
||||
T1 v1;
|
||||
if (!Read<T1>(in, v1)) { return false; }
|
||||
v = static_cast<T>(v1);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<AMDGPU::RuntimeMD::Key>(std::istream& in, AMDGPU::RuntimeMD::Key& v) {
|
||||
return ReadConvert<uint8_t>(in, v);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<AMDGPU::RuntimeMD::KernelArg::Kind>(std::istream& in, AMDGPU::RuntimeMD::KernelArg::Kind& v) {
|
||||
return ReadConvert<uint8_t>(in, v);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<AMDGPU::RuntimeMD::KernelArg::ValueType>(std::istream& in, AMDGPU::RuntimeMD::KernelArg::ValueType& v) {
|
||||
return ReadConvert<uint16_t>(in, v);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<AMDGPU::RuntimeMD::KernelArg::AccessQualifer>(std::istream& in, AMDGPU::RuntimeMD::KernelArg::AccessQualifer& v) {
|
||||
return ReadConvert<uint8_t>(in, v);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool Read<AMDGPU::RuntimeMD::Language>(std::istream& in, AMDGPU::RuntimeMD::Language& v) {
|
||||
return ReadConvert<uint8_t>(in, v);
|
||||
}
|
||||
|
||||
namespace KernelArg {
|
||||
using namespace AMDGPU::RuntimeMD::KernelArg;
|
||||
Metadata::Metadata()
|
||||
: size(0), align(0), pointeeAlign(0), accQual(None),
|
||||
isConst(false), isRestrict(false), isVolatile(false), isPipe(false)
|
||||
{}
|
||||
|
||||
static const char* KindToString(Kind kind) {
|
||||
switch (kind) {
|
||||
case ByValue: return "ByValue";
|
||||
case GlobalBuffer: return "GlobalBuffer";
|
||||
case DynamicSharedPointer: return "DynamicSharedPointer";
|
||||
case Image: return "Image";
|
||||
case Sampler: return "Sampler";
|
||||
case Pipe: return "Pipe";
|
||||
case Queue: return "Queue";
|
||||
case HiddenGlobalOffsetX: return "HiddenGlobalOffsetX";
|
||||
case HiddenGlobalOffsetY: return "HiddenGlobalOffsetY";
|
||||
case HiddenGlobalOffsetZ: return "HiddenGlobalOffsetZ";
|
||||
case HiddenPrintfBuffer: return "HiddenPrintfBuffer";
|
||||
case HiddenDefaultQueue: return "HiddenDefaultQueue";
|
||||
case HiddenCompletionAction: return "HiddenCompletionAction";
|
||||
case HiddenNone: return "HiddenNone";
|
||||
default: return "<UnknownType>";
|
||||
}
|
||||
}
|
||||
|
||||
static const char* ValueTypeToString(ValueType valueType) {
|
||||
switch (valueType) {
|
||||
case Struct: return "Struct";
|
||||
case I8: return "I8";
|
||||
case U8: return "U8";
|
||||
case I16: return "I16";
|
||||
case U16: return "U16";
|
||||
case F16: return "F16";
|
||||
case I32: return "I32";
|
||||
case U32: return "U32";
|
||||
case F32: return "F32";
|
||||
case I64: return "I64";
|
||||
case U64: return "U64";
|
||||
case F64: return "F64";
|
||||
default: return "<UnknownValueType>";
|
||||
}
|
||||
}
|
||||
|
||||
static const char* AccessQualToString(AccessQualifer accessQual) {
|
||||
switch (accessQual) {
|
||||
case None: return "None";
|
||||
case ReadOnly: return "ReadOnly";
|
||||
case WriteOnly: return "WriteOnly";
|
||||
case ReadWrite: return "ReadWrite";
|
||||
default: return "<UnknownTypeQual>";
|
||||
}
|
||||
}
|
||||
|
||||
bool Metadata::ReadValue(std::istream& in, AMDGPU::RuntimeMD::Key key) {
|
||||
using namespace AMDGPU::RuntimeMD;
|
||||
|
||||
switch (key) {
|
||||
case KeyArgSize: return Read(in, size);
|
||||
case KeyArgAlign: return Read(in, align);
|
||||
case KeyArgTypeName: return Read(in, typeName);
|
||||
case KeyArgName: return Read(in, name);
|
||||
case KeyArgKind: return Read(in, kind);
|
||||
case KeyArgValueType: return Read(in, valueType);
|
||||
case KeyArgPointeeAlign: return Read(in, pointeeAlign);
|
||||
case KeyArgAddrQual: return Read(in, addrQual);
|
||||
case KeyArgAccQual: return Read(in, accQual);
|
||||
case KeyArgIsConst: isConst = true; return true;
|
||||
case KeyArgIsRestrict: isRestrict = true; return true;
|
||||
case KeyArgIsVolatile: isVolatile = true; return true;
|
||||
case KeyArgIsPipe: isPipe = true; return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Metadata::Print(std::ostream& out) {
|
||||
out
|
||||
<< "Kind: " << KindToString(kind);
|
||||
if (kind == ByValue) {
|
||||
out << " ValueType:" << ValueTypeToString(valueType);
|
||||
}
|
||||
if (isConst) { out << " Const"; }
|
||||
if (isRestrict) { out << " Restrict"; }
|
||||
if (isVolatile) { out << " Volatile"; }
|
||||
if (isPipe) { out << " Pipe"; }
|
||||
if (kind == Image || kind == Pipe) {
|
||||
out << " Access: " << AccessQualToString(accQual);
|
||||
}
|
||||
if (kind == GlobalBuffer || kind == DynamicSharedPointer) {
|
||||
out
|
||||
<< " Address: " << (unsigned) addrQual;
|
||||
}
|
||||
out
|
||||
<< " Size: " << size
|
||||
<< " Align: " << align;
|
||||
if (kind == DynamicSharedPointer) {
|
||||
out << " Pointee Align: " << pointeeAlign;
|
||||
}
|
||||
if (!typeName.empty()) {
|
||||
out << " Type Name: \"" << typeName << "\"";
|
||||
}
|
||||
if (!name.empty()) {
|
||||
out << " Name: \"" << name << "\"";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
Metadata::Metadata()
|
||||
: mdVersion(UINT8_MAX), mdRevision(UINT8_MAX),
|
||||
language((AMDGPU::RuntimeMD::Language) UINT8_MAX), languageVersion(UINT16_MAX),
|
||||
hasRequiredWorkgroupSize(false),
|
||||
hasWorkgroupSizeHint(false),
|
||||
hasVectorTypeHint(false),
|
||||
hasKernelIndex(false),
|
||||
hasMinWavesPerSIMD(false), hasMaxWavesPerSIMD(false),
|
||||
hasFlatWorkgroupSizeLimits(false),
|
||||
hasMaxWorkgroupSize(false),
|
||||
isNoPartialWorkgroups(false)
|
||||
{}
|
||||
|
||||
void Metadata::SetCommon(uint8_t mdVersion, uint8_t mdRevision,
|
||||
AMDGPU::RuntimeMD::Language language, uint16_t languageVersion) {
|
||||
this->mdVersion = mdVersion;
|
||||
this->mdRevision = mdRevision;
|
||||
this->language = language;
|
||||
this->languageVersion = languageVersion;
|
||||
}
|
||||
|
||||
const KernelArg::Metadata& Metadata::GetKernelArgMetadata(size_t index) const {
|
||||
assert((index < args.size()) && "kernel argument index too big");
|
||||
return args[index];
|
||||
}
|
||||
|
||||
bool Metadata::ReadValue(std::istream& in, AMDGPU::RuntimeMD::Key key) {
|
||||
using namespace AMDGPU::RuntimeMD;
|
||||
|
||||
KernelArg::Metadata* arg = args.empty() ? nullptr : &args.back();
|
||||
|
||||
switch (key) {
|
||||
case KeyKernelName:
|
||||
hasName = true;
|
||||
return Read(in, name);
|
||||
case KeyArgBegin:
|
||||
args.resize(args.size() + 1);
|
||||
break;
|
||||
case KeyArgEnd:
|
||||
// Verified in Program::Metadata::Read.
|
||||
break;
|
||||
case KeyArgSize:
|
||||
case KeyArgAlign:
|
||||
case KeyArgTypeName:
|
||||
case KeyArgName:
|
||||
case KeyArgKind:
|
||||
case KeyArgValueType:
|
||||
case KeyArgPointeeAlign:
|
||||
case KeyArgAddrQual:
|
||||
case KeyArgAccQual:
|
||||
case KeyArgIsConst:
|
||||
case KeyArgIsRestrict:
|
||||
case KeyArgIsVolatile:
|
||||
case KeyArgIsPipe:
|
||||
if (!arg) { return false; }
|
||||
if (!arg->ReadValue(in, key)) { return false; }
|
||||
break;
|
||||
case KeyReqdWorkGroupSize:
|
||||
hasRequiredWorkgroupSize = true;
|
||||
return Read3(in, requiredWorkgroupSize);
|
||||
case KeyWorkGroupSizeHint:
|
||||
hasWorkgroupSizeHint = true;
|
||||
return Read3(in, workgroupSizeHint);
|
||||
case KeyVecTypeHint:
|
||||
hasVectorTypeHint = true;
|
||||
return Read(in, vectorTypeHint);
|
||||
case KeyKernelIndex:
|
||||
hasKernelIndex = true;
|
||||
return Read(in, kernelIndex);
|
||||
case KeyMinWavesPerSIMD:
|
||||
hasMinWavesPerSIMD = true;
|
||||
return Read(in, minWavesPerSimd);
|
||||
case KeyMaxWavesPerSIMD:
|
||||
hasMaxWavesPerSIMD = true;
|
||||
return Read(in, maxWavesPerSimd);
|
||||
case KeyFlatWorkGroupSizeLimits:
|
||||
hasFlatWorkgroupSizeLimits = true;
|
||||
return
|
||||
Read(in, minFlatWorkgroupSize) &&
|
||||
Read(in, maxFlatWorkgroupSize);
|
||||
case KeyMaxWorkGroupSize:
|
||||
hasMaxWorkgroupSize = true;
|
||||
return Read3(in, maxWorkgroupSize);
|
||||
case KeyNoPartialWorkGroups:
|
||||
isNoPartialWorkgroups = true;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char* LanguageToString(AMDGPU::RuntimeMD::Language language) {
|
||||
using namespace AMDGPU::RuntimeMD;
|
||||
switch (language) {
|
||||
case OpenCL_C: return "OpenCL C";
|
||||
case HCC: return "HCC";
|
||||
case OpenMP: return "OpenMP";
|
||||
case OpenCL_CPP: return "OpenCL C++";
|
||||
default: return "<Unknown language>";
|
||||
}
|
||||
}
|
||||
|
||||
void Metadata::Print(std::ostream& out) {
|
||||
using namespace metadata_output;
|
||||
|
||||
out << " Kernel";
|
||||
if (HasName()) {
|
||||
out << " " << name;
|
||||
}
|
||||
out <<
|
||||
" (" << LanguageToString(language) << ' ' << (int) languageVersion <<
|
||||
"), metadata " << (int) mdVersion << '.' << (int) mdRevision << std::endl;
|
||||
if (hasRequiredWorkgroupSize) {
|
||||
out << " Required workgroup size: " << dim3(requiredWorkgroupSize) << std::endl;
|
||||
}
|
||||
if (hasWorkgroupSizeHint) {
|
||||
out << " Workgroup size hint: " << dim3(workgroupSizeHint) << std::endl;
|
||||
}
|
||||
if (hasVectorTypeHint) {
|
||||
out << " Vector type hint: " << vectorTypeHint << std::endl;
|
||||
}
|
||||
if (hasKernelIndex) {
|
||||
out << " Kernel iIndex: " << kernelIndex << std::endl;
|
||||
}
|
||||
if (hasMinWavesPerSIMD) {
|
||||
out << " Min waves per SIMD: " << minWavesPerSimd << std::endl;
|
||||
}
|
||||
if (hasMaxWavesPerSIMD) {
|
||||
out << " Max waves per SIMD: " << maxWavesPerSimd << std::endl;
|
||||
}
|
||||
if (hasFlatWorkgroupSizeLimits) {
|
||||
out << " Min flat workgroup size: " << minFlatWorkgroupSize << std::endl;
|
||||
out << " Max flat workgroup size: " << maxFlatWorkgroupSize << std::endl;
|
||||
}
|
||||
if (isNoPartialWorkgroups) {
|
||||
out << " No partial workgroups" << std::endl;
|
||||
}
|
||||
out << " Arguments" << std::endl;
|
||||
for (uint32_t i = 0; i < args.size(); ++i) {
|
||||
out << " " << i << ": ";
|
||||
args[i].Print(out);
|
||||
out << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Program {
|
||||
bool Metadata::ReadFrom(std::istream& in) {
|
||||
using namespace AMDGPU::RuntimeMD;
|
||||
Kernel::Metadata* kernel = nullptr;
|
||||
bool arg = false;
|
||||
uint8_t mdVersion = UINT8_MAX, mdRevision = UINT8_MAX;
|
||||
Language language = (Language) UINT8_MAX; uint16_t languageVersion = UINT16_MAX;
|
||||
while (in.tellg() != (std::streampos) -1 && !in.eof()) {
|
||||
Key key;
|
||||
if (!Read(in, key)) {
|
||||
if (in.eof()) { break; }
|
||||
return false;
|
||||
}
|
||||
switch (key) {
|
||||
case KeyNull: break; // Ignore
|
||||
case KeyMDVersion:
|
||||
if (!Read(in, mdRevision) ||
|
||||
!Read(in, mdVersion)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case KeyLanguage:
|
||||
if (!Read(in, language)) { return false; }
|
||||
break;
|
||||
case KeyLanguageVersion:
|
||||
if (!Read(in, languageVersion)) { return false; }
|
||||
break;
|
||||
case KeyKernelBegin:
|
||||
if (kernel) { return false; }
|
||||
kernels.resize(kernels.size() + 1);
|
||||
kernel = &kernels.back();
|
||||
kernel->SetCommon(mdVersion, mdRevision, language, languageVersion);
|
||||
break;
|
||||
case KeyKernelEnd:
|
||||
if (!kernel) { return false; }
|
||||
kernel = nullptr;
|
||||
break;
|
||||
case KeyArgBegin:
|
||||
if (!kernel || arg) { return false; }
|
||||
arg = true;
|
||||
if (!kernel->ReadValue(in, key)) { return false; }
|
||||
break;
|
||||
case KeyArgEnd:
|
||||
if (!kernel || !arg) { return false; }
|
||||
arg = false;
|
||||
break;
|
||||
case KeyPrintfInfo: {
|
||||
std::string formatString;
|
||||
if (!Read(in, formatString)) { return false; }
|
||||
printfInfo.push_back(formatString);
|
||||
break;
|
||||
}
|
||||
case KeyKernelName:
|
||||
case KeyArgSize:
|
||||
case KeyArgAlign:
|
||||
case KeyArgTypeName:
|
||||
case KeyArgName:
|
||||
case KeyArgKind:
|
||||
case KeyArgValueType:
|
||||
case KeyArgPointeeAlign:
|
||||
case KeyArgAddrQual:
|
||||
case KeyArgAccQual:
|
||||
case KeyArgIsConst:
|
||||
case KeyArgIsRestrict:
|
||||
case KeyArgIsVolatile:
|
||||
case KeyArgIsPipe:
|
||||
case KeyReqdWorkGroupSize:
|
||||
case KeyWorkGroupSizeHint:
|
||||
case KeyVecTypeHint:
|
||||
case KeyKernelIndex:
|
||||
case KeyMinWavesPerSIMD:
|
||||
case KeyMaxWavesPerSIMD:
|
||||
case KeyFlatWorkGroupSizeLimits:
|
||||
case KeyMaxWorkGroupSize:
|
||||
case KeyNoPartialWorkGroups:
|
||||
if (!kernel) { return false; }
|
||||
if (!kernel->ReadValue(in, key)) { return false; }
|
||||
break;
|
||||
default:
|
||||
//out << "Unsupported metadata key: " << key << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const Kernel::Metadata& Metadata::GetKernelMetadata(size_t index) const {
|
||||
assert(kernels.size() && "kernel metadata not found");
|
||||
assert((index < kernels.size()) && "kernel index too big");
|
||||
|
||||
return kernels[index];
|
||||
}
|
||||
|
||||
size_t Metadata::KernelIndexByName(const std::string& name) const {
|
||||
assert(kernels.size() && "kernel metadata not found");
|
||||
|
||||
size_t idx = 0;
|
||||
for (auto kernel : kernels) {
|
||||
if (kernel.Name().compare(name) == 0) { return idx; }
|
||||
idx++;
|
||||
}
|
||||
return kernels.max_size();
|
||||
}
|
||||
|
||||
bool Metadata::ReadFrom(const void* buffer, size_t size) {
|
||||
std::istringstream is(std::string(static_cast<const char*>(buffer), size));
|
||||
if (!ReadFrom(is)) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
void Metadata::Print(std::ostream& out) {
|
||||
out << "AMDGPU runtime metadata (" << kernels.size() << " kernel";
|
||||
if (kernels.size() > 1) out << "s";
|
||||
if (printfInfo.size() > 0) {
|
||||
out << ", " << printfInfo.size() << " printf info string";
|
||||
if (printfInfo.size() > 1) out << "s";
|
||||
}
|
||||
out << "):" << std::endl;
|
||||
for (Kernel::Metadata& kernel : kernels) {
|
||||
kernel.Print(out);
|
||||
}
|
||||
for (auto str : printfInfo) {
|
||||
out << " PrintfInfo \"" << str << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace metadata_output {
|
||||
std::ostream& operator<<(std::ostream& out, const dim3& d) {
|
||||
out << "(" << d.data[0] << ", " << d.data[1] << ", " << d.data[2] << ")";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// The University of Illinois/NCSA
|
||||
// Open Source License (NCSA)
|
||||
//
|
||||
// Copyright (c) 2014-2016, Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// Developed by:
|
||||
//
|
||||
// AMD Research and AMD HSA Software Development
|
||||
//
|
||||
// Advanced Micro Devices, Inc.
|
||||
//
|
||||
// www.amd.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal with the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimers.
|
||||
// - Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimers in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// - Neither the names of Advanced Micro Devices, Inc,
|
||||
// nor the names of its contributors may be used to endorse or promote
|
||||
// products derived from this Software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS WITH THE SOFTWARE.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef AMDGPU_METADATA_HPP_
|
||||
#define AMDGPU_METADATA_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
#undef None
|
||||
#include "AMDGPURuntimeMetadata.h"
|
||||
|
||||
namespace amd {
|
||||
namespace hsa {
|
||||
namespace code {
|
||||
|
||||
namespace KernelArg {
|
||||
class Metadata {
|
||||
private:
|
||||
uint32_t size;
|
||||
uint32_t align;
|
||||
uint32_t pointeeAlign;
|
||||
std::string typeName;
|
||||
std::string name;
|
||||
AMDGPU::RuntimeMD::KernelArg::Kind kind;
|
||||
AMDGPU::RuntimeMD::KernelArg::ValueType valueType;
|
||||
uint8_t addrQual;
|
||||
AMDGPU::RuntimeMD::KernelArg::AccessQualifer accQual;
|
||||
bool isConst, isRestrict, isVolatile, isPipe;
|
||||
|
||||
public:
|
||||
Metadata();
|
||||
uint32_t Size() const { return size; }
|
||||
uint32_t Align() const { return align; }
|
||||
uint32_t PointeeAlign() const { return pointeeAlign; }
|
||||
const std::string& TypeName() const { return typeName; }
|
||||
const std::string& Name() const { return name; }
|
||||
AMDGPU::RuntimeMD::KernelArg::Kind Kind() const { return kind; }
|
||||
AMDGPU::RuntimeMD::KernelArg::ValueType ValueType() const { return valueType; }
|
||||
uint8_t AddrQual() const { return addrQual; }
|
||||
AMDGPU::RuntimeMD::KernelArg::AccessQualifer AccQual() const { return accQual; }
|
||||
bool IsConst() const { return isConst; }
|
||||
bool IsRestrict() const { return isRestrict; }
|
||||
bool IsVolatile() const { return isVolatile; }
|
||||
bool IsPipe() const { return isPipe; }
|
||||
|
||||
bool ReadValue(std::istream& in, AMDGPU::RuntimeMD::Key key);
|
||||
void Print(std::ostream& out);
|
||||
};
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
class Metadata {
|
||||
private:
|
||||
uint8_t mdVersion, mdRevision;
|
||||
AMDGPU::RuntimeMD::Language language;
|
||||
uint16_t languageVersion;
|
||||
std::vector<KernelArg::Metadata> args;
|
||||
|
||||
unsigned hasName : 1;
|
||||
unsigned hasRequiredWorkgroupSize : 1;
|
||||
unsigned hasWorkgroupSizeHint : 1;
|
||||
unsigned hasVectorTypeHint : 1;
|
||||
unsigned hasKernelIndex : 1;
|
||||
unsigned hasMinWavesPerSIMD : 1, hasMaxWavesPerSIMD : 1;
|
||||
unsigned hasFlatWorkgroupSizeLimits : 1;
|
||||
unsigned hasMaxWorkgroupSize : 1;
|
||||
unsigned isNoPartialWorkgroups : 1;
|
||||
|
||||
std::string name;
|
||||
uint32_t requiredWorkgroupSize[3];
|
||||
uint32_t workgroupSizeHint[3];
|
||||
std::string vectorTypeHint;
|
||||
|
||||
uint32_t kernelIndex;
|
||||
uint32_t numSgprs, numVgprs;
|
||||
uint32_t minWavesPerSimd, maxWavesPerSimd;
|
||||
uint32_t minFlatWorkgroupSize, maxFlatWorkgroupSize;
|
||||
uint32_t maxWorkgroupSize[3];
|
||||
|
||||
public:
|
||||
Metadata();
|
||||
|
||||
bool HasName() const { return hasName; }
|
||||
bool HasRequiredWorkgroupSize() const { return hasRequiredWorkgroupSize; }
|
||||
bool HasWorkgroupSizeHint() const { return hasWorkgroupSizeHint; }
|
||||
bool HasVecTypeHint() const { return hasVectorTypeHint; }
|
||||
bool HasKernelIndex() const { return hasKernelIndex; }
|
||||
bool HasMinWavesPerSIMD() const { return hasMinWavesPerSIMD; }
|
||||
bool HasMaxWavesPerSIMD() const { return hasMaxWavesPerSIMD; }
|
||||
bool HasFlatWorkgroupSizeLimits() const { return hasFlatWorkgroupSizeLimits; }
|
||||
bool HasMaxWorkgroupSize() const { return hasMaxWorkgroupSize; }
|
||||
|
||||
size_t KernelArgCount() const { return args.size(); }
|
||||
const KernelArg::Metadata& GetKernelArgMetadata(size_t index) const;
|
||||
|
||||
const std::string& Name() const { return name; }
|
||||
const uint32_t* RequiredWorkgroupSize() const { return hasRequiredWorkgroupSize ? requiredWorkgroupSize : nullptr; }
|
||||
const uint32_t* WorkgroupSizeHint() const { return hasWorkgroupSizeHint ? workgroupSizeHint : nullptr; }
|
||||
const std::string& VecTypeHint() const { return vectorTypeHint; }
|
||||
uint32_t KernelIndex() const { return hasKernelIndex ? kernelIndex : UINT32_MAX; }
|
||||
uint32_t MinWavesPerSIMD() const { return hasMinWavesPerSIMD ? minWavesPerSimd : UINT32_MAX; }
|
||||
uint32_t MaxWavesPerSIMD() const { return hasMaxWavesPerSIMD ? maxWavesPerSimd : UINT32_MAX; }
|
||||
uint32_t MinFlatWorkgroupSize() const { return hasFlatWorkgroupSizeLimits ? minFlatWorkgroupSize : UINT32_MAX; }
|
||||
uint32_t MaxFlatWorkgroupSize() const { return hasFlatWorkgroupSizeLimits ? maxFlatWorkgroupSize : UINT32_MAX; }
|
||||
const uint32_t* MaxWorkgroupSize() const { return hasMaxWorkgroupSize ? maxWorkgroupSize : 0; }
|
||||
bool IsNoPartialWorkgroups() const { return isNoPartialWorkgroups; }
|
||||
|
||||
void SetCommon(uint8_t mdVersion, uint8_t mdRevision, AMDGPU::RuntimeMD::Language language, uint16_t languageVersion);
|
||||
bool ReadValue(std::istream& in, AMDGPU::RuntimeMD::Key key);
|
||||
void Print(std::ostream& out);
|
||||
};
|
||||
}
|
||||
|
||||
namespace Program {
|
||||
class Metadata {
|
||||
private:
|
||||
uint16_t version;
|
||||
std::vector<Kernel::Metadata> kernels;
|
||||
std::vector<std::string> printfInfo;
|
||||
|
||||
public:
|
||||
size_t KernelCount() const { return kernels.size(); }
|
||||
const Kernel::Metadata& GetKernelMetadata(size_t index) const;
|
||||
size_t KernelIndexByName(const std::string& name) const;
|
||||
const std::vector<std::string>& PrintfInfo() const { return printfInfo; }
|
||||
|
||||
bool ReadFrom(std::istream& in);
|
||||
bool ReadFrom(const void* buffer, size_t size);
|
||||
void Print(std::ostream& out);
|
||||
};
|
||||
}
|
||||
|
||||
namespace metadata_output {
|
||||
|
||||
struct dim3 {
|
||||
uint32_t* data;
|
||||
|
||||
dim3(uint32_t* data_)
|
||||
: data(data_) {}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const dim3& d);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // AMDGPU_METADATA_HPP_
|
||||
@@ -5,9 +5,6 @@
|
||||
#include "rockernel.hpp"
|
||||
#include "SCHSAInterface.h"
|
||||
#include "amd_hsa_kernel_code.h"
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
#include "amdgpu_metadata.hpp"
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -17,9 +14,9 @@ namespace roc {
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
static inline ROC_ARG_TYPE
|
||||
GetKernelArgType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgType(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
switch (lcArg.Kind()) {
|
||||
switch (lcArg.Kind) {
|
||||
case AMDGPU::RuntimeMD::KernelArg::GlobalBuffer:
|
||||
case AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer:
|
||||
return ROC_ARGTYPE_POINTER;
|
||||
@@ -92,9 +89,9 @@ GetKernelArgType(const aclArgData* argInfo)
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
static inline size_t
|
||||
GetKernelArgAlignment(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgAlignment(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
return lcArg.Align();
|
||||
return lcArg.Align;
|
||||
}
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
@@ -135,10 +132,10 @@ GetKernelArgAlignment(const aclArgData* argInfo)
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
static inline size_t
|
||||
GetKernelArgPointeeAlignment(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgPointeeAlignment(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
uint32_t align = lcArg.PointeeAlign();
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
uint32_t align = lcArg.PointeeAlign;
|
||||
if (align == 0) {
|
||||
LogWarning("Missing DynamicSharedPointer alignment");
|
||||
align = 128; /* worst case alignment */;
|
||||
@@ -160,11 +157,11 @@ GetKernelArgPointeeAlignment(const aclArgData* argInfo)
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
static inline ROC_ACCESS_TYPE
|
||||
GetKernelArgAccessType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelArgAccessType(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::Image) {
|
||||
switch (lcArg.AccQual()) {
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::Image) {
|
||||
switch (lcArg.AccQual) {
|
||||
case AMDGPU::RuntimeMD::KernelArg::ReadOnly:
|
||||
return ROC_ACCESS_TYPE_RO;
|
||||
case AMDGPU::RuntimeMD::KernelArg::WriteOnly:
|
||||
@@ -204,23 +201,23 @@ GetKernelArgAccessType(const aclArgData* argInfo)
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
static inline ROC_ADDRESS_QUALIFIER
|
||||
GetKernelAddrQual(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelAddrQual(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
return ROC_ADDRESS_LOCAL;
|
||||
}
|
||||
else if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer) {
|
||||
if (lcArg.AddrQual() == AMDGPU::RuntimeMD::KernelArg::Global) {
|
||||
else if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer) {
|
||||
if (lcArg.AddrQual == AMDGPU::RuntimeMD::KernelArg::Global) {
|
||||
return ROC_ADDRESS_GLOBAL;
|
||||
}
|
||||
else if (lcArg.AddrQual() == AMDGPU::RuntimeMD::KernelArg::Constant) {
|
||||
else if (lcArg.AddrQual == AMDGPU::RuntimeMD::KernelArg::Constant) {
|
||||
return ROC_ADDRESS_CONSTANT;
|
||||
}
|
||||
LogError("Unsupported address type");
|
||||
return ROC_ADDRESS_ERROR;
|
||||
}
|
||||
else if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::Image
|
||||
|| lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::Sampler) {
|
||||
else if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::Image
|
||||
|| lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::Sampler) {
|
||||
return ROC_ADDRESS_GLOBAL;
|
||||
}
|
||||
return ROC_ADDRESS_ERROR;
|
||||
@@ -257,15 +254,15 @@ GetKernelAddrQual(const aclArgData* argInfo)
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
static inline ROC_DATA_TYPE
|
||||
GetKernelDataType(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetKernelDataType(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
aclArgDataType dataType;
|
||||
|
||||
if (lcArg.Kind() != AMDGPU::RuntimeMD::KernelArg::ByValue) {
|
||||
if (lcArg.Kind != AMDGPU::RuntimeMD::KernelArg::ByValue) {
|
||||
return ROC_DATATYPE_ERROR;
|
||||
}
|
||||
|
||||
switch (lcArg.ValueType()) {
|
||||
switch (lcArg.ValueType) {
|
||||
case AMDGPU::RuntimeMD::KernelArg::I8:
|
||||
return ROC_DATATYPE_S8;
|
||||
case AMDGPU::RuntimeMD::KernelArg::I16:
|
||||
@@ -494,18 +491,18 @@ GetOclAccessQual(const Kernel::Argument* arg)
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
static inline cl_kernel_arg_type_qualifier
|
||||
GetOclTypeQual(const amd::hsa::code::KernelArg::Metadata& lcArg)
|
||||
GetOclTypeQual(const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg)
|
||||
{
|
||||
cl_kernel_arg_type_qualifier rv = CL_KERNEL_ARG_TYPE_NONE;
|
||||
if (lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind() == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
if (lcArg.IsVolatile()) {
|
||||
if (lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::GlobalBuffer
|
||||
|| lcArg.Kind == AMDGPU::RuntimeMD::KernelArg::DynamicSharedPointer) {
|
||||
if (lcArg.IsVolatile) {
|
||||
rv |= CL_KERNEL_ARG_TYPE_VOLATILE;
|
||||
}
|
||||
if (lcArg.IsRestrict()) {
|
||||
if (lcArg.IsRestrict) {
|
||||
rv |= CL_KERNEL_ARG_TYPE_RESTRICT;
|
||||
}
|
||||
if (lcArg.IsConst()) {
|
||||
if (lcArg.IsConst) {
|
||||
rv |= CL_KERNEL_ARG_TYPE_CONST;
|
||||
}
|
||||
}
|
||||
@@ -610,21 +607,21 @@ Kernel::initArguments(const aclArgData* aclArg)
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
void
|
||||
Kernel::initArguments_LC(const amd::hsa::code::Kernel::Metadata& kernelMD)
|
||||
Kernel::initArguments_LC(const AMDGPU::RuntimeMD::Kernel::Metadata& kernelMD)
|
||||
{
|
||||
device::Kernel::parameters_t params;
|
||||
|
||||
size_t offset = 0;
|
||||
|
||||
for (size_t i = 0; i < kernelMD.KernelArgCount(); ++i) {
|
||||
const amd::hsa::code::KernelArg::Metadata& lcArg =
|
||||
kernelMD.GetKernelArgMetadata(i);
|
||||
for (size_t i = 0; i < kernelMD.Args.size(); ++i) {
|
||||
const AMDGPU::RuntimeMD::KernelArg::Metadata& lcArg =
|
||||
kernelMD.Args[i];
|
||||
|
||||
// Initialize HSAIL kernel argument
|
||||
Kernel::Argument* arg = new Kernel::Argument;
|
||||
arg->name_ = lcArg.Name();
|
||||
arg->typeName_ = lcArg.TypeName();
|
||||
arg->size_ = lcArg.Size();
|
||||
arg->name_ = lcArg.Name;
|
||||
arg->typeName_ = lcArg.TypeName;
|
||||
arg->size_ = lcArg.Size;
|
||||
arg->type_ = GetKernelArgType(lcArg);
|
||||
arg->addrQual_ = GetKernelAddrQual(lcArg);
|
||||
arg->dataType_ = GetKernelDataType(lcArg);
|
||||
@@ -650,12 +647,12 @@ Kernel::initArguments_LC(const amd::hsa::code::Kernel::Metadata& kernelMD)
|
||||
// Initialize Device kernel parameters
|
||||
amd::KernelParameterDescriptor desc;
|
||||
|
||||
desc.name_ = lcArg.Name().c_str();
|
||||
desc.name_ = lcArg.Name.c_str();
|
||||
desc.type_ = GetOclType(arg);
|
||||
desc.addressQualifier_ = GetOclAddrQual(arg);
|
||||
desc.accessQualifier_ = GetOclAccessQual(arg);
|
||||
desc.typeQualifier_ = GetOclTypeQual(lcArg);
|
||||
desc.typeName_ = lcArg.TypeName().c_str();
|
||||
desc.typeName_ = lcArg.TypeName.c_str();
|
||||
|
||||
// Make a check if it is local or global
|
||||
if (desc.addressQualifier_ == CL_KERNEL_ARG_ADDRESS_LOCAL) {
|
||||
@@ -700,19 +697,27 @@ Kernel::Kernel(
|
||||
kernargSegmentAlignment_(kernargSegmentAlignment) {}
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
static const AMDGPU::RuntimeMD::Kernel::Metadata* FindKernelMetadata(const AMDGPU::RuntimeMD::Program::Metadata* programMD, const std::string& name) {
|
||||
for (const AMDGPU::RuntimeMD::Kernel::Metadata& kernelMD : programMD->Kernels) {
|
||||
if (kernelMD.Name == name) { return &kernelMD; }
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Kernel::init_LC()
|
||||
{
|
||||
hsa_agent_t hsaDevice = program_->hsaDevice();
|
||||
|
||||
// Pull out metadata from the ELF
|
||||
const amd::hsa::code::Program::Metadata* runtimeMD = program_->metadata();
|
||||
if (!runtimeMD) {
|
||||
const AMDGPU::RuntimeMD::Program::Metadata* programMD = program_->metadata();
|
||||
assert(programMD != nullptr);
|
||||
|
||||
const AMDGPU::RuntimeMD::Kernel::Metadata* kernelMD = FindKernelMetadata(programMD, name());
|
||||
if (kernelMD == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t idx = runtimeMD->KernelIndexByName(name());
|
||||
const amd::hsa::code::Kernel::Metadata& kernelMD = runtimeMD->GetKernelMetadata(idx);
|
||||
initArguments_LC(kernelMD);
|
||||
initArguments_LC(*kernelMD);
|
||||
|
||||
//Set the workgroup information for the kernel
|
||||
memset(&workGroupInfo_, 0, sizeof(workGroupInfo_));
|
||||
@@ -721,22 +726,22 @@ bool Kernel::init_LC()
|
||||
workGroupInfo_.availableSGPRs_ = 0;
|
||||
workGroupInfo_.availableVGPRs_ = 0;
|
||||
|
||||
if (kernelMD.HasRequiredWorkgroupSize()) {
|
||||
const uint32_t* requiredWorkgroupSize = kernelMD.RequiredWorkgroupSize();
|
||||
if (!kernelMD->ReqdWorkGroupSize.empty()) {
|
||||
const auto& requiredWorkgroupSize = kernelMD->ReqdWorkGroupSize;
|
||||
workGroupInfo_.compileSize_[0] = requiredWorkgroupSize[0];
|
||||
workGroupInfo_.compileSize_[1] = requiredWorkgroupSize[1];
|
||||
workGroupInfo_.compileSize_[2] = requiredWorkgroupSize[2];
|
||||
}
|
||||
|
||||
if (kernelMD.HasWorkgroupSizeHint()) {
|
||||
const uint32_t* workgroupSizeHint = kernelMD.WorkgroupSizeHint();
|
||||
if (!kernelMD->WorkGroupSizeHint.empty()) {
|
||||
const auto& workgroupSizeHint = kernelMD->WorkGroupSizeHint;
|
||||
workGroupInfo_.compileSizeHint_[0] = workgroupSizeHint[0];
|
||||
workGroupInfo_.compileSizeHint_[1] = workgroupSizeHint[1];
|
||||
workGroupInfo_.compileSizeHint_[2] = workgroupSizeHint[2];
|
||||
}
|
||||
|
||||
if (kernelMD.HasVecTypeHint()) {
|
||||
workGroupInfo_.compileVecTypeHint_ = kernelMD.VecTypeHint().c_str();
|
||||
if (!kernelMD->VecTypeHint.empty()) {
|
||||
workGroupInfo_.compileVecTypeHint_ = kernelMD->VecTypeHint.c_str();
|
||||
}
|
||||
|
||||
uint32_t wavefront_size = 0;
|
||||
@@ -784,7 +789,7 @@ bool Kernel::init_LC()
|
||||
workGroupInfo_.size_ = program_->dev().info().maxWorkGroupSize_;
|
||||
}
|
||||
|
||||
initPrintf_LC(runtimeMD->PrintfInfo());
|
||||
initPrintf_LC(programMD->PrintfInfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ private:
|
||||
void initArguments(const aclArgData* aclArg);
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
//! Initializes Hsail Argument metadata and info for LC
|
||||
void initArguments_LC(const amd::hsa::code::Kernel::Metadata& kernelMD);
|
||||
void initArguments_LC(const AMDGPU::RuntimeMD::Kernel::Metadata& kernelMD);
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
//! Initializes HSAIL Printf metadata and info
|
||||
|
||||
@@ -930,16 +930,11 @@ HSAILProgram::setKernels_LC(amd::option::Options *options, void* binary, size_t
|
||||
if (note->n_type == 7 /*AMDGPU::PT_NOTE::NT_AMDGPU_HSA_RUNTIME_METADATA*/
|
||||
&& note->n_namesz == sizeof "AMD"
|
||||
&& !memcmp(name, "AMD", note->n_namesz)) {
|
||||
metadata_ = new amd::hsa::code::Program::Metadata();
|
||||
if (metadata_ && metadata_->ReadFrom(desc,note->n_descsz)) {
|
||||
// We've found and loaded the runtime metadata, exit the
|
||||
// note record loop now.
|
||||
break;
|
||||
}
|
||||
|
||||
buildLog_ += "Error while parsing ELF program binary " \
|
||||
"runtime metadata section\n";
|
||||
return false;
|
||||
std::string metadataStr((const char *) desc, (size_t) note->n_descsz);
|
||||
metadata_ = new AMDGPU::RuntimeMD::Program::Metadata(metadataStr);
|
||||
// We've found and loaded the runtime metadata, exit the
|
||||
// note record loop now.
|
||||
break;
|
||||
}
|
||||
ptr += sizeof(*note)
|
||||
+ amd::alignUp(note->n_namesz, sizeof(int))
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "HSAILItems.h"
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
#include "amdgpu_metadata.hpp"
|
||||
#include "AMDGPURuntimeMetadata.h"
|
||||
#include "driver/AmdCompiler.h"
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
//! Returns the program metadata.
|
||||
const amd::hsa::code::Program::Metadata* metadata() const { return metadata_; }
|
||||
const AMDGPU::RuntimeMD::Program::Metadata* metadata() const { return metadata_; }
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
//! Return a typecasted GPU device
|
||||
@@ -169,7 +169,7 @@ private:
|
||||
hsa_executable_t hsaExecutable_; //!< Handle to HSA executable
|
||||
|
||||
#if defined(WITH_LIGHTNING_COMPILER)
|
||||
amd::hsa::code::Program::Metadata* metadata_; //!< Runtime metadata
|
||||
AMDGPU::RuntimeMD::Program::Metadata* metadata_; //!< Runtime metadata
|
||||
//! Return a new transient compiler instance.
|
||||
static std::auto_ptr<amd::opencl_driver::Compiler> newCompilerInstance();
|
||||
#endif // defined(WITH_LIGHTNING_COMPILER)
|
||||
|
||||
Ссылка в новой задаче
Block a user