mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Unpack 32bit zebin correctly
Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
06e5b1cd42
commit
a8c9458936
@@ -18,10 +18,11 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
template <>
|
||||
SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> archive, const ConstStringRef requestedProductAbbreviation, const TargetDevice &requestedTargetDevice,
|
||||
std::string &outErrReason, std::string &outWarning) {
|
||||
auto elf = Elf::decodeElf<Elf::EI_CLASS_64>(archive, outErrReason, outWarning);
|
||||
template <Elf::ELF_IDENTIFIER_CLASS numBits>
|
||||
SingleDeviceBinary unpackSingleZebin(const ArrayRef<const uint8_t> archive, const ConstStringRef requestedProductAbbreviation, const TargetDevice &requestedTargetDevice,
|
||||
std::string &outErrReason, std::string &outWarning) {
|
||||
|
||||
auto elf = Elf::decodeElf<numBits>(archive, outErrReason, outWarning);
|
||||
if (nullptr == elf.elfFileHeader) {
|
||||
return {};
|
||||
}
|
||||
@@ -60,7 +61,7 @@ SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(cons
|
||||
? (requestedTargetDevice.coreFamily == static_cast<GFXCORE_FAMILY>(elf.elfFileHeader->machine))
|
||||
: (requestedTargetDevice.productFamily == static_cast<PRODUCT_FAMILY>(elf.elfFileHeader->machine));
|
||||
validForTarget &= (0 == flags.validateRevisionId) | ((requestedTargetDevice.stepping >= flags.minHwRevisionId) & (requestedTargetDevice.stepping <= flags.maxHwRevisionId));
|
||||
validForTarget &= (8U == requestedTargetDevice.maxPointerSizeInBytes);
|
||||
validForTarget &= (requestedTargetDevice.maxPointerSizeInBytes >= static_cast<uint32_t>(numBits == Elf::EI_CLASS_32 ? 4 : 8));
|
||||
}
|
||||
|
||||
if (false == validForTarget) {
|
||||
@@ -76,6 +77,14 @@ SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(cons
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <>
|
||||
SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> archive, const ConstStringRef requestedProductAbbreviation, const TargetDevice &requestedTargetDevice,
|
||||
std::string &outErrReason, std::string &outWarning) {
|
||||
return Elf::isElf<Elf::EI_CLASS_32>(archive)
|
||||
? unpackSingleZebin<Elf::EI_CLASS_32>(archive, requestedProductAbbreviation, requestedTargetDevice, outErrReason, outWarning)
|
||||
: unpackSingleZebin<Elf::EI_CLASS_64>(archive, requestedProductAbbreviation, requestedTargetDevice, outErrReason, outWarning);
|
||||
}
|
||||
|
||||
template <Elf::ELF_IDENTIFIER_CLASS numBits>
|
||||
void prepareLinkerInputForZebin(ProgramInfo &programInfo, Elf::Elf<numBits> &elf) {
|
||||
programInfo.prepareLinkerInputStorage();
|
||||
|
||||
@@ -93,7 +93,7 @@ bool validateTargetDevice(const Elf::Elf<numBits> &elf, const TargetDevice &targ
|
||||
validForTarget &= (gfxCore != IGFX_UNKNOWN_CORE) ? targetDevice.coreFamily == gfxCore : true;
|
||||
validForTarget &= (productFamily != IGFX_UNKNOWN) ? targetDevice.productFamily == productFamily : true;
|
||||
validForTarget &= (0 == targetMetadata.validateRevisionId) | ((targetDevice.stepping >= targetMetadata.minHwRevisionId) & (targetDevice.stepping <= targetMetadata.maxHwRevisionId));
|
||||
validForTarget &= (8U == targetDevice.maxPointerSizeInBytes);
|
||||
validForTarget &= (targetDevice.maxPointerSizeInBytes >= static_cast<uint32_t>(numBits == Elf::EI_CLASS_32 ? 4 : 8));
|
||||
return validForTarget;
|
||||
}
|
||||
|
||||
|
||||
@@ -159,27 +159,32 @@ TEST(UnpackSingleDeviceBinary, GivenArBinaryWithOclElfThenReturnPatchtokensBinar
|
||||
}
|
||||
|
||||
TEST(UnpackSingleDeviceBinary, GivenZebinThenReturnSelf) {
|
||||
ZebinTestData::ValidEmptyProgram zebinProgram;
|
||||
ZebinTestData::ValidEmptyProgram zebin64BitProgram;
|
||||
ZebinTestData::ValidEmptyProgram<NEO::Elf::EI_CLASS_32> zebin32BitProgram;
|
||||
|
||||
auto requestedProductAbbreviation = "unk";
|
||||
NEO::TargetDevice requestedTargetDevice;
|
||||
requestedTargetDevice.productFamily = static_cast<PRODUCT_FAMILY>(zebinProgram.elfHeader->machine);
|
||||
requestedTargetDevice.productFamily = static_cast<PRODUCT_FAMILY>(zebin64BitProgram.elfHeader->machine);
|
||||
requestedTargetDevice.stepping = 0U;
|
||||
requestedTargetDevice.maxPointerSizeInBytes = 8U;
|
||||
std::string outErrors;
|
||||
std::string outWarnings;
|
||||
auto unpacked = NEO::unpackSingleDeviceBinary(zebinProgram.storage, requestedProductAbbreviation, requestedTargetDevice, outErrors, outWarnings);
|
||||
EXPECT_TRUE(unpacked.buildOptions.empty());
|
||||
EXPECT_TRUE(unpacked.debugData.empty());
|
||||
EXPECT_FALSE(unpacked.deviceBinary.empty());
|
||||
EXPECT_EQ(zebinProgram.storage.data(), unpacked.deviceBinary.begin());
|
||||
EXPECT_EQ(zebinProgram.storage.size(), unpacked.deviceBinary.size());
|
||||
EXPECT_TRUE(unpacked.intermediateRepresentation.empty());
|
||||
EXPECT_EQ(NEO::DeviceBinaryFormat::Zebin, unpacked.format);
|
||||
EXPECT_EQ(requestedTargetDevice.coreFamily, unpacked.targetDevice.coreFamily);
|
||||
EXPECT_EQ(requestedTargetDevice.stepping, unpacked.targetDevice.stepping);
|
||||
EXPECT_EQ(8U, unpacked.targetDevice.maxPointerSizeInBytes);
|
||||
EXPECT_TRUE(outWarnings.empty());
|
||||
EXPECT_TRUE(outErrors.empty());
|
||||
|
||||
for (auto zebin : {&zebin64BitProgram.storage, &zebin32BitProgram.storage}) {
|
||||
auto unpacked = NEO::unpackSingleDeviceBinary(*zebin, requestedProductAbbreviation, requestedTargetDevice, outErrors, outWarnings);
|
||||
EXPECT_TRUE(unpacked.buildOptions.empty());
|
||||
EXPECT_TRUE(unpacked.debugData.empty());
|
||||
EXPECT_FALSE(unpacked.deviceBinary.empty());
|
||||
EXPECT_EQ(zebin->data(), unpacked.deviceBinary.begin());
|
||||
EXPECT_EQ(zebin->size(), unpacked.deviceBinary.size());
|
||||
EXPECT_TRUE(unpacked.intermediateRepresentation.empty());
|
||||
EXPECT_EQ(NEO::DeviceBinaryFormat::Zebin, unpacked.format);
|
||||
EXPECT_EQ(requestedTargetDevice.coreFamily, unpacked.targetDevice.coreFamily);
|
||||
EXPECT_EQ(requestedTargetDevice.stepping, unpacked.targetDevice.stepping);
|
||||
EXPECT_EQ(8U, unpacked.targetDevice.maxPointerSizeInBytes);
|
||||
EXPECT_TRUE(outWarnings.empty());
|
||||
EXPECT_TRUE(outErrors.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(IsAnyPackedDeviceBinaryFormat, GivenUnknownFormatThenReturnFalse) {
|
||||
|
||||
@@ -5635,6 +5635,32 @@ TEST_F(IntelGTNotesFixture, WhenValidatingTargetDeviceGivenValidTargetDeviceAndV
|
||||
EXPECT_TRUE(validateTargetDevice(elf, targetDevice, outErrReason, outWarning));
|
||||
}
|
||||
|
||||
TEST(ValidateTargetDevice32BitZebin, Given32BitZebinAndValidIntelGTNotesWhenValidatingTargetDeviceThenReturnTrue) {
|
||||
TargetDevice targetDevice;
|
||||
targetDevice.productFamily = productFamily;
|
||||
targetDevice.coreFamily = renderCoreFamily;
|
||||
targetDevice.maxPointerSizeInBytes = 4;
|
||||
targetDevice.stepping = hardwareInfoTable[productFamily]->platform.usRevId;
|
||||
|
||||
ZebinTestData::ValidEmptyProgram<NEO::Elf::EI_CLASS_32> zebin;
|
||||
zebin.elfHeader->type = Elf::ET_REL;
|
||||
zebin.elfHeader->machine = Elf::ELF_MACHINE::EM_INTELGT;
|
||||
|
||||
Elf::ZebinTargetFlags targetMetadata;
|
||||
targetMetadata.validateRevisionId = true;
|
||||
targetMetadata.minHwRevisionId = targetDevice.stepping;
|
||||
targetMetadata.maxHwRevisionId = targetDevice.stepping;
|
||||
auto currentVersion = versionToString(NEO::zeInfoDecoderVersion);
|
||||
auto intelGTNotesSection = ZebinTestData::createIntelGTNoteSection(productFamily, renderCoreFamily, targetMetadata, currentVersion);
|
||||
zebin.appendSection(Elf::SHT_NOTE, Elf::SectionsNamesZebin::noteIntelGT, intelGTNotesSection);
|
||||
std::string outErrReason, outWarning;
|
||||
auto elf = Elf::decodeElf<Elf::EI_CLASS_32>(zebin.storage, outErrReason, outWarning);
|
||||
EXPECT_TRUE(outWarning.empty());
|
||||
EXPECT_TRUE(outErrReason.empty());
|
||||
|
||||
EXPECT_TRUE(validateTargetDevice(elf, targetDevice, outErrReason, outWarning));
|
||||
}
|
||||
|
||||
TEST_F(IntelGTNotesFixture, WhenValidatingTargetDeviceGivenValidTargetDeviceAndNoNotesThenReturnFalse) {
|
||||
TargetDevice targetDevice;
|
||||
targetDevice.productFamily = productFamily;
|
||||
|
||||
Reference in New Issue
Block a user