mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 07:14:10 +08:00
Revert "fix: select target device compatible binary from fatbinary"
This reverts commit 97a206ed33.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
1d88f89a19
commit
f31c3fdd03
@@ -9,8 +9,6 @@
|
||||
|
||||
#include "platforms.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace AOT {
|
||||
consteval PRODUCT_CONFIG getConfixMaxPlatform() {
|
||||
return CONFIG_MAX_PLATFORM;
|
||||
@@ -24,50 +22,4 @@ inline const auto &getRtlIdAcronyms() {
|
||||
return rtlIdAcronyms;
|
||||
}
|
||||
|
||||
inline std::vector<std::string> getCompatibilityFallbackProductAbbreviations(const std::string &requestedProductAbbreviation) {
|
||||
std::vector<std::string> result;
|
||||
PRODUCT_CONFIG requestedConfig = PRODUCT_CONFIG::UNKNOWN_ISA;
|
||||
|
||||
std::string searchKey = requestedProductAbbreviation;
|
||||
|
||||
for (const auto &acronymEntry : deviceAcronyms) {
|
||||
if (acronymEntry.first == searchKey || acronymEntry.first.find(searchKey + "-") == 0) {
|
||||
requestedConfig = acronymEntry.second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (requestedConfig == PRODUCT_CONFIG::UNKNOWN_ISA) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (const auto &compatibilityEntry : compatibilityMapping) {
|
||||
bool foundInThisEntry = false;
|
||||
for (const auto &compatibleConfig : compatibilityEntry.second) {
|
||||
if (compatibleConfig == requestedConfig) {
|
||||
foundInThisEntry = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundInThisEntry) {
|
||||
for (const auto &acronymEntry : deviceAcronyms) {
|
||||
if (acronymEntry.second == compatibilityEntry.first) {
|
||||
std::string compatibleProductName = acronymEntry.first;
|
||||
size_t dashPos = compatibleProductName.find('-');
|
||||
if (dashPos != std::string::npos) {
|
||||
compatibleProductName = compatibleProductName.substr(0, dashPos);
|
||||
}
|
||||
|
||||
if (std::find(result.begin(), result.end(), compatibleProductName) == result.end()) {
|
||||
result.push_back(compatibleProductName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace AOT
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
#include "shared/source/helpers/product_config_helper.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
|
||||
#include "neo_aot_platforms.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace NEO {
|
||||
void searchForBinary(Ar::Ar &archiveData, const ConstStringRef filter, Ar::ArFileEntryHeaderAndData *&matched) {
|
||||
for (auto &file : archiveData.files) {
|
||||
@@ -25,6 +19,7 @@ void searchForBinary(Ar::Ar &archiveData, const ConstStringRef filter, Ar::ArFil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
bool isDeviceBinaryFormat<NEO::DeviceBinaryFormat::archive>(const ArrayRef<const uint8_t> binary) {
|
||||
return NEO::Ar::isAr(binary);
|
||||
@@ -39,73 +34,49 @@ SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::archive>(co
|
||||
}
|
||||
|
||||
std::string pointerSize = ((requestedTargetDevice.maxPointerSizeInBytes == 8) ? "64" : "32");
|
||||
|
||||
auto searchForProduct = [&](const std::string &productAbbreviation, bool isOriginalProduct) -> SingleDeviceBinary {
|
||||
std::string filterPointerSizeAndMajorMinorRevision = pointerSize + "." + ProductConfigHelper::parseMajorMinorRevisionValue(requestedTargetDevice.aotConfig);
|
||||
std::string filterPointerSizeAndMajorMinor = pointerSize + "." + ProductConfigHelper::parseMajorMinorValue(requestedTargetDevice.aotConfig);
|
||||
std::string filterPointerSizeAndPlatform = pointerSize + "." + productAbbreviation;
|
||||
std::string filterPointerSizeAndPlatformAndStepping = filterPointerSizeAndPlatform + "." + std::to_string(requestedTargetDevice.stepping);
|
||||
|
||||
Ar::ArFileEntryHeaderAndData *matchedFiles[4] = {};
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndMajorMinorRevision = matchedFiles[0];
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndPlatformAndStepping = matchedFiles[1];
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndMajorMinor = matchedFiles[2];
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndPlatform = matchedFiles[3];
|
||||
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndMajorMinorRevision), matchedPointerSizeAndMajorMinorRevision);
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndPlatformAndStepping), matchedPointerSizeAndPlatformAndStepping);
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndMajorMinor), matchedPointerSizeAndMajorMinor);
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndPlatform), matchedPointerSizeAndPlatform);
|
||||
|
||||
std::string unpackErrors;
|
||||
std::string unpackWarnings;
|
||||
SingleDeviceBinary binaryForRecompilation = {};
|
||||
|
||||
for (auto matchedFile : matchedFiles) {
|
||||
if (nullptr == matchedFile) {
|
||||
continue;
|
||||
}
|
||||
auto unpacked = unpackSingleDeviceBinary(matchedFile->fileData, ConstStringRef(productAbbreviation), requestedTargetDevice, unpackErrors, unpackWarnings);
|
||||
if (false == unpacked.deviceBinary.empty()) {
|
||||
if ((matchedFile != matchedPointerSizeAndPlatformAndStepping) && (matchedFile != matchedPointerSizeAndMajorMinorRevision)) {
|
||||
outWarning = "Couldn't find perfectly matched binary in AR, using best usable";
|
||||
}
|
||||
unpacked.packedTargetDeviceBinary = ArrayRef<const uint8_t>(matchedFile->fileData.begin(), matchedFile->fileData.size());
|
||||
return unpacked;
|
||||
}
|
||||
if (binaryForRecompilation.intermediateRepresentation.empty() && (false == unpacked.intermediateRepresentation.empty())) {
|
||||
binaryForRecompilation = unpacked;
|
||||
}
|
||||
}
|
||||
|
||||
return binaryForRecompilation;
|
||||
};
|
||||
|
||||
auto result = searchForProduct(requestedProductAbbreviation.str(), true);
|
||||
if (false == result.deviceBinary.empty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
SingleDeviceBinary binaryForRecompilation = result;
|
||||
|
||||
auto compatibleProducts = AOT::getCompatibilityFallbackProductAbbreviations(requestedProductAbbreviation.str());
|
||||
for (const auto &compatibleProduct : compatibleProducts) {
|
||||
auto compatResult = searchForProduct(compatibleProduct, false);
|
||||
if (false == compatResult.deviceBinary.empty()) {
|
||||
outWarning = "Couldn't find perfectly matched binary in AR, using best usable";
|
||||
return compatResult;
|
||||
}
|
||||
if (binaryForRecompilation.intermediateRepresentation.empty() && (false == compatResult.intermediateRepresentation.empty())) {
|
||||
binaryForRecompilation = compatResult;
|
||||
}
|
||||
}
|
||||
|
||||
std::string filterPointerSizeAndMajorMinorRevision = pointerSize + "." + ProductConfigHelper::parseMajorMinorRevisionValue(requestedTargetDevice.aotConfig);
|
||||
std::string filterPointerSizeAndMajorMinor = pointerSize + "." + ProductConfigHelper::parseMajorMinorValue(requestedTargetDevice.aotConfig);
|
||||
std::string filterPointerSizeAndPlatform = pointerSize + "." + requestedProductAbbreviation.str();
|
||||
std::string filterPointerSizeAndPlatformAndStepping = filterPointerSizeAndPlatform + "." + std::to_string(requestedTargetDevice.stepping);
|
||||
ConstStringRef filterGenericIrFileName{"generic_ir"};
|
||||
Ar::ArFileEntryHeaderAndData *matchedGenericIr = nullptr;
|
||||
|
||||
Ar::ArFileEntryHeaderAndData *matchedFiles[5] = {};
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndMajorMinorRevision = matchedFiles[0];
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndPlatformAndStepping = matchedFiles[1];
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndMajorMinor = matchedFiles[2];
|
||||
Ar::ArFileEntryHeaderAndData *&matchedPointerSizeAndPlatform = matchedFiles[3];
|
||||
Ar::ArFileEntryHeaderAndData *&matchedGenericIr = matchedFiles[4];
|
||||
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndMajorMinorRevision), matchedPointerSizeAndMajorMinorRevision);
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndPlatformAndStepping), matchedPointerSizeAndPlatformAndStepping);
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndMajorMinor), matchedPointerSizeAndMajorMinor);
|
||||
searchForBinary(archiveData, ConstStringRef(filterPointerSizeAndPlatform), matchedPointerSizeAndPlatform);
|
||||
searchForBinary(archiveData, filterGenericIrFileName, matchedGenericIr);
|
||||
|
||||
if (matchedGenericIr && binaryForRecompilation.intermediateRepresentation.empty()) {
|
||||
binaryForRecompilation.intermediateRepresentation = matchedGenericIr->fileData;
|
||||
std::string unpackErrors;
|
||||
std::string unpackWarnings;
|
||||
SingleDeviceBinary binaryForRecompilation = {};
|
||||
for (auto matchedFile : matchedFiles) {
|
||||
if (nullptr == matchedFile) {
|
||||
continue;
|
||||
}
|
||||
auto unpacked = unpackSingleDeviceBinary(matchedFile->fileData, requestedProductAbbreviation, requestedTargetDevice, unpackErrors, unpackWarnings);
|
||||
if (false == unpacked.deviceBinary.empty()) {
|
||||
if ((matchedFile != matchedPointerSizeAndPlatformAndStepping) && (matchedFile != matchedPointerSizeAndMajorMinorRevision)) {
|
||||
outWarning = "Couldn't find perfectly matched binary in AR, using best usable";
|
||||
}
|
||||
if (unpacked.intermediateRepresentation.empty() && matchedGenericIr) {
|
||||
auto unpackedGenericIr = unpackSingleDeviceBinary(matchedGenericIr->fileData, requestedProductAbbreviation, requestedTargetDevice, unpackErrors, unpackWarnings);
|
||||
if (!unpackedGenericIr.intermediateRepresentation.empty()) {
|
||||
unpacked.intermediateRepresentation = unpackedGenericIr.intermediateRepresentation;
|
||||
}
|
||||
}
|
||||
unpacked.packedTargetDeviceBinary = ArrayRef<const uint8_t>(matchedFile->fileData.begin(), matchedFile->fileData.size());
|
||||
return unpacked;
|
||||
}
|
||||
if (binaryForRecompilation.intermediateRepresentation.empty() && (false == unpacked.intermediateRepresentation.empty())) {
|
||||
binaryForRecompilation = unpacked;
|
||||
}
|
||||
}
|
||||
|
||||
if (false == binaryForRecompilation.intermediateRepresentation.empty()) {
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace AOT {
|
||||
enum PRODUCT_CONFIG : uint32_t; // NOLINT(readability-identifier-naming)
|
||||
enum RELEASE : uint32_t;
|
||||
enum FAMILY : uint32_t;
|
||||
|
||||
} // namespace AOT
|
||||
|
||||
namespace NEO {
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
#include "shared/test/common/test_macros/test_base.h"
|
||||
|
||||
#include "neo_aot_platforms.h"
|
||||
|
||||
TEST(IsDeviceBinaryFormatAr, GivenValidBinaryThenReturnTrue) {
|
||||
auto emptyArchive = ArrayRef<const uint8_t>::fromAny(NEO::Ar::arMagic.begin(), NEO::Ar::arMagic.size());
|
||||
EXPECT_TRUE(NEO::isDeviceBinaryFormat<NEO::DeviceBinaryFormat::archive>(emptyArchive));
|
||||
@@ -449,7 +447,8 @@ TEST(UnpackSingleDeviceBinaryAr, GivenInvalidGenericIrFileWhenDeviceBinaryNotMat
|
||||
|
||||
EXPECT_TRUE(unpacked.intermediateRepresentation.empty());
|
||||
}
|
||||
TEST(UnpackSingleDeviceBinaryAr, WhenMatchingDeviceBinaryPresentAndGenericIrExistsThenGenericIrIsIgnored) {
|
||||
|
||||
TEST(UnpackSingleDeviceBinaryAr, WhenDeviceBinaryMatchedButHasNoIrAndGenericIrFileAvailableThenUseBinaryWithAssignedGenericIr) {
|
||||
PatchTokensTestData::ValidEmptyProgram programTokens;
|
||||
std::string requiredProduct = NEO::hardwarePrefix[productFamily];
|
||||
std::string requiredStepping = std::to_string(programTokens.header->SteppingId);
|
||||
@@ -458,77 +457,35 @@ TEST(UnpackSingleDeviceBinaryAr, WhenMatchingDeviceBinaryPresentAndGenericIrExis
|
||||
NEO::Ar::ArEncoder encoder{true};
|
||||
ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize + "." + requiredProduct + "." + requiredStepping, programTokens.storage));
|
||||
|
||||
NEO::Elf::ElfEncoder<NEO::Elf::EI_CLASS_64> elfEncoderIr;
|
||||
elfEncoderIr.getElfFileHeader().type = NEO::Elf::ET_OPENCL_OBJECTS;
|
||||
const std::string ignoredSpirvContent{"\x07\x23\x02\x03Dummy SPIR-V that should be ignored"};
|
||||
const auto spirvFile{ArrayRef<const uint8_t>::fromAny(ignoredSpirvContent.data(), ignoredSpirvContent.size())};
|
||||
elfEncoderIr.appendSection(NEO::Elf::SHT_OPENCL_SPIRV, NEO::Elf::SectionNamesOpenCl::spirvObject, spirvFile);
|
||||
const auto elfIrData = elfEncoderIr.encode();
|
||||
ASSERT_FALSE(elfIrData.empty());
|
||||
ASSERT_TRUE(encoder.appendFileEntry("generic_ir", ArrayRef<const uint8_t>(elfIrData)));
|
||||
|
||||
NEO::TargetDevice target{};
|
||||
target.coreFamily = static_cast<GFXCORE_FAMILY>(programTokens.header->Device);
|
||||
target.stepping = programTokens.header->SteppingId;
|
||||
target.maxPointerSizeInBytes = programTokens.header->GPUPointerSizeInBytes;
|
||||
target.aotConfig = 0;
|
||||
|
||||
auto arData = encoder.encode();
|
||||
std::string unpackErrors;
|
||||
std::string unpackWarnings;
|
||||
|
||||
auto unpacked = NEO::unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::archive>(
|
||||
arData, requiredProduct, target, unpackErrors, unpackWarnings);
|
||||
|
||||
EXPECT_TRUE(unpackErrors.empty()) << unpackErrors;
|
||||
EXPECT_TRUE(unpackWarnings.empty()) << unpackWarnings;
|
||||
|
||||
EXPECT_FALSE(unpacked.deviceBinary.empty());
|
||||
EXPECT_TRUE(unpacked.intermediateRepresentation.empty());
|
||||
}
|
||||
|
||||
TEST(UnpackSingleDeviceBinaryAr, WhenNoDeviceBinaryAndGenericIrAvailableThenGenericIrIsUsed) {
|
||||
PatchTokensTestData::ValidEmptyProgram programTokens;
|
||||
std::string requiredProduct = NEO::hardwarePrefix[productFamily];
|
||||
std::string requiredPointerSize = (programTokens.header->GPUPointerSizeInBytes == 4) ? "32" : "64";
|
||||
|
||||
NEO::Ar::ArEncoder encoder{true};
|
||||
|
||||
NEO::Elf::ElfEncoder<NEO::Elf::EI_CLASS_64> elfEncoderIr;
|
||||
elfEncoderIr.getElfFileHeader().type = NEO::Elf::ET_OPENCL_OBJECTS;
|
||||
|
||||
const std::string customSprivContent{"\x07\x23\x02\x03This is a custom file, with SPIR-V magic!"};
|
||||
const auto spirvFile{ArrayRef<const uint8_t>::fromAny(customSprivContent.data(), customSprivContent.size())};
|
||||
elfEncoderIr.appendSection(NEO::Elf::SHT_OPENCL_SPIRV, NEO::Elf::SectionNamesOpenCl::spirvObject, spirvFile);
|
||||
|
||||
const auto elfIrData = elfEncoderIr.encode();
|
||||
ASSERT_TRUE(encoder.appendFileEntry("generic_ir", ArrayRef<const uint8_t>(elfIrData)));
|
||||
|
||||
NEO::TargetDevice target{};
|
||||
NEO::TargetDevice target;
|
||||
target.coreFamily = static_cast<GFXCORE_FAMILY>(programTokens.header->Device);
|
||||
target.stepping = programTokens.header->SteppingId;
|
||||
target.maxPointerSizeInBytes = programTokens.header->GPUPointerSizeInBytes;
|
||||
target.aotConfig = 0;
|
||||
|
||||
auto arData = encoder.encode();
|
||||
std::string unpackErrors;
|
||||
std::string unpackWarnings;
|
||||
auto unpacked = NEO::unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::archive>(arData, requiredProduct, target, unpackErrors, unpackWarnings);
|
||||
|
||||
EXPECT_TRUE(unpackErrors.empty()) << unpackErrors;
|
||||
EXPECT_TRUE(unpackWarnings.empty()) << unpackWarnings;
|
||||
|
||||
EXPECT_TRUE(unpacked.deviceBinary.empty());
|
||||
ASSERT_FALSE(unpacked.intermediateRepresentation.empty());
|
||||
ASSERT_EQ(customSprivContent.size(), unpacked.intermediateRepresentation.size());
|
||||
|
||||
EXPECT_EQ(elfIrData.size(), unpacked.intermediateRepresentation.size());
|
||||
const auto isSpirvSameAsInGenericIr = std::memcmp(customSprivContent.data(), unpacked.intermediateRepresentation.begin(), customSprivContent.size()) == 0;
|
||||
EXPECT_TRUE(isSpirvSameAsInGenericIr);
|
||||
|
||||
const uint8_t *irBegin = unpacked.intermediateRepresentation.begin();
|
||||
const uint8_t *irEnd = irBegin + unpacked.intermediateRepresentation.size();
|
||||
const uint8_t *patternBegin = reinterpret_cast<const uint8_t *>(customSprivContent.data());
|
||||
const uint8_t *patternEnd = patternBegin + customSprivContent.size();
|
||||
|
||||
auto it = std::search(irBegin, irEnd, patternBegin, patternEnd);
|
||||
EXPECT_NE(it, irEnd) << "SPIR-V section payload not found inside generic_ir ELF";
|
||||
EXPECT_FALSE(unpacked.deviceBinary.empty());
|
||||
}
|
||||
|
||||
TEST(UnpackSingleDeviceBinaryAr, WhenDeviceBinaryMatchedAndHasIrAndGenericIrFileAvailableThenUseBinaryAndItsIr) {
|
||||
@@ -656,38 +613,3 @@ TEST(UnpackSingleDeviceBinaryAr, WhenCouldNotFindBinaryWithRightPointerSizeThenU
|
||||
EXPECT_TRUE(unpackWarnings.empty()) << unpackWarnings;
|
||||
EXPECT_STREQ("Couldn't find matching binary in AR archive", unpackErrors.c_str());
|
||||
}
|
||||
|
||||
TEST(UnpackSingleDeviceBinaryAr, WhenRequestedDeviceHasCompatibleFallbackThenUseFallbackDevice) {
|
||||
PatchTokensTestData::ValidEmptyProgram programTokens;
|
||||
|
||||
std::string requestedProduct = "lnl";
|
||||
std::string fallbackProduct = "bmg";
|
||||
|
||||
auto compatibleDevices = AOT::getCompatibilityFallbackProductAbbreviations(requestedProduct);
|
||||
if (compatibleDevices.empty() ||
|
||||
std::find(compatibleDevices.begin(), compatibleDevices.end(), fallbackProduct) == compatibleDevices.end()) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
NEO::Ar::ArEncoder encoder{true};
|
||||
std::string pointerSize = (programTokens.header->GPUPointerSizeInBytes == 4) ? "32" : "64";
|
||||
|
||||
ASSERT_TRUE(encoder.appendFileEntry(pointerSize + "." + fallbackProduct, programTokens.storage));
|
||||
|
||||
NEO::TargetDevice target;
|
||||
target.coreFamily = static_cast<GFXCORE_FAMILY>(programTokens.header->Device);
|
||||
target.stepping = programTokens.header->SteppingId;
|
||||
target.maxPointerSizeInBytes = programTokens.header->GPUPointerSizeInBytes;
|
||||
|
||||
auto arData = encoder.encode();
|
||||
std::string unpackErrors;
|
||||
std::string unpackWarnings;
|
||||
|
||||
auto unpacked = NEO::unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::archive>(arData, requestedProduct, target, unpackErrors, unpackWarnings);
|
||||
|
||||
EXPECT_TRUE(unpackErrors.empty());
|
||||
EXPECT_FALSE(unpacked.deviceBinary.empty());
|
||||
EXPECT_EQ(NEO::DeviceBinaryFormat::patchtokens, unpacked.format);
|
||||
|
||||
EXPECT_STREQ("Couldn't find perfectly matched binary in AR, using best usable", unpackWarnings.c_str());
|
||||
}
|
||||
Reference in New Issue
Block a user