mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Create input for linker during zebin decoding
Remove code duplication. Parsing zebin elf for relocations and symbols is moved to decodeSingleDeviceBinary. Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:

committed by
Compute-Runtime-Automation

parent
a9bc4de8cf
commit
311b0b0020
@ -396,18 +396,6 @@ bool ModuleTranslationUnit::processUnpackedBinary() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (programInfo.decodedElf.elfFileHeader) {
|
||||
NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
|
||||
|
||||
uint32_t id = 0;
|
||||
for (auto &kernelInfo : this->programInfo.kernelInfos) {
|
||||
nameToKernelId[kernelInfo->kernelDescriptor.kernelMetadata.kernelName] = id;
|
||||
id++;
|
||||
}
|
||||
programInfo.prepareLinkerInputStorage();
|
||||
programInfo.linkerInput->decodeElfSymbolTableAndRelocations(programInfo.decodedElf, nameToKernelId);
|
||||
}
|
||||
|
||||
processDebugData();
|
||||
|
||||
size_t slmNeeded = NEO::getMaxInlineSlmNeeded(programInfo);
|
||||
|
@ -186,18 +186,6 @@ cl_int Program::processGenBinary(const ClDevice &clDevice) {
|
||||
DeviceBinaryFormat singleDeviceBinaryFormat;
|
||||
std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, binary, decodeErrors, decodeWarnings);
|
||||
|
||||
if (isDeviceBinaryFormat<DeviceBinaryFormat::Zebin>(binary.deviceBinary)) {
|
||||
NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
|
||||
|
||||
uint32_t id = 0;
|
||||
for (auto &kernelInfo : programInfo.kernelInfos) {
|
||||
nameToKernelId[kernelInfo->kernelDescriptor.kernelMetadata.kernelName] = id;
|
||||
id++;
|
||||
}
|
||||
programInfo.prepareLinkerInputStorage();
|
||||
programInfo.linkerInput->decodeElfSymbolTableAndRelocations(programInfo.decodedElf, nameToKernelId);
|
||||
}
|
||||
|
||||
if (decodeWarnings.empty() == false) {
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s\n", decodeWarnings.c_str());
|
||||
}
|
||||
|
@ -26,6 +26,10 @@ set(CLOC_LIB_SRCS_LIB
|
||||
${NEO_SHARED_DIRECTORY}/device_binary_format/elf/elf_encoder.cpp
|
||||
${NEO_SHARED_DIRECTORY}/device_binary_format/elf/elf_encoder.h
|
||||
${NEO_SHARED_DIRECTORY}/device_binary_format/elf/ocl_elf.h
|
||||
${NEO_SHARED_DIRECTORY}/device_binary_format/device_binary_formats.h
|
||||
${NEO_SHARED_DIRECTORY}/device_binary_format/yaml/yaml_parser.cpp
|
||||
${NEO_SHARED_DIRECTORY}/device_binary_format/zebin_decoder.cpp
|
||||
${NEO_SHARED_DIRECTORY}/device_binary_format/zebin_decoder.h
|
||||
${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}devices.inl
|
||||
${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}devices_additional.inl
|
||||
${NEO_SHARED_DIRECTORY}/dll/devices/devices_base.inl
|
||||
@ -88,9 +92,6 @@ set(CLOC_LIB_SRCS_LIB
|
||||
${OCLOC_DIRECTORY}/source/queries.h
|
||||
${OCLOC_DIRECTORY}/source/utilities/get_git_version_info.h
|
||||
${OCLOC_DIRECTORY}/source/utilities/get_git_version_info.cpp
|
||||
${NEO_SOURCE_DIR}/shared/source/device_binary_format/device_binary_format_zebin.cpp
|
||||
${NEO_SOURCE_DIR}/shared/source/device_binary_format/zebin_decoder.cpp
|
||||
${NEO_SOURCE_DIR}/shared/source/device_binary_format/yaml/yaml_parser.cpp
|
||||
${NEO_SOURCE_DIR}/third_party${BRANCH_DIR_SUFFIX}aot_config_headers/platforms.h
|
||||
)
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "shared/offline_compiler/source/ocloc_validator.h"
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
|
||||
#include "shared/source/device_binary_format/device_binary_formats.h"
|
||||
#include "shared/source/device_binary_format/zebin_decoder.h"
|
||||
#include "shared/source/program/kernel_info.h"
|
||||
#include "shared/source/program/program_info.h"
|
||||
|
||||
@ -28,7 +28,6 @@ namespace Ocloc {
|
||||
|
||||
int validate(const std::vector<std::string> &args, OclocArgHelper *argHelper) {
|
||||
NEO::ProgramInfo programInfo;
|
||||
NEO::SingleDeviceBinary deviceBinary;
|
||||
std::string errors;
|
||||
std::string warnings;
|
||||
UNRECOVERABLE_IF(nullptr == argHelper)
|
||||
@ -51,13 +50,14 @@ int validate(const std::vector<std::string> &args, OclocArgHelper *argHelper) {
|
||||
auto fileData = argHelper->readBinaryFile(fileName);
|
||||
argHelper->printf("Validating : %s (%zd bytes).\n", fileName.c_str(), fileData.size());
|
||||
|
||||
deviceBinary.deviceBinary = deviceBinary.deviceBinary.fromAny(fileData.data(), fileData.size());
|
||||
if (false == NEO::isDeviceBinaryFormat<DeviceBinaryFormat::Zebin>(deviceBinary.deviceBinary)) {
|
||||
auto deviceBinary = ArrayRef<const uint8_t>::fromAny(fileData.data(), fileData.size());
|
||||
if (false == NEO::isDeviceBinaryFormat<DeviceBinaryFormat::Zebin>(deviceBinary)) {
|
||||
argHelper->printf("Input is not a Zebin file (not elf or wrong elf object file type)\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
auto decodeResult = NEO::decodeSingleDeviceBinary<DeviceBinaryFormat::Zebin>(programInfo, deviceBinary, errors, warnings);
|
||||
auto elf = NEO::Elf::decodeElf<NEO::Elf::EI_CLASS_64>(deviceBinary, errors, warnings);
|
||||
auto decodeResult = NEO::decodeZebin(programInfo, elf, errors, warnings);
|
||||
if (false == warnings.empty()) {
|
||||
argHelper->printf("Validator detected potential problems :\n%s\n", warnings.c_str());
|
||||
}
|
||||
|
@ -11,23 +11,13 @@
|
||||
#include "shared/source/device_binary_format/elf/elf_encoder.h"
|
||||
#include "shared/source/device_binary_format/elf/zebin_elf.h"
|
||||
#include "shared/source/device_binary_format/zebin_decoder.h"
|
||||
#include "shared/source/program/kernel_info.h"
|
||||
#include "shared/source/program/program_info.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
template <>
|
||||
bool isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> binary) {
|
||||
auto header = Elf::decodeElfFileHeader<Elf::EI_CLASS_64>(binary);
|
||||
if (nullptr == header) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return header->type == NEO::Elf::ET_REL ||
|
||||
header->type == NEO::Elf::ET_ZEBIN_EXE;
|
||||
}
|
||||
|
||||
template <>
|
||||
SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> archive, const ConstStringRef requestedProductAbbreviation, const TargetDevice &requestedTargetDevice,
|
||||
std::string &outErrReason, std::string &outWarning) {
|
||||
@ -86,4 +76,29 @@ SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(cons
|
||||
return ret;
|
||||
}
|
||||
|
||||
void prepareLinkerInputForZebin(ProgramInfo &programInfo, Elf::Elf<Elf::EI_CLASS_64> &elf) {
|
||||
programInfo.prepareLinkerInputStorage();
|
||||
|
||||
LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
|
||||
for (uint32_t id = 0; id < static_cast<uint32_t>(programInfo.kernelInfos.size()); id++) {
|
||||
nameToKernelId[programInfo.kernelInfos[id]->kernelDescriptor.kernelMetadata.kernelName] = id;
|
||||
}
|
||||
programInfo.linkerInput->decodeElfSymbolTableAndRelocations(elf, nameToKernelId);
|
||||
}
|
||||
|
||||
template <>
|
||||
DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) {
|
||||
auto elf = Elf::decodeElf<Elf::EI_CLASS_64>(src.deviceBinary, outErrReason, outWarning);
|
||||
if (nullptr == elf.elfFileHeader) {
|
||||
return DecodeError::InvalidBinary;
|
||||
}
|
||||
|
||||
dst.grfSize = src.targetDevice.grfSize;
|
||||
dst.minScratchSpaceSize = src.targetDevice.minScratchSpaceSize;
|
||||
auto decodeError = decodeZebin(dst, elf, outErrReason, outWarning);
|
||||
prepareLinkerInputForZebin(dst, elf);
|
||||
|
||||
return decodeError;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
@ -26,6 +26,17 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
template <>
|
||||
bool isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> binary) {
|
||||
auto header = Elf::decodeElfFileHeader<Elf::EI_CLASS_64>(binary);
|
||||
if (nullptr == header) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return header->type == NEO::Elf::ET_REL ||
|
||||
header->type == NEO::Elf::ET_ZEBIN_EXE;
|
||||
}
|
||||
|
||||
bool validateTargetDevice(const Elf::Elf<Elf::EI_CLASS_64> &elf, const TargetDevice &targetDevice, std::string &outErrReason, std::string &outWarning) {
|
||||
GFXCORE_FAMILY gfxCore = IGFX_UNKNOWN_CORE;
|
||||
PRODUCT_FAMILY productFamily = IGFX_UNKNOWN;
|
||||
@ -1427,13 +1438,7 @@ NEO::DecodeError populateKernelSourceAttributes(NEO::KernelDescriptor &dst, NEO:
|
||||
return DecodeError::Success;
|
||||
}
|
||||
|
||||
template <>
|
||||
DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) {
|
||||
auto elf = Elf::decodeElf<Elf::EI_CLASS_64>(src.deviceBinary, outErrReason, outWarning);
|
||||
if (nullptr == elf.elfFileHeader) {
|
||||
return DecodeError::InvalidBinary;
|
||||
}
|
||||
|
||||
NEO::DecodeError decodeZebin(ProgramInfo &dst, NEO::Elf::Elf<NEO::Elf::EI_CLASS_64> &elf, std::string &outErrReason, std::string &outWarning) {
|
||||
ZebinSections zebinSections;
|
||||
auto extractError = extractZebinSections(elf, zebinSections, outErrReason, outWarning);
|
||||
if (DecodeError::Success != extractError) {
|
||||
@ -1445,10 +1450,6 @@ DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo
|
||||
return extractError;
|
||||
}
|
||||
|
||||
dst.decodedElf = elf;
|
||||
dst.grfSize = src.targetDevice.grfSize;
|
||||
dst.minScratchSpaceSize = src.targetDevice.minScratchSpaceSize;
|
||||
|
||||
if (false == zebinSections.globalDataSections.empty()) {
|
||||
dst.globalVariables.initData = zebinSections.globalDataSections[0]->data.begin();
|
||||
dst.globalVariables.size = zebinSections.globalDataSections[0]->data.size();
|
||||
|
@ -121,4 +121,6 @@ NEO::DecodeError populateZeInfoVersion(NEO::Elf::ZebinKernelMetadata::Types::Ver
|
||||
NEO::DecodeError populateExternalFunctionsMetadata(NEO::ProgramInfo &dst, NEO::Yaml::YamlParser &yamlParser, const NEO::Yaml::Node &functionNd, std::string &outErrReason, std::string &outWarning);
|
||||
|
||||
NEO::DecodeError populateKernelSourceAttributes(NEO::KernelDescriptor &dst, NEO::Elf::ZebinKernelMetadata::Types::Kernel::Attributes::AttributesBaseT &attributes);
|
||||
|
||||
NEO::DecodeError decodeZebin(ProgramInfo &dst, NEO::Elf::Elf<NEO::Elf::EI_CLASS_64> &elf, std::string &outErrReason, std::string &outWarning);
|
||||
} // namespace NEO
|
||||
|
@ -45,7 +45,6 @@ struct ProgramInfo {
|
||||
|
||||
std::vector<ExternalFunctionInfo> externalFunctions;
|
||||
std::vector<KernelInfo *> kernelInfos;
|
||||
Elf::Elf<Elf::EI_CLASS_64> decodedElf;
|
||||
uint32_t grfSize = 32U;
|
||||
uint32_t minScratchSpaceSize = 0U;
|
||||
};
|
||||
|
Reference in New Issue
Block a user