fix: select target device compatible binary from fatbinary

removes recompilation from IR step when fatbinary contains compatible
devices binaries

Resolves: NEO-14300,GSD-10568
Signed-off-by: Aleksandra Nizio <aleksandra.nizio@intel.com>
This commit is contained in:
Aleksandra Nizio
2025-10-07 16:13:02 +00:00
committed by Compute-Runtime-Automation
parent 7955df80e7
commit 97a206ed33
4 changed files with 207 additions and 51 deletions

View File

@@ -9,6 +9,8 @@
#include "platforms.h"
#include <algorithm>
namespace AOT {
consteval PRODUCT_CONFIG getConfixMaxPlatform() {
return CONFIG_MAX_PLATFORM;
@@ -22,4 +24,50 @@ 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

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -10,6 +10,12 @@
#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) {
@@ -19,7 +25,6 @@ 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);
@@ -34,49 +39,73 @@ SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::archive>(co
}
std::string pointerSize = ((requestedTargetDevice.maxPointerSizeInBytes == 8) ? "64" : "32");
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);
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;
}
}
ConstStringRef filterGenericIrFileName{"generic_ir"};
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);
Ar::ArFileEntryHeaderAndData *matchedGenericIr = nullptr;
searchForBinary(archiveData, filterGenericIrFileName, matchedGenericIr);
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 (matchedGenericIr && binaryForRecompilation.intermediateRepresentation.empty()) {
binaryForRecompilation.intermediateRepresentation = matchedGenericIr->fileData;
}
if (false == binaryForRecompilation.intermediateRepresentation.empty()) {