Zebin: Add support for querying device globals by host name

This commit adds support for querying global pointers via decorated
names passed in zeInfo.
Related-To: NEO-6734
Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
Kacper Nowak
2022-02-23 11:48:31 +00:00
committed by Compute-Runtime-Automation
parent 999c6424a4
commit 38086029ed
11 changed files with 289 additions and 8 deletions

View File

@@ -242,5 +242,8 @@ std::string constructRelocationsDebugMessage(const Linker::RelocatedSymbolsMap &
constexpr bool shouldIgnoreRelocation(const LinkerInput::RelocationInfo &relocation) {
return LinkerInput::RelocationInfo::Type::PerThreadPayloadOffset == relocation.type;
}
inline bool isDataSegment(const SegmentType &segment) {
return segment == SegmentType::GlobalConstants || segment == SegmentType::GlobalVariables;
}
} // namespace NEO

View File

@@ -157,6 +157,7 @@ namespace ZebinKernelMetadata {
namespace Tags {
static constexpr ConstStringRef kernels("kernels");
static constexpr ConstStringRef version("version");
static constexpr ConstStringRef globalHostAccessTable("global_host_access_table");
namespace Kernel {
static constexpr ConstStringRef name("name");
static constexpr ConstStringRef executionEnv("execution_env");
@@ -278,6 +279,10 @@ static constexpr ConstStringRef hasNonKernelArgStore("has_non_kernel_arg_store")
static constexpr ConstStringRef hasNonKernelArgAtomic("has_non_kernel_arg_atomic");
} // namespace ExperimentalProperties
} // namespace Kernel
namespace GlobalHostAccessTable {
static constexpr ConstStringRef deviceName("device_name");
static constexpr ConstStringRef hostName("host_name");
} // namespace GlobalHostAccessTable
} // namespace Tags
namespace Types {
@@ -529,6 +534,12 @@ struct PerThreadMemoryBufferBaseT {
} // namespace Kernel
namespace GlobalHostAccessTable {
struct globalHostAccessTableT {
std::string deviceName;
std::string hostName;
};
} // namespace GlobalHostAccessTable
} // namespace Types
} // namespace ZebinKernelMetadata

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -664,6 +664,16 @@ inline bool YamlParser::readValueChecked<bool>(const Node &node, bool &outValue)
return true;
}
template <>
inline bool YamlParser::readValueChecked<std::string>(const Node &node, std::string &outValue) const {
const auto &token = tokens[node.value];
if (Token::Type::LiteralString != token.traits.type) {
return false;
}
outValue.resize(token.len);
std::copy(token.pos, token.pos + token.len, outValue.begin());
return true;
}
} // namespace Yaml
} // namespace NEO

View File

@@ -645,6 +645,28 @@ DecodeError readZeInfoPerThreadMemoryBuffers(const NEO::Yaml::YamlParser &parser
return validBuffer ? DecodeError::Success : DecodeError::InvalidBinary;
}
DecodeError readZeInfoGlobalHostAceessTable(const NEO::Yaml::YamlParser &parser, const NEO::Yaml::Node &node,
ZeInfoGlobalHostAccessTables &outDeviceNameToHostTable,
ConstStringRef context,
std::string &outErrReason, std::string &outWarning) {
bool validTable = true;
for (const auto &globalHostAccessNameNd : parser.createChildrenRange(node)) {
outDeviceNameToHostTable.resize(outDeviceNameToHostTable.size() + 1);
for (const auto &globalHostAccessNameMemberNd : parser.createChildrenRange(globalHostAccessNameNd)) {
auto &globalHostAccessMetadata = *outDeviceNameToHostTable.rbegin();
auto key = parser.readKey(globalHostAccessNameMemberNd);
if (NEO::Elf::ZebinKernelMetadata::Tags::GlobalHostAccessTable::deviceName == key) {
validTable &= readZeInfoValueChecked(parser, globalHostAccessNameMemberNd, globalHostAccessMetadata.deviceName, context, outErrReason);
} else if (NEO::Elf::ZebinKernelMetadata::Tags::GlobalHostAccessTable::hostName == key) {
validTable &= readZeInfoValueChecked(parser, globalHostAccessNameMemberNd, globalHostAccessMetadata.hostName, context, outErrReason);
} else {
outWarning.append("DeviceBinaryFormat::Zebin::" + NEO::Elf::SectionsNamesZebin::zeInfo.str() + " : Unknown entry \"" + key.str() + "\" for payload argument in context of " + context.str() + "\n");
}
}
}
return validTable ? DecodeError::Success : DecodeError::InvalidBinary;
}
template <typename ElSize, size_t Len>
bool setVecArgIndicesBasedOnSize(CrossThreadDataOffset (&vec)[Len], size_t vecSize, CrossThreadDataOffset baseOffset) {
switch (vecSize) {
@@ -1276,6 +1298,7 @@ DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo
UniqueNode kernelsSectionNodes;
UniqueNode versionSectionNodes;
UniqueNode globalHostAccessTableNodes;
for (const auto &globalScopeNd : yamlParser.createChildrenRange(*yamlParser.getRoot())) {
auto key = yamlParser.readKey(globalScopeNd);
if (NEO::Elf::ZebinKernelMetadata::Tags::kernels == key) {
@@ -1284,8 +1307,12 @@ DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo
} else if (NEO::Elf::ZebinKernelMetadata::Tags::version == key) {
versionSectionNodes.push_back(&globalScopeNd);
continue;
} else if (NEO::Elf::ZebinKernelMetadata::Tags::globalHostAccessTable == key) {
globalHostAccessTableNodes.push_back(&globalScopeNd);
continue;
} else {
outWarning.append("DeviceBinaryFormat::Zebin::" + NEO::Elf::SectionsNamesZebin::zeInfo.str() + " : Unknown entry \"" + yamlParser.readKey(globalScopeNd).str() + "\" in global scope of " + NEO::Elf::SectionsNamesZebin::zeInfo.str() + "\n");
}
outWarning.append("DeviceBinaryFormat::Zebin::" + NEO::Elf::SectionsNamesZebin::zeInfo.str() + " : Unknown entry \"" + yamlParser.readKey(globalScopeNd).str() + "\" in global scope of " + NEO::Elf::SectionsNamesZebin::zeInfo.str() + "\n");
}
if (versionSectionNodes.size() > 1U) {
@@ -1330,6 +1357,17 @@ DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo
}
}
if (false == globalHostAccessTableNodes.empty()) {
ZeInfoGlobalHostAccessTables globalHostAccessMapping;
auto zeInfoErr = readZeInfoGlobalHostAceessTable(yamlParser, *globalHostAccessTableNodes[0], globalHostAccessMapping, "globalHostAccessTable", outErrReason, outWarning);
if (DecodeError::Success != zeInfoErr) {
return zeInfoErr;
}
for (auto it = globalHostAccessMapping.begin(); it != globalHostAccessMapping.end(); it++) {
dst.globalsDeviceToHostNameMap[it->deviceName] = it->hostName;
}
}
return DecodeError::Success;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -100,6 +100,11 @@ DecodeError readZeInfoPerThreadMemoryBuffers(const NEO::Yaml::YamlParser &parser
ZeInfoPerThreadMemoryBuffers &outPerThreadMemoryBuffers,
ConstStringRef context,
std::string &outErrReason, std::string &outWarning);
using ZeInfoGlobalHostAccessTables = StackVec<NEO::Elf::ZebinKernelMetadata::Types::GlobalHostAccessTable::globalHostAccessTableT, 32>;
DecodeError readZeInfoGlobalHostAceessTable(const NEO::Yaml::YamlParser &parser, const NEO::Yaml::Node &node,
ZeInfoGlobalHostAccessTables &outDeviceNameToHostTable,
ConstStringRef context,
std::string &outErrReason, std::string &outWarning);
NEO::DecodeError populateArgDescriptor(const NEO::Elf::ZebinKernelMetadata::Types::Kernel::PerThreadPayloadArgument::PerThreadPayloadArgumentBaseT &src, NEO::KernelDescriptor &dst, const uint32_t grfSize,
std::string &outErrReason, std::string &outWarning);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -11,6 +11,7 @@
#include <cstddef>
#include <memory>
#include <unordered_map>
#include <vector>
namespace NEO {
@@ -39,6 +40,7 @@ struct ProgramInfo {
GlobalSurfaceInfo globalVariables;
GlobalSurfaceInfo globalStrings;
std::unique_ptr<LinkerInput> linkerInput;
std::unordered_map<std::string, std::string> globalsDeviceToHostNameMap;
std::vector<KernelInfo *> kernelInfos;
Elf::Elf<Elf::EI_CLASS_64> decodedElf;