feature: Add support for legacy acronyms in ocloc's fatbinary

Expands support for deprecated acronyms to fatbinary. Previously,
these were allowed only in single-target builds.

Related-To: NEO-10190

Signed-off-by: Chodor, Jaroslaw <jaroslaw.chodor@intel.com>
This commit is contained in:
Chodor, Jaroslaw
2024-02-12 16:41:21 +00:00
committed by Compute-Runtime-Automation
parent 57c946b61c
commit b58717b9e3
7 changed files with 130 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -1920,6 +1920,61 @@ TEST(OclocFatBinaryHelpersTest, givenNonEmptyBuildLogWhenBuildingFatbinaryForTar
EXPECT_TRUE(output.empty()) << output;
}
TEST(OclocFatBinaryHelpersTest, givenListOfDeprecatedAcronymsThenUseThemAsIs) {
ProductConfigHelper productConfigHelper;
auto allDeperecatedAcronyms = productConfigHelper.getDeprecatedAcronyms();
if (allDeperecatedAcronyms.empty()) {
return;
}
::testing::internal::CaptureStdout();
std::vector<std::string> argv = {
"ocloc",
"-q",
"-file",
clFiles + "copybuffer.cl",
"-device",
allDeperecatedAcronyms[0].str()};
int deviceArgIndex = 5;
MockOfflineCompiler mockOfflineCompiler{};
mockOfflineCompiler.initialize(argv.size(), argv);
const auto mockArgHelper = mockOfflineCompiler.uniqueHelper.get();
const auto deviceConfig = getDeviceConfig(mockOfflineCompiler, mockArgHelper);
mockOfflineCompiler.buildReturnValue = OCLOC_SUCCESS;
Ar::ArEncoder ar;
const std::string pointerSize{"64"};
const int previousReturnValue{OCLOC_SUCCESS};
for (const auto &product : allDeperecatedAcronyms) {
argv[deviceArgIndex] = product.str();
auto retVal = buildFatBinaryForTarget(previousReturnValue, argv, pointerSize, ar, &mockOfflineCompiler, mockArgHelper, product.str());
EXPECT_EQ(0, retVal);
}
const auto output{::testing::internal::GetCapturedStdout()};
EXPECT_TRUE(output.empty()) << output;
auto encodedFatbin = ar.encode();
std::string arError, arWarning;
auto decodedAr = Ar::decodeAr(encodedFatbin, arError, arWarning);
EXPECT_TRUE(arError.empty()) << arError;
EXPECT_TRUE(arWarning.empty()) << arWarning;
std::unordered_set<std::string> entryNames;
for (const auto &entry : decodedAr.files) {
entryNames.insert(entry.fileName.str());
}
for (const auto &deprecatedAcronym : allDeperecatedAcronyms) {
auto expectedFName = (pointerSize + ".") + deprecatedAcronym.data();
EXPECT_EQ(1U, entryNames.count(expectedFName)) << deprecatedAcronym.data() << "not found in [" << ConstStringRef(",").join(entryNames) << "]";
}
}
TEST(OclocFatBinaryHelpersTest, givenQuietModeWhenBuildingFatbinaryForTargetThenNothingIsPrinted) {
using namespace std::string_literals;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -8,6 +8,7 @@
#include "offline_compiler_tests.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_fatbinary.h"
#include "shared/source/compiler_interface/compiler_options.h"
#include "shared/source/compiler_interface/intermediate_representations.h"
#include "shared/source/compiler_interface/oclc_extensions.h"
@@ -689,6 +690,22 @@ TEST_F(MockOfflineCompilerTests, givenDeprecatedAcronymsWithRevisionWhenInitHwIn
}
}
TEST_F(MockOfflineCompilerTests, givenDeprecatedAcronymThenSameAcronymIsReturnedAsProduct) {
MockOfflineCompiler mockOfflineCompiler;
auto deprecatedAcronyms = mockOfflineCompiler.argHelper->productConfigHelper->getDeprecatedAcronyms();
if (deprecatedAcronyms.empty()) {
GTEST_SKIP();
}
for (const auto &acronym : deprecatedAcronyms) {
NEO::CompilerOptions::TokenizedString srcAcronym;
srcAcronym.push_back(acronym);
auto products = NEO::getProductForSpecificTarget(srcAcronym, mockOfflineCompiler.argHelper);
ASSERT_EQ(1U, products.size());
EXPECT_STREQ(acronym.data(), products[0].data());
}
}
TEST_F(MockOfflineCompilerTests, givenValidAcronymAndRevisionIdWhenInitHardwareInfoForProductConfigThenInvalidDeviceIsReturned) {
MockOfflineCompiler mockOfflineCompiler;
auto &allEnabledDeviceConfigs = mockOfflineCompiler.argHelper->productConfigHelper->getDeviceAotInfo();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -229,6 +229,11 @@ std::vector<ConstStringRef> getProductForSpecificTarget(const CompilerOptions::T
requestedConfigs.push_back(target);
continue;
}
auto legacyAcronymHwInfo = getHwInfoForDeprecatedAcronym(targetStr);
if (nullptr != legacyAcronymHwInfo) {
requestedConfigs.push_back(target);
continue;
}
argHelper->printf("Failed to parse target : %s - invalid device:\n", target.str().c_str());
return {};
}
@@ -284,14 +289,19 @@ int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy
return retVal;
}
std::string productConfig("");
std::string entryName("");
if (product.find(".") != std::string::npos) {
productConfig = product;
entryName = product;
} else {
productConfig = ProductConfigHelper::parseMajorMinorRevisionValue(argHelper->productConfigHelper->getProductConfigFromDeviceName(product));
auto productConfig = argHelper->productConfigHelper->getProductConfigFromDeviceName(product);
if (AOT::UNKNOWN_ISA != productConfig) {
entryName = ProductConfigHelper::parseMajorMinorRevisionValue(productConfig);
} else {
entryName = product;
}
}
fatbinary.appendFileEntry(pointerSize + "." + productConfig, pCompiler->getPackedDeviceBinaryOutput());
fatbinary.appendFileEntry(pointerSize + "." + entryName, pCompiler->getPackedDeviceBinaryOutput());
return retVal;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,6 +7,7 @@
#pragma once
#include "shared/source/compiler_interface/tokenized_string.h"
#include "shared/source/utilities/arrayref.h"
#include "shared/source/utilities/const_stringref.h"
@@ -45,5 +46,6 @@ int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy
OfflineCompiler *pCompiler, OclocArgHelper *argHelper, const std::string &deviceConfig);
int appendGenericIr(Ar::ArEncoder &fatbinary, const std::string &inputFile, OclocArgHelper *argHelper, std::string options);
std::vector<uint8_t> createEncodedElfWithSpirv(const ArrayRef<const uint8_t> &spirv, const ArrayRef<const uint8_t> &options);
std::vector<ConstStringRef> getProductForSpecificTarget(const NEO::CompilerOptions::TokenizedString &targets, OclocArgHelper *argHelper);
} // namespace NEO

View File

@@ -741,32 +741,40 @@ std::string &OfflineCompiler::getBuildLog() {
return buildLog;
}
int OfflineCompiler::initHardwareInfoForDeprecatedAcronyms(std::string deviceName, std::unique_ptr<NEO::CompilerProductHelper> &compilerProductHelper, std::unique_ptr<NEO::ReleaseHelper> &releaseHelper) {
const HardwareInfo *getHwInfoForDeprecatedAcronym(const std::string &deviceName) {
std::vector<PRODUCT_FAMILY> allSupportedProduct{ALL_SUPPORTED_PRODUCT_FAMILIES};
std::transform(deviceName.begin(), deviceName.end(), deviceName.begin(), ::tolower);
auto deviceNameLowered = deviceName;
std::transform(deviceNameLowered.begin(), deviceNameLowered.end(), deviceNameLowered.begin(), ::tolower);
for (const auto &product : allSupportedProduct) {
if (0 == strcmp(deviceName.c_str(), hardwarePrefix[product])) {
hwInfo = *hardwareInfoTable[product];
if (revisionId != -1) {
hwInfo.platform.usRevId = revisionId;
}
compilerProductHelper = NEO::CompilerProductHelper::create(hwInfo.platform.eProductFamily);
auto defaultIpVersion = compilerProductHelper->getDefaultHwIpVersion();
auto productConfig = compilerProductHelper->matchRevisionIdWithProductConfig(defaultIpVersion, revisionId);
hwInfo.ipVersion = argHelper->productConfigHelper->isSupportedProductConfig(productConfig) ? productConfig : defaultIpVersion;
uint64_t config = hwInfoConfig ? hwInfoConfig : compilerProductHelper->getHwInfoConfig(hwInfo);
setHwInfoValuesFromConfig(config, hwInfo);
releaseHelper = NEO::ReleaseHelper::create(hwInfo.ipVersion);
hardwareInfoBaseSetup[hwInfo.platform.eProductFamily](&hwInfo, true, releaseHelper.get());
UNRECOVERABLE_IF(compilerProductHelper == nullptr);
productFamilyName = hardwarePrefix[hwInfo.platform.eProductFamily];
return OCLOC_SUCCESS;
if (0 == strcmp(deviceNameLowered.c_str(), hardwarePrefix[product])) {
return hardwareInfoTable[product];
}
}
return OCLOC_INVALID_DEVICE;
return nullptr;
}
int OfflineCompiler::initHardwareInfoForDeprecatedAcronyms(const std::string &deviceName, std::unique_ptr<NEO::CompilerProductHelper> &compilerProductHelper, std::unique_ptr<NEO::ReleaseHelper> &releaseHelper) {
auto foundHwInfo = getHwInfoForDeprecatedAcronym(deviceName);
if (nullptr == foundHwInfo) {
return OCLOC_INVALID_DEVICE;
}
hwInfo = *foundHwInfo;
if (revisionId != -1) {
hwInfo.platform.usRevId = revisionId;
}
compilerProductHelper = NEO::CompilerProductHelper::create(hwInfo.platform.eProductFamily);
auto defaultIpVersion = compilerProductHelper->getDefaultHwIpVersion();
auto productConfig = compilerProductHelper->matchRevisionIdWithProductConfig(defaultIpVersion, revisionId);
hwInfo.ipVersion = argHelper->productConfigHelper->isSupportedProductConfig(productConfig) ? productConfig : defaultIpVersion;
uint64_t config = hwInfoConfig ? hwInfoConfig : compilerProductHelper->getHwInfoConfig(hwInfo);
setHwInfoValuesFromConfig(config, hwInfo);
releaseHelper = NEO::ReleaseHelper::create(hwInfo.ipVersion);
hardwareInfoBaseSetup[hwInfo.platform.eProductFamily](&hwInfo, true, releaseHelper.get());
UNRECOVERABLE_IF(compilerProductHelper == nullptr);
productFamilyName = hardwarePrefix[hwInfo.platform.eProductFamily];
return OCLOC_SUCCESS;
}
bool OfflineCompiler::isArgumentDeviceId(const std::string &argument) const {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -38,6 +38,8 @@ struct NameVersionPair : ocloc_name_version {
};
static_assert(sizeof(NameVersionPair) == sizeof(ocloc_name_version));
const HardwareInfo *getHwInfoForDeprecatedAcronym(const std::string &deviceName);
class OfflineCompiler {
public:
static std::vector<NameVersionPair> getExtensions(ConstStringRef product, bool needVersions, OclocArgHelper *helper);
@@ -129,7 +131,7 @@ All supported acronyms: %s.
int initHardwareInfo(std::string deviceName);
int initHardwareInfoForProductConfig(std::string deviceName);
int initHardwareInfoForDeprecatedAcronyms(std::string deviceName, std::unique_ptr<NEO::CompilerProductHelper> &compilerProductHelper, std::unique_ptr<NEO::ReleaseHelper> &releaseHelper);
int initHardwareInfoForDeprecatedAcronyms(const std::string &deviceName, std::unique_ptr<NEO::CompilerProductHelper> &compilerProductHelper, std::unique_ptr<NEO::ReleaseHelper> &releaseHelper);
bool isArgumentDeviceId(const std::string &argument) const;
std::string getStringWithinDelimiters(const std::string &src);
int initialize(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 Intel Corporation
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -231,10 +231,10 @@ class ConstStringRef {
}
ret.reserve(len);
ret.append(*container.begin());
for (auto it = container.begin() + 1, e = container.end(); it != e; ++it) {
ret.append(container.begin()->data(), container.begin()->size());
for (auto it = std::next(container.begin()), e = container.end(); it != e; ++it) {
ret.append(this->ptr, this->len);
ret.append(*it);
ret.append(it->data(), it->size());
}
return ret;
}