Fix ocloc fatbinary for better gen/sku detection

Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
Kacper Nowak
2021-04-16 15:25:00 +02:00
committed by Compute-Runtime-Automation
parent 2ef41e4b18
commit e5a1d33a2b
8 changed files with 133 additions and 81 deletions

View File

@@ -16,7 +16,7 @@ namespace NEO {
int MultiCommand::singleBuild(const std::vector<std::string> &args) {
int retVal = OfflineCompiler::ErrorCode::SUCCESS;
if (requestedFatBinary(args)) {
if (requestedFatBinary(args, argHelper)) {
retVal = buildFatBinary(args, argHelper);
} else {
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(args.size(), args, true, retVal, argHelper)};

View File

@@ -102,7 +102,7 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
int retValue = OfflineCompiler::ErrorCode::SUCCESS;
std::unique_ptr<MultiCommand> pMulti{(MultiCommand::create(allArgs, retValue, helper.get()))};
return retValue;
} else if (requestedFatBinary(allArgs)) {
} else if (requestedFatBinary(allArgs, helper.get())) {
return buildFatBinary(allArgs, helper.get());
} else if (numArgs > 1 && ConstStringRef("validate") == allArgs[1]) {
return NEO::Ocloc::validate(allArgs, helper.get());

View File

@@ -13,6 +13,7 @@
#include "hw_cmds.h"
#include <algorithm>
#include <cstring>
#include <sstream>
@@ -60,6 +61,13 @@ OclocArgHelper::OclocArgHelper(const uint32_t numSources, const uint8_t **dataSo
for (uint32_t i = 0; i < numInputHeaders; ++i) {
headers.push_back(Source(dataInputHeaders[i], static_cast<size_t>(lenInputHeaders[i]), nameInputHeaders[i]));
}
for (unsigned int i = 0; i < IGFX_MAX_CORE; ++i) {
if (NEO::familyName[i] == nullptr)
continue;
std::string gen = NEO::familyName[i];
std::transform(gen.begin(), gen.end(), gen.begin(), ::tolower);
genIGFXMap.insert({gen, i});
}
}
OclocArgHelper::OclocArgHelper() : OclocArgHelper(0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr) {}
@@ -170,4 +178,20 @@ std::string OclocArgHelper::returnProductNameForDevice(unsigned short deviceId)
}
}
return res;
}
bool OclocArgHelper::isGen(const std::string &device) {
std::string buf(device);
std::transform(buf.begin(), buf.end(), buf.begin(), ::tolower);
auto it = genIGFXMap.find(buf);
return it == genIGFXMap.end() ? false : true;
}
unsigned int OclocArgHelper::returnIGFXforGen(const std::string &device) {
std::string buf(device);
std::transform(buf.begin(), buf.end(), buf.begin(), ::tolower);
auto it = genIGFXMap.find(buf);
if (it == genIGFXMap.end())
return 0;
return it->second;
}

View File

@@ -11,6 +11,7 @@
#include <cctype>
#include <fstream>
#include <map>
#include <memory>
#include <string>
#include <vector>
@@ -53,6 +54,7 @@ class OclocArgHelper {
uint64_t **lenOutputs = nullptr;
bool hasOutput = false;
const std::vector<DeviceProduct> deviceProductTable;
std::map<std::string, unsigned int> genIGFXMap;
void moveOutputs();
MessagePrinter messagePrinter;
Source *findSourceFile(const std::string &filename);
@@ -102,4 +104,6 @@ class OclocArgHelper {
messagePrinter.printf(format, std::forward<Args>(args)...);
}
std::string returnProductNameForDevice(unsigned short deviceId);
bool isGen(const std::string &device);
unsigned int returnIGFXforGen(const std::string &device);
};

View File

@@ -23,13 +23,13 @@
namespace NEO {
bool requestedFatBinary(const std::vector<std::string> &args) {
bool requestedFatBinary(const std::vector<std::string> &args, OclocArgHelper *helper) {
for (size_t argIndex = 1; argIndex < args.size(); argIndex++) {
const auto &currArg = args[argIndex];
const bool hasMoreArgs = (argIndex + 1 < args.size());
if ((ConstStringRef("-device") == currArg) && hasMoreArgs) {
ConstStringRef deviceArg(args[argIndex + 1]);
return deviceArg.contains("*") || deviceArg.contains("-") || deviceArg.contains(",") || deviceArg.containsCaseInsensitive("gen") || deviceArg.startsWith("XE_");
return deviceArg.contains("*") || deviceArg.contains("-") || deviceArg.contains(",") || helper->isGen(deviceArg.str());
}
}
return false;
@@ -56,34 +56,6 @@ PRODUCT_FAMILY asProductId(ConstStringRef product, const std::vector<PRODUCT_FAM
return IGFX_UNKNOWN;
}
std::vector<GFXCORE_FAMILY> asGfxCoreIdList(ConstStringRef core) {
std::vector<GFXCORE_FAMILY> result;
constexpr size_t genPrefixLength = 3;
auto coreSuffixBeg = core.begin() + genPrefixLength;
size_t coreSuffixLength = core.end() - coreSuffixBeg;
ConstStringRef coreSuffix(coreSuffixBeg, coreSuffixLength);
for (unsigned int coreId = 0; coreId < IGFX_MAX_CORE; ++coreId) {
auto name = familyName[coreId];
if (name == nullptr)
continue;
auto nameSuffix = name + genPrefixLength;
auto nameNumberEnd = nameSuffix;
for (; *nameNumberEnd != '\0' && isdigit(*nameNumberEnd); ++nameNumberEnd)
;
size_t nameNumberLength = nameNumberEnd - nameSuffix;
if (nameNumberLength > coreSuffixLength)
continue;
if (ConstStringRef(nameSuffix, std::min(coreSuffixLength, strlen(nameSuffix))) == coreSuffix)
result.push_back(static_cast<GFXCORE_FAMILY>(coreId));
}
return result;
}
void appendPlatformsForGfxCore(GFXCORE_FAMILY core, const std::vector<PRODUCT_FAMILY> &allSupportedPlatforms, std::vector<PRODUCT_FAMILY> &out) {
for (auto family : allSupportedPlatforms) {
if (core == hardwareInfoTable[family]->platform.eRenderCoreFamily) {
@@ -112,12 +84,14 @@ std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef device
if (range.size() == 1) {
// open range , from-max or min-to
if (range[0].containsCaseInsensitive("gen") || range[0].startsWith("XE_")) {
auto coreIdList = asGfxCoreIdList(range[0]);
if (coreIdList.empty()) {
if (argHelper->isGen(range[0].str())) {
std::vector<GFXCORE_FAMILY> coreIdList;
auto coreId = argHelper->returnIGFXforGen(range[0].str());
if (coreId == 0) {
argHelper->printf("Unknown device : %s\n", set.str().c_str());
return {};
}
coreIdList.push_back(static_cast<GFXCORE_FAMILY>(coreId));
if ('-' == set[0]) {
// to
auto coreId = coreIdList.back();
@@ -152,25 +126,22 @@ std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef device
}
}
} else {
if (range[0].contains("gen") || range[0].startsWith("XE_")) {
if (false == range[1].contains("gen") && false == range[1].startsWith("XE_")) {
if (argHelper->isGen(range[0].str())) {
if (false == argHelper->isGen(range[1].str())) {
argHelper->printf("Ranges mixing platforms and gfxCores is not supported : %s - should be genFrom-genTo or platformFrom-platformTo\n", set.str().c_str());
return {};
}
auto coreFromList = asGfxCoreIdList(range[0]);
auto coreToList = asGfxCoreIdList(range[1]);
if (coreFromList.empty()) {
auto coreFrom = argHelper->returnIGFXforGen(range[0].str());
auto coreTo = argHelper->returnIGFXforGen(range[1].str());
if (coreFrom == 0) {
argHelper->printf("Unknown device : %s\n", set.str().c_str());
return {};
}
if (coreToList.empty()) {
if (coreTo == 0) {
argHelper->printf("Unknown device : %s\n", set.str().c_str());
return {};
}
auto coreFrom = coreFromList.front();
auto coreTo = coreToList.back();
if (coreFrom > coreTo) {
if (static_cast<GFXCORE_FAMILY>(coreFrom) > static_cast<GFXCORE_FAMILY>(coreTo)) {
std::swap(coreFrom, coreTo);
}
while (coreFrom <= coreTo) {
@@ -197,17 +168,16 @@ std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef device
requestedPlatforms.insert(requestedPlatforms.end(), from, to);
}
}
} else if (set.containsCaseInsensitive("gen") || deviceArg.startsWith("XE_")) {
} else if (argHelper->isGen(set.str())) {
if (set.size() == genArg.size()) {
argHelper->printf("Invalid gen-based device : %s - gen should be followed by a number\n", set.str().c_str());
} else {
auto coreIdList = asGfxCoreIdList(set);
if (coreIdList.empty()) {
auto coreId = argHelper->returnIGFXforGen(set.str());
if (coreId == 0) {
argHelper->printf("Unknown device : %s\n", set.str().c_str());
return {};
}
for (auto coreId : coreIdList)
appendPlatformsForGfxCore(coreId, allSupportedPlatforms, requestedPlatforms);
appendPlatformsForGfxCore(static_cast<GFXCORE_FAMILY>(coreId), allSupportedPlatforms, requestedPlatforms);
}
} else {
auto prodId = asProductId(set, allSupportedPlatforms);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -17,11 +17,11 @@
class OclocArgHelper;
namespace NEO {
bool requestedFatBinary(const std::vector<std::string> &args);
inline bool requestedFatBinary(int argc, const char *argv[]) {
bool requestedFatBinary(const std::vector<std::string> &args, OclocArgHelper *helper);
inline bool requestedFatBinary(int argc, const char *argv[], OclocArgHelper *helper) {
std::vector<std::string> args;
args.assign(argv, argv + argc);
return requestedFatBinary(args);
return requestedFatBinary(args, helper);
}
int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelper);
@@ -34,7 +34,6 @@ inline int buildFatBinary(int argc, const char *argv[], OclocArgHelper *argHelpe
std::vector<PRODUCT_FAMILY> getAllSupportedTargetPlatforms();
std::vector<ConstStringRef> toProductNames(const std::vector<PRODUCT_FAMILY> &productIds);
PRODUCT_FAMILY asProductId(ConstStringRef product, const std::vector<PRODUCT_FAMILY> &allSupportedPlatforms);
std::vector<GFXCORE_FAMILY> asGfxCoreIdList(ConstStringRef core);
void appendPlatformsForGfxCore(GFXCORE_FAMILY core, const std::vector<PRODUCT_FAMILY> &allSupportedPlatforms, std::vector<PRODUCT_FAMILY> &out);
std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef deviceArg, OclocArgHelper *argHelper);

View File

@@ -289,6 +289,7 @@ int OfflineCompiler::getHardwareInfo(std::string deviceName) {
int retVal = INVALID_DEVICE;
overridePlatformName(deviceName);
std::transform(deviceName.begin(), deviceName.end(), deviceName.begin(), ::tolower);
const char hexPrefix = 2;
std::string product("");