Remove duplicate product configs

In some cases, when a user passes -device in the form of
<major>.<minor>.<revision> (e.g. 12.0.0) ocloc requests fatBinary.
There is no need to duplicate compatible binaries.

Signed-off-by: Daria Hinz <daria.hinz@intel.com>
This commit is contained in:
Daria Hinz
2022-02-09 17:37:53 +01:00
committed by Compute-Runtime-Automation
parent 71f48c89c8
commit c1eae01ce9
5 changed files with 37 additions and 46 deletions

View File

@@ -79,19 +79,14 @@ TEST(OclocFatBinaryRequestedFatBinary, GivenDeviceArgToFatBinaryWhenConfigMatche
EXPECT_TRUE(NEO::requestedFatBinary(3, fewConfigs, argHelper.get()));
}
TEST(OclocFatBinaryProductConfigSupport, WhenPlatformIsSupportedThenAtLeastOneCorrespondingProductConfigExists) {
TEST(OclocFatBinaryRequestedFatBinary, GivenDeviceArgAsSingleProductConfigThenFatBinaryIsNotRequested) {
std::unique_ptr<OclocArgHelper> argHelper = std::make_unique<OclocArgHelper>();
auto allEnabledDeviceConfigs = argHelper->getAllSupportedDeviceConfigs();
auto allSuportedPlatforms = getAllSupportedTargetPlatforms();
for (auto &platform : allSuportedPlatforms) {
bool supportExist = false;
for (auto &config : allEnabledDeviceConfigs) {
if (config.hwInfo->platform.eProductFamily == platform) {
supportExist = true;
break;
}
}
EXPECT_TRUE(supportExist);
for (auto &deviceConfig : allEnabledDeviceConfigs) {
std::string configStr = argHelper->parseProductConfigFromValue(deviceConfig.config);
const char *singleConfig[] = {"ocloc", "-device", configStr.c_str()};
EXPECT_FALSE(NEO::requestedFatBinary(3, singleConfig, argHelper.get()));
}
}
@@ -851,9 +846,8 @@ TEST_F(OclocFatBinaryGetTargetConfigsForFatbinary, GivenTwoConfigsWhenFatBinaryB
EXPECT_EQ(retVal, NEO::OclocErrorCode::SUCCESS);
for (auto deviceConfig : expected) {
std::string platformName = hardwarePrefix[deviceConfig.hwInfo->platform.eProductFamily];
std::string revId = std::to_string(deviceConfig.revId);
resString << "Build succeeded for : " << platformName + "." + revId + ".\n";
auto targetConfig = argHelper->parseProductConfigFromValue(deviceConfig.config);
resString << "Build succeeded for : " << targetConfig + ".\n";
}
EXPECT_STREQ(output.c_str(), resString.str().c_str());
@@ -897,9 +891,8 @@ TEST_F(OclocFatBinaryGetTargetConfigsForFatbinary, GivenProductConfigOpenRangeFr
EXPECT_EQ(retVal, NEO::OclocErrorCode::SUCCESS);
for (auto deviceConfig : expected) {
std::string platformName = hardwarePrefix[deviceConfig.hwInfo->platform.eProductFamily];
std::string revId = std::to_string(deviceConfig.revId);
resString << "Build succeeded for : " << platformName + "." + revId + ".\n";
auto targetConfig = argHelper->parseProductConfigFromValue(deviceConfig.config);
resString << "Build succeeded for : " << targetConfig + ".\n";
}
EXPECT_STREQ(output.c_str(), resString.str().c_str());
@@ -943,9 +936,8 @@ TEST_F(OclocFatBinaryGetTargetConfigsForFatbinary, GivenProductConfigOpenRangeTo
EXPECT_EQ(retVal, NEO::OclocErrorCode::SUCCESS);
for (auto deviceConfig : expected) {
std::string platformName = hardwarePrefix[deviceConfig.hwInfo->platform.eProductFamily];
std::string revId = std::to_string(deviceConfig.revId);
resString << "Build succeeded for : " << platformName + "." + revId + ".\n";
auto targetConfig = argHelper->parseProductConfigFromValue(deviceConfig.config);
resString << "Build succeeded for : " << targetConfig + ".\n";
}
EXPECT_STREQ(output.c_str(), resString.str().c_str());
@@ -997,9 +989,8 @@ TEST_F(OclocFatBinaryGetTargetConfigsForFatbinary, GivenProductConfigClosedRange
EXPECT_EQ(retVal, NEO::OclocErrorCode::SUCCESS);
for (auto deviceConfig : expected) {
std::string platformName = hardwarePrefix[deviceConfig.hwInfo->platform.eProductFamily];
std::string revId = std::to_string(deviceConfig.revId);
resString << "Build succeeded for : " << platformName + "." + revId + ".\n";
auto targetConfig = argHelper->parseProductConfigFromValue(deviceConfig.config);
resString << "Build succeeded for : " << targetConfig + ".\n";
}
EXPECT_STREQ(output.c_str(), resString.str().c_str());

View File

@@ -62,7 +62,7 @@ OclocArgHelper::OclocArgHelper(const uint32_t numSources, const uint8_t **dataSo
#include "product_config.inl"
#undef DEVICE_CONFIG
#undef DEVICE_CONFIG_REVISION
{PRODUCT_CONFIG::UNKNOWN_ISA, {}, 0x0}}) {
}) {
for (uint32_t i = 0; i < numSources; ++i) {
inputs.push_back(Source(dataSources[i], static_cast<size_t>(lenSources[i]), nameSources[i]));
}
@@ -76,6 +76,9 @@ OclocArgHelper::OclocArgHelper(const uint32_t numSources, const uint8_t **dataSo
std::transform(gen.begin(), gen.end(), gen.begin(), ::tolower);
genIGFXMap.insert({gen, i});
}
std::sort(deviceMap.begin(), deviceMap.end(), compareConfigs);
deviceMap.erase(std::unique(deviceMap.begin(), deviceMap.end(), isDuplicateConfig), deviceMap.end());
}
OclocArgHelper::OclocArgHelper() : OclocArgHelper(0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr) {}
@@ -190,8 +193,6 @@ bool OclocArgHelper::getHwInfoForProductConfig(uint32_t config, NEO::HardwareInf
void OclocArgHelper::getProductConfigsForGfxCoreFamily(GFXCORE_FAMILY core, std::vector<DeviceMapping> &out) {
for (auto &deviceConfig : deviceMap) {
if (deviceConfig.config == PRODUCT_CONFIG::UNKNOWN_ISA)
continue;
if (deviceConfig.hwInfo->platform.eRenderCoreFamily == core) {
out.push_back(deviceConfig);
}
@@ -228,15 +229,7 @@ std::string OclocArgHelper::returnProductNameForDevice(unsigned short deviceId)
}
std::vector<DeviceMapping> OclocArgHelper::getAllSupportedDeviceConfigs() {
std::vector<DeviceMapping> allConfigs;
for (auto &deviceConfig : deviceMap) {
if (deviceConfig.config != PRODUCT_CONFIG::UNKNOWN_ISA) {
allConfigs.push_back(deviceConfig);
}
}
std::sort(allConfigs.begin(), allConfigs.end(), compareConfigs);
return allConfigs;
return deviceMap;
}
const std::string OclocArgHelper::parseProductConfigFromValue(PRODUCT_CONFIG config) {
@@ -252,9 +245,7 @@ const std::string OclocArgHelper::parseProductConfigFromValue(PRODUCT_CONFIG con
std::vector<PRODUCT_CONFIG> OclocArgHelper::getAllSupportedProductConfigs() {
std::vector<PRODUCT_CONFIG> allConfigs;
for (auto &deviceConfig : deviceMap) {
if (deviceConfig.config != PRODUCT_CONFIG::UNKNOWN_ISA) {
allConfigs.push_back(deviceConfig.config);
}
allConfigs.push_back(deviceConfig.config);
}
std::sort(allConfigs.begin(), allConfigs.end());
return allConfigs;

View File

@@ -84,6 +84,10 @@ class OclocArgHelper {
return deviceMap0.config < deviceMap1.config;
}
static bool isDuplicateConfig(DeviceMapping deviceMap0, DeviceMapping deviceMap1) {
return deviceMap0.config == deviceMap1.config;
}
public:
OclocArgHelper();
OclocArgHelper(const uint32_t numSources, const uint8_t **dataSources,

View File

@@ -306,10 +306,10 @@ std::vector<DeviceMapping> getTargetConfigsForFatbinary(ConstStringRef deviceArg
return retVal;
}
int buildFatBinaryForTarget(int retVal, std::vector<std::string> argsCopy, std::string pointerSize, Ar::ArEncoder &fatbinary, OfflineCompiler *pCompiler, OclocArgHelper *argHelper) {
int buildFatBinaryForTarget(int retVal, std::vector<std::string> argsCopy, std::string pointerSize, Ar::ArEncoder &fatbinary,
OfflineCompiler *pCompiler, OclocArgHelper *argHelper, const std::string &deviceConfig) {
std::string product = hardwarePrefix[pCompiler->getHardwareInfo().platform.eProductFamily];
auto stepping = pCompiler->getHardwareInfo().platform.usRevId;
std::string deviceConfig = product + "." + std::to_string(stepping);
if (retVal == 0) {
retVal = buildWithSafetyGuard(pCompiler);
@@ -331,7 +331,7 @@ int buildFatBinaryForTarget(int retVal, std::vector<std::string> argsCopy, std::
if (retVal) {
return retVal;
}
fatbinary.appendFileEntry(pointerSize + "." + deviceConfig, pCompiler->getPackedDeviceBinaryOutput());
fatbinary.appendFileEntry(pointerSize + "." + product + "." + std::to_string(stepping), pCompiler->getPackedDeviceBinaryOutput());
return retVal;
}
@@ -384,7 +384,11 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
return retVal;
}
retVal = buildFatBinaryForTarget(retVal, argsCopy, pointerSizeInBits, fatbinary, pCompiler.get(), argHelper);
std::string product = hardwarePrefix[pCompiler->getHardwareInfo().platform.eProductFamily];
auto stepping = pCompiler->getHardwareInfo().platform.usRevId;
auto targetPlatforms = product + "." + std::to_string(stepping);
retVal = buildFatBinaryForTarget(retVal, argsCopy, pointerSizeInBits, fatbinary, pCompiler.get(), argHelper, targetPlatforms);
if (retVal) {
return retVal;
}
@@ -408,7 +412,8 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
return retVal;
}
retVal = buildFatBinaryForTarget(retVal, argsCopy, pointerSizeInBits, fatbinary, pCompiler.get(), argHelper);
auto targetConfigStr = argHelper->parseProductConfigFromValue(targetConfig.config);
retVal = buildFatBinaryForTarget(retVal, argsCopy, pointerSizeInBits, fatbinary, pCompiler.get(), argHelper, targetConfigStr);
if (retVal) {
return retVal;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -46,6 +46,6 @@ std::vector<DeviceMapping> getProductConfigsForSpecificTargets(CompilerOptions::
std::vector<ConstStringRef> getPlatformsForSpecificTargets(CompilerOptions::TokenizedString targets, OclocArgHelper *argHelper);
std::vector<ConstStringRef> toProductNames(const std::vector<PRODUCT_FAMILY> &productIds);
PRODUCT_FAMILY asProductId(ConstStringRef product, const std::vector<PRODUCT_FAMILY> &allSupportedPlatforms);
int buildFatBinaryForTarget(int retVal, std::vector<std::string> argsCopy, std::string pointerSize,
Ar::ArEncoder &fatbinary, OfflineCompiler *pCompiler, OclocArgHelper *argHelper);
int buildFatBinaryForTarget(int retVal, std::vector<std::string> argsCopy, std::string pointerSize, Ar::ArEncoder &fatbinary,
OfflineCompiler *pCompiler, OclocArgHelper *argHelper, const std::string &deviceConfig);
} // namespace NEO