Ocloc: New AOT approach implementation

Ocloc will handle any new values that may be
passed to the -device argument.

Supported acronyms are available under cmd:
ocloc compile --help

Supported patterns:
- device acronym
- release acronym
- family acronym
- version (major.minor.revision)

Fatbinary will no longer handle major.minor.revision variances,
only acronyms allowed.

Signed-off-by: Daria Hinz <daria.hinz@intel.com>
This commit is contained in:
Daria Hinz
2022-05-13 10:00:27 +00:00
committed by Compute-Runtime-Automation
parent 552c91bf07
commit a44f1b43aa
76 changed files with 1966 additions and 1866 deletions

View File

@ -12,6 +12,8 @@ set(OCLOC_FOLDER_NAME "offline_compiler")
set(CLOC_LIB_SRCS_LIB
${NEO_SHARED_DIRECTORY}/compiler_interface/compiler_options/compiler_options_base.cpp
${NEO_SHARED_DIRECTORY}/compiler_interface/create_main.cpp
${NEO_SHARED_DIRECTORY}/compiler_interface/oclc_extensions.cpp
${NEO_SHARED_DIRECTORY}/compiler_interface/oclc_extensions.h
${NEO_SHARED_DIRECTORY}/device_binary_format/ar/ar.h
${NEO_SHARED_DIRECTORY}/device_binary_format/ar/ar_decoder.cpp
${NEO_SHARED_DIRECTORY}/device_binary_format/ar/ar_decoder.h
@ -28,11 +30,11 @@ set(CLOC_LIB_SRCS_LIB
${NEO_SHARED_DIRECTORY}/dll/devices/devices_base.inl
${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}/product_config.inl
${NEO_SHARED_DIRECTORY}/dll/devices/product_config_base.inl
${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}platforms.h
${NEO_SHARED_DIRECTORY}/helpers/abort.cpp
${NEO_SHARED_DIRECTORY}/helpers/compiler_hw_info_config.h
${NEO_SHARED_DIRECTORY}/helpers/compiler_hw_info_config.cpp
${NEO_SHARED_DIRECTORY}/helpers/compiler_hw_info_config_base.inl
${NEO_SHARED_DIRECTORY}/helpers/compiler_aot_config_bdw_and_later.inl
${NEO_SHARED_DIRECTORY}/helpers/compiler_hw_info_config_bdw_and_later.inl
${NEO_SHARED_DIRECTORY}/helpers/compiler_options_parser.cpp
${NEO_SHARED_DIRECTORY}/helpers/compiler_options_parser.h
@ -41,9 +43,9 @@ set(CLOC_LIB_SRCS_LIB
${NEO_SHARED_DIRECTORY}/helpers/hw_info.cpp
${NEO_SHARED_DIRECTORY}/helpers/hw_info.h
${NEO_SHARED_DIRECTORY}/helpers${BRANCH_DIR_SUFFIX}hw_info_extended.cpp
${NEO_SHARED_DIRECTORY}/helpers/product_config_helper.cpp
${NEO_SHARED_DIRECTORY}/helpers/product_config_helper.h
${NEO_SHARED_DIRECTORY}/os_interface/os_library.h
${NEO_SHARED_DIRECTORY}/compiler_interface/oclc_extensions.cpp
${NEO_SHARED_DIRECTORY}/compiler_interface/oclc_extensions.h
${OCLOC_DIRECTORY}/source/decoder/binary_decoder.cpp
${OCLOC_DIRECTORY}/source/decoder/binary_decoder.h
${OCLOC_DIRECTORY}/source/decoder/binary_encoder.cpp
@ -81,6 +83,7 @@ set(CLOC_LIB_SRCS_LIB
${NEO_SOURCE_DIR}/shared/source/device_binary_format/device_binary_format_zebin.cpp
${NEO_SOURCE_DIR}/shared/source/device_binary_format/zebin_decoder.cpp
${NEO_SOURCE_DIR}/shared/source/device_binary_format/yaml/yaml_parser.cpp
${NEO_SOURCE_DIR}/third_party${BRANCH_DIR_SUFFIX}aot_config_headers/platforms.h
)
if(${IGA_HEADERS_AVAILABLE})

View File

@ -336,7 +336,7 @@ Examples:
Disassemble Intel Compute GPU device binary
ocloc disasm -file source_file_Gen9core.bin
)===",
NEO::getDevicesTypes().c_str());
argHelper->getAllSupportedAcronyms().c_str());
}
int BinaryDecoder::processBinary(const void *&ptr, std::ostream &ptmFile) {

View File

@ -133,7 +133,7 @@ Examples:
Assemble to Intel Compute GPU device binary
ocloc asm -out reassembled.bin
)===",
NEO::getDevicesTypes().c_str());
argHelper->getAllSupportedAcronyms().c_str());
}
int BinaryEncoder::encode() {

View File

@ -7,6 +7,7 @@
#include "ocloc_arg_helper.h"
#include "shared/source/helpers/compiler_hw_info_config.h"
#include "shared/source/helpers/file_io.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/string.h"
@ -63,13 +64,11 @@ OclocArgHelper::OclocArgHelper(const uint32_t numSources, const uint8_t **dataSo
#undef NAMEDDEVICE
{0u, std::string("")}}),
deviceMap({
#define DEVICE_CONFIG_IDS_AND_REVISION(product, productConfig, deviceIds, revision_id) {product, &NEO::productConfig::hwInfo, &NEO::deviceIds, revision_id},
#define DEVICE_CONFIG_IDS(product, productConfig, deviceIds) {product, &NEO::productConfig::hwInfo, &NEO::deviceIds, NEO::productConfig::hwInfo.platform.usRevId},
#define DEVICE_CONFIG(product, productConfig) {product, &NEO::productConfig::hwInfo, nullptr, NEO::productConfig::hwInfo.platform.usRevId},
#define DEVICE_CONFIG_IDS(product, productConfig, deviceIds, family, release) {&NEO::productConfig::hwInfo, &NEO::deviceIds, AOT::family, AOT::release, {AOT::product}},
#define DEVICE_CONFIG(product, productConfig, family, release) {&NEO::productConfig::hwInfo, nullptr, AOT::family, AOT::release, {AOT::product}},
#include "product_config.inl"
#undef DEVICE_CONFIG
#undef DEVICE_CONFIG_IDS
#undef DEVICE_CONFIG_IDS_AND_REVISION
}) {
for (uint32_t i = 0; i < numSources; ++i) {
inputs.push_back(Source(dataSources[i], static_cast<size_t>(lenSources[i]), nameSources[i]));
@ -77,15 +76,15 @@ 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 family = 0; family < IGFX_MAX_CORE; ++family) {
if (NEO::familyName[family] == nullptr) {
continue;
}
insertGenNames(static_cast<GFXCORE_FAMILY>(family));
}
std::sort(deviceMap.begin(), deviceMap.end(), compareConfigs);
deviceMap.erase(std::unique(deviceMap.begin(), deviceMap.end(), isDuplicateConfig), deviceMap.end());
for (auto &device : deviceMap) {
for (const auto &[acronym, value] : AOT::productConfigAcronyms) {
if (value == device.aotConfig.ProductConfig) {
device.acronyms.push_back(NEO::ConstStringRef(acronym));
}
}
}
}
OclocArgHelper::OclocArgHelper() : OclocArgHelper(0, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr) {}
@ -169,31 +168,19 @@ std::unique_ptr<char[]> OclocArgHelper::loadDataFromFile(const std::string &file
}
}
void OclocArgHelper::setDeviceInfoForFatbinaryTarget(const DeviceMapping &device) {
deviceForFatbinary.hwInfo = device.hwInfo;
deviceForFatbinary.revId = device.revId;
deviceForFatbinary.deviceIds = device.deviceIds;
}
void OclocArgHelper::setHwInfoForFatbinaryTarget(NEO::HardwareInfo &hwInfo) {
hwInfo = *deviceForFatbinary.hwInfo;
NEO::hardwareInfoBaseSetup[hwInfo.platform.eProductFamily](&hwInfo, true);
hwInfo.platform.usRevId = deviceForFatbinary.revId;
if (deviceForFatbinary.deviceIds) {
hwInfo.platform.usDeviceID = deviceForFatbinary.deviceIds->front();
}
}
bool OclocArgHelper::getHwInfoForProductConfig(uint32_t config, NEO::HardwareInfo &hwInfo) {
bool retVal = false;
if (config == UNKNOWN_ISA) {
if (config == AOT::UNKNOWN_ISA) {
return retVal;
}
for (auto &deviceConfig : deviceMap) {
if (deviceConfig.config == config) {
if (deviceConfig.aotConfig.ProductConfig == config) {
hwInfo = *deviceConfig.hwInfo;
const auto &compilerHwInfoConfig = *NEO::CompilerHwInfoConfig::get(hwInfo.platform.eProductFamily);
compilerHwInfoConfig.setProductConfigForHwInfo(hwInfo, deviceConfig.aotConfig);
NEO::hardwareInfoBaseSetup[hwInfo.platform.eProductFamily](&hwInfo, true);
hwInfo.platform.usRevId = deviceConfig.revId;
if (deviceConfig.deviceIds) {
hwInfo.platform.usDeviceID = deviceConfig.deviceIds->front();
}
@ -204,14 +191,6 @@ bool OclocArgHelper::getHwInfoForProductConfig(uint32_t config, NEO::HardwareInf
return retVal;
}
void OclocArgHelper::getProductConfigsForGfxCoreFamily(GFXCORE_FAMILY core, std::vector<DeviceMapping> &out) {
for (auto &deviceConfig : deviceMap) {
if (deviceConfig.hwInfo->platform.eRenderCoreFamily == core) {
out.push_back(deviceConfig);
}
}
}
void OclocArgHelper::saveOutput(const std::string &filename, const void *pData, const size_t &dataSize) {
if (outputEnabled()) {
addOutput(filename, pData, dataSize);
@ -231,6 +210,60 @@ void OclocArgHelper::saveOutput(const std::string &filename, const std::ostream
}
}
std::string OclocArgHelper::getAllSupportedAcronyms() {
std::ostringstream os;
for (const auto &device : deviceMap) {
for (const auto &acronym : device.acronyms) {
if (os.tellp())
os << ", ";
os << acronym.str();
}
}
return os.str();
}
std::vector<NEO::ConstStringRef> OclocArgHelper::getEnabledProductAcronyms() {
std::vector<NEO::ConstStringRef> enabledAcronyms{};
for (const auto &device : deviceMap) {
if (!device.acronyms.empty()) {
enabledAcronyms.push_back(device.acronyms.front());
}
}
return enabledAcronyms;
}
std::vector<NEO::ConstStringRef> OclocArgHelper::getEnabledReleasesAcronyms() {
std::vector<NEO::ConstStringRef> ret;
for (const auto &[acronym, value] : AOT::releaseAcronyms) {
if (std::any_of(deviceMap.begin(), deviceMap.end(), findRelease(value))) {
ret.push_back(NEO::ConstStringRef(acronym));
}
}
return ret;
}
std::vector<NEO::ConstStringRef> OclocArgHelper::getEnabledFamiliesAcronyms() {
std::vector<NEO::ConstStringRef> enabledAcronyms;
for (const auto &[acronym, value] : AOT::familyAcronyms) {
if (std::any_of(deviceMap.begin(), deviceMap.end(), findFamily(value))) {
enabledAcronyms.push_back(NEO::ConstStringRef(acronym));
}
}
return enabledAcronyms;
}
bool OclocArgHelper::setAcronymForDeviceId(std::string &device) {
auto product = returnProductNameForDevice(std::stoi(device, 0, 16));
if (!product.empty()) {
printf("Auto-detected target based on %s device id: %s\n", device.c_str(), product.c_str());
} else {
printf("Could not determine target based on device id: %s\n", device.c_str());
return false;
}
device = std::move(product);
return true;
}
std::string OclocArgHelper::returnProductNameForDevice(unsigned short deviceId) {
std::string res = "";
for (int i = 0; deviceProductTable[i].deviceId != 0; i++) {
@ -245,15 +278,6 @@ std::vector<DeviceMapping> &OclocArgHelper::getAllSupportedDeviceConfigs() {
return deviceMap;
}
std::vector<PRODUCT_CONFIG> OclocArgHelper::getAllSupportedProductConfigs() {
std::vector<PRODUCT_CONFIG> allConfigs;
for (auto &deviceConfig : deviceMap) {
allConfigs.push_back(deviceConfig.config);
}
std::sort(allConfigs.begin(), allConfigs.end());
return allConfigs;
}
int OclocArgHelper::parseProductConfigFromString(const std::string &device, size_t begin, size_t end) {
if (begin == end) {
return CONFIG_STATUS::MISMATCHED_VALUE;
@ -271,119 +295,55 @@ int OclocArgHelper::parseProductConfigFromString(const std::string &device, size
}
}
std::vector<uint32_t> OclocArgHelper::getMajorMinorRevision(const std::string &device) {
std::vector<uint32_t> numeration;
AheadOfTimeConfig OclocArgHelper::getMajorMinorRevision(const std::string &device) {
AheadOfTimeConfig product = {AOT::UNKNOWN_ISA};
auto majorPos = device.find(".");
auto major = parseProductConfigFromString(device, 0, majorPos);
if (major == CONFIG_STATUS::MISMATCHED_VALUE) {
return {};
}
numeration.push_back(major);
if (majorPos == std::string::npos) {
return numeration;
if (major == CONFIG_STATUS::MISMATCHED_VALUE || majorPos == std::string::npos) {
return product;
}
auto minorPos = device.find(".", ++majorPos);
auto minor = parseProductConfigFromString(device, majorPos, minorPos);
if (minor == CONFIG_STATUS::MISMATCHED_VALUE) {
return {};
}
numeration.push_back(minor);
if (minorPos == std::string::npos) {
return numeration;
if (minor == CONFIG_STATUS::MISMATCHED_VALUE || minorPos == std::string::npos) {
return product;
}
auto revision = parseProductConfigFromString(device, minorPos + 1, device.size());
if (revision == CONFIG_STATUS::MISMATCHED_VALUE) {
return {};
return product;
}
numeration.push_back(revision);
return numeration;
product.ProductConfigID.Major = major;
product.ProductConfigID.Minor = minor;
product.ProductConfigID.Revision = revision;
return product;
}
uint32_t OclocArgHelper::getProductConfig(std::vector<uint32_t> &numeration) {
uint32_t config = 0x0;
config = numeration.at(0) << 16;
if (numeration.size() > 1) {
config |= (numeration.at(1) << 8);
bool OclocArgHelper::isRelease(const std::string &device) {
auto release = ProductConfigHelper::returnReleaseForAcronym(device);
if (release == AOT::UNKNOWN_RELEASE) {
return false;
}
if (numeration.size() > 2) {
config |= numeration.at(2);
}
return config;
return std::any_of(deviceMap.begin(), deviceMap.end(), findRelease(release));
}
uint32_t OclocArgHelper::getMaskForConfig(std::vector<uint32_t> &numeration) {
uint32_t mask = 0xffffff;
if (numeration.size() == 1) {
mask = 0xff0000;
} else if (numeration.size() == 2) {
mask = 0xffff00;
bool OclocArgHelper::isFamily(const std::string &device) {
auto family = ProductConfigHelper::returnFamilyForAcronym(device);
if (family == AOT::UNKNOWN_FAMILY) {
return false;
}
return mask;
return std::any_of(deviceMap.begin(), deviceMap.end(), findFamily(family));
}
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;
bool OclocArgHelper::isProductConfig(const std::string &device) {
auto config = ProductConfigHelper::returnProductConfigForAcronym(device);
if (config == AOT::UNKNOWN_ISA) {
return false;
}
return std::any_of(deviceMap.begin(), deviceMap.end(), findProductConfig(config));
}
bool OclocArgHelper::areQuotesRequired(const std::string_view &argName) {
return argName == "-options" || argName == "-internal_options";
}
PRODUCT_CONFIG OclocArgHelper::findConfigMatch(const std::string &device, bool firstAppearance) {
auto numeration = getMajorMinorRevision(device);
if (numeration.empty()) {
return PRODUCT_CONFIG::UNKNOWN_ISA;
}
std::vector<PRODUCT_CONFIG> allMatchedConfigs;
std::vector<PRODUCT_CONFIG> allConfigs = getAllSupportedProductConfigs();
auto configValue = getProductConfig(numeration);
uint32_t mask = getMaskForConfig(numeration);
if (!firstAppearance) {
// find last appearance
std::reverse(allConfigs.begin(), allConfigs.end());
}
for (auto &productConfig : allConfigs) {
uint32_t value = static_cast<uint32_t>(productConfig) & mask;
if (value == configValue) {
return productConfig;
}
}
return PRODUCT_CONFIG::UNKNOWN_ISA;
}
void OclocArgHelper::insertGenNames(GFXCORE_FAMILY family) {
std::string genName = NEO::familyName[family];
std::transform(genName.begin(), genName.end(), genName.begin(), ::tolower);
genIGFXMap.insert({genName, family});
auto findCore = genName.find("_core");
if (findCore != std::string::npos) {
genName = genName.substr(0, findCore);
genIGFXMap.insert({genName, family});
}
auto findUnderline = genName.find("_");
if (findUnderline != std::string::npos) {
genName.erase(std::remove(genName.begin(), genName.end(), '_'), genName.end());
genIGFXMap.insert({genName, family});
}
}

View File

@ -9,6 +9,8 @@
#include "shared/offline_compiler/source/decoder/helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/product_config_helper.h"
#include "shared/source/utilities/const_stringref.h"
#include "device_ids_configs.h"
#include "hw_cmds.h"
@ -48,13 +50,15 @@ struct DeviceProduct {
};
struct DeviceMapping {
PRODUCT_CONFIG config = UNKNOWN_ISA;
const NEO::HardwareInfo *hwInfo = nullptr;
const std::vector<unsigned short> *deviceIds = nullptr;
unsigned int revId = 0U;
AOT::FAMILY family = AOT::UNKNOWN_FAMILY;
AOT::RELEASE release = AOT::UNKNOWN_RELEASE;
AheadOfTimeConfig aotConfig = {0};
std::vector<NEO::ConstStringRef> acronyms{};
bool operator==(const DeviceMapping &rhs) {
return config == rhs.config && hwInfo == rhs.hwInfo && revId == rhs.revId;
return aotConfig.ProductConfig == rhs.aotConfig.ProductConfig && family == rhs.family && release == rhs.release;
}
};
@ -70,9 +74,6 @@ class OclocArgHelper {
MessagePrinter messagePrinter;
const std::vector<DeviceProduct> deviceProductTable;
std::vector<DeviceMapping> deviceMap;
DeviceMapping deviceForFatbinary;
std::map<std::string, unsigned int> genIGFXMap;
bool fatBinary = false;
void moveOutputs();
Source *findSourceFile(const std::string &filename);
bool sourceFileExists(const std::string &filename) const;
@ -82,11 +83,22 @@ class OclocArgHelper {
}
static bool compareConfigs(DeviceMapping deviceMap0, DeviceMapping deviceMap1) {
return deviceMap0.config < deviceMap1.config;
return deviceMap0.aotConfig.ProductConfig < deviceMap1.aotConfig.ProductConfig;
}
static bool isDuplicateConfig(DeviceMapping deviceMap0, DeviceMapping deviceMap1) {
return deviceMap0.config == deviceMap1.config;
template <typename EqComparableT>
auto findFamily(const EqComparableT &lhs) {
return [&lhs](const auto &rhs) { return lhs == rhs.family; };
}
template <typename EqComparableT>
auto findRelease(const EqComparableT &lhs) {
return [&lhs](const auto &rhs) { return lhs == rhs.release; };
}
template <typename EqComparableT>
auto findProductConfig(const EqComparableT &lhs) {
return [&lhs](const auto &rhs) { return lhs == rhs.aotConfig.ProductConfig; };
}
public:
@ -105,16 +117,13 @@ class OclocArgHelper {
MOCKABLE_VIRTUAL bool fileExists(const std::string &filename) const;
int parseProductConfigFromString(const std::string &device, size_t begin, size_t end);
bool getHwInfoForProductConfig(uint32_t config, NEO::HardwareInfo &hwInfo);
void getProductConfigsForGfxCoreFamily(GFXCORE_FAMILY core, std::vector<DeviceMapping> &out);
void setDeviceInfoForFatbinaryTarget(const DeviceMapping &device);
void setHwInfoForFatbinaryTarget(NEO::HardwareInfo &hwInfo);
std::vector<PRODUCT_CONFIG> getAllSupportedProductConfigs();
std::vector<DeviceMapping> &getAllSupportedDeviceConfigs();
std::vector<uint32_t> getMajorMinorRevision(const std::string &device);
uint32_t getProductConfig(std::vector<uint32_t> &numeration);
uint32_t getMaskForConfig(std::vector<uint32_t> &numeration);
PRODUCT_CONFIG findConfigMatch(const std::string &device, bool firstAppearance);
void insertGenNames(GFXCORE_FAMILY family);
std::vector<NEO::ConstStringRef> getEnabledProductAcronyms();
std::vector<NEO::ConstStringRef> getEnabledReleasesAcronyms();
std::vector<NEO::ConstStringRef> getEnabledFamiliesAcronyms();
std::string getAllSupportedAcronyms();
AheadOfTimeConfig getMajorMinorRevision(const std::string &device);
bool setAcronymForDeviceId(std::string &device);
std::vector<std::string> headersToVectorOfStrings();
MOCKABLE_VIRTUAL void readFileToVectorOfStrings(const std::string &filename, std::vector<std::string> &lines);
MOCKABLE_VIRTUAL std::vector<char> readBinaryFile(const std::string &filename);
@ -130,13 +139,6 @@ class OclocArgHelper {
return headers;
}
void setFatbinary(bool isFatBinary) {
this->fatBinary = isFatBinary;
}
bool isFatbinary() {
return fatBinary;
}
MOCKABLE_VIRTUAL void saveOutput(const std::string &filename, const void *pData, const size_t &dataSize);
void saveOutput(const std::string &filename, const std::ostream &stream);
@ -149,8 +151,10 @@ 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);
bool isRelease(const std::string &device);
bool isFamily(const std::string &device);
bool isProductConfig(const std::string &device);
bool areQuotesRequired(const std::string_view &argName);
std::string returnProductNameForDevice(unsigned short deviceId);
};

View File

@ -23,295 +23,195 @@
#include <cstdio>
namespace NEO {
std::vector<PRODUCT_CONFIG> getAllMatchedConfigs(const std::string device, OclocArgHelper *argHelper) {
std::vector<PRODUCT_CONFIG> allMatchedConfigs;
auto numeration = argHelper->getMajorMinorRevision(device);
if (numeration.empty()) {
return {};
}
auto config = argHelper->getProductConfig(numeration);
std::vector<PRODUCT_CONFIG> allConfigs = argHelper->getAllSupportedProductConfigs();
uint32_t mask = argHelper->getMaskForConfig(numeration);
for (auto &productConfig : allConfigs) {
auto prod = static_cast<uint32_t>(productConfig) & mask;
if (config == prod) {
allMatchedConfigs.push_back(productConfig);
}
}
return allMatchedConfigs;
}
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]);
auto products = getAllMatchedConfigs(deviceArg.str(), helper);
if (products.size() > 1) {
return true;
}
return deviceArg.contains("*") || deviceArg.contains("-") || deviceArg.contains(",") || helper->isGen(deviceArg.str());
auto retVal = deviceArg.contains("*");
retVal |= deviceArg.contains(":");
retVal |= deviceArg.contains(",");
retVal |= helper->isFamily(deviceArg.str());
retVal |= helper->isRelease(deviceArg.str());
return retVal;
}
}
return false;
}
std::vector<PRODUCT_FAMILY> getAllSupportedTargetPlatforms() {
return std::vector<PRODUCT_FAMILY>{ALL_SUPPORTED_PRODUCT_FAMILIES};
}
std::vector<ConstStringRef> toProductNames(const std::vector<PRODUCT_FAMILY> &productIds) {
std::vector<ConstStringRef> ret;
for (auto prodId : productIds) {
ret.push_back(ConstStringRef(hardwarePrefix[prodId], strlen(hardwarePrefix[prodId])));
}
return ret;
}
PRODUCT_FAMILY asProductId(ConstStringRef product, const std::vector<PRODUCT_FAMILY> &allSupportedPlatforms) {
for (auto &family : allSupportedPlatforms) {
if (product == hardwarePrefix[family]) {
return family;
}
}
return IGFX_UNKNOWN;
}
std::vector<DeviceMapping> getProductConfigsForOpenRange(ConstStringRef openRange, OclocArgHelper *argHelper, bool rangeTo) {
std::vector<DeviceMapping> requestedConfigs;
std::vector<DeviceMapping> allSupportedDeviceConfigs = argHelper->getAllSupportedDeviceConfigs();
if (argHelper->isGen(openRange.str())) {
std::vector<GFXCORE_FAMILY> coreIdList;
auto coreId = argHelper->returnIGFXforGen(openRange.str());
coreIdList.push_back(static_cast<GFXCORE_FAMILY>(coreId));
if (rangeTo) {
auto coreId = coreIdList.back();
unsigned int coreIt = IGFX_UNKNOWN_CORE;
++coreIt;
while (coreIt <= static_cast<unsigned int>(coreId)) {
argHelper->getProductConfigsForGfxCoreFamily(static_cast<GFXCORE_FAMILY>(coreIt), requestedConfigs);
++coreIt;
}
} else {
unsigned int coreIt = coreIdList.front();
while (coreIt < static_cast<unsigned int>(IGFX_MAX_CORE)) {
argHelper->getProductConfigsForGfxCoreFamily(static_cast<GFXCORE_FAMILY>(coreIt), requestedConfigs);
++coreIt;
template <>
void getProductsAcronymsForTarget<AOT::FAMILY>(std::vector<NEO::ConstStringRef> &out, AOT::FAMILY target, OclocArgHelper *argHelper) {
auto allSuppportedProducts = argHelper->getAllSupportedDeviceConfigs();
for (const auto &device : allSuppportedProducts) {
if (device.family == target && !device.acronyms.empty()) {
if (std::find(out.begin(), out.end(), device.acronyms.front()) == out.end()) {
out.push_back(device.acronyms.front());
}
}
}
}
template <>
void getProductsAcronymsForTarget<AOT::RELEASE>(std::vector<NEO::ConstStringRef> &out, AOT::RELEASE target, OclocArgHelper *argHelper) {
auto allSuppportedProducts = argHelper->getAllSupportedDeviceConfigs();
for (const auto &device : allSuppportedProducts) {
if (device.release == target && !device.acronyms.empty()) {
if (std::find(out.begin(), out.end(), device.acronyms.front()) == out.end()) {
out.push_back(device.acronyms.front());
}
}
}
}
template <typename T>
void getProductsForTargetRange(T targetFrom, T targetTo, std::vector<ConstStringRef> &out,
OclocArgHelper *argHelper) {
if (targetFrom > targetTo) {
std::swap(targetFrom, targetTo);
}
while (targetFrom <= targetTo) {
getProductsAcronymsForTarget<T>(out, targetFrom, argHelper);
targetFrom = static_cast<T>(static_cast<unsigned int>(targetFrom) + 1);
}
}
void getProductsForRange(unsigned int productFrom, unsigned int productTo, std::vector<ConstStringRef> &out,
OclocArgHelper *argHelper) {
auto allSuppportedProducts = argHelper->getAllSupportedDeviceConfigs();
for (const auto &device : allSuppportedProducts) {
auto validAcronym = device.aotConfig.ProductConfig >= productFrom;
validAcronym &= device.aotConfig.ProductConfig <= productTo;
validAcronym &= !device.acronyms.empty();
if (validAcronym) {
out.push_back(device.acronyms.front());
}
}
}
std::vector<ConstStringRef> getProductForClosedRange(ConstStringRef rangeFrom, ConstStringRef rangeTo, OclocArgHelper *argHelper) {
std::vector<ConstStringRef> requestedProducts = {};
auto rangeFromStr = rangeFrom.str();
auto rangeToStr = rangeTo.str();
if (argHelper->isFamily(rangeFromStr) && argHelper->isFamily(rangeToStr)) {
auto familyFrom = ProductConfigHelper::returnFamilyForAcronym(rangeFromStr);
auto familyTo = ProductConfigHelper::returnFamilyForAcronym(rangeToStr);
getProductsForTargetRange(familyFrom, familyTo, requestedProducts, argHelper);
} else if (argHelper->isRelease(rangeFromStr) && argHelper->isRelease(rangeToStr)) {
auto releaseFrom = ProductConfigHelper::returnReleaseForAcronym(rangeFromStr);
auto releaseTo = ProductConfigHelper::returnReleaseForAcronym(rangeToStr);
getProductsForTargetRange(releaseFrom, releaseTo, requestedProducts, argHelper);
} else if (argHelper->isProductConfig(rangeFromStr) && argHelper->isProductConfig(rangeToStr)) {
unsigned int productConfigFrom = ProductConfigHelper::returnProductConfigForAcronym(rangeFromStr);
unsigned int productConfigTo = ProductConfigHelper::returnProductConfigForAcronym(rangeToStr);
if (productConfigFrom > productConfigTo) {
std::swap(productConfigFrom, productConfigTo);
}
getProductsForRange(productConfigFrom, productConfigTo, requestedProducts, argHelper);
} else {
auto productConfig = argHelper->findConfigMatch(openRange.str(), !rangeTo);
if (productConfig == PRODUCT_CONFIG::UNKNOWN_ISA) {
argHelper->printf("Unknown device : %s\n", openRange.str().c_str());
return {};
}
auto configIt = std::find_if(allSupportedDeviceConfigs.begin(),
allSupportedDeviceConfigs.end(),
[&cf = productConfig](const DeviceMapping &c) -> bool { return cf == c.config; });
if (rangeTo) {
for (auto &deviceConfig : allSupportedDeviceConfigs) {
if (deviceConfig.config <= productConfig) {
requestedConfigs.push_back(deviceConfig);
}
}
} else {
requestedConfigs.insert(requestedConfigs.end(), configIt, allSupportedDeviceConfigs.end());
}
}
return requestedConfigs;
}
std::vector<DeviceMapping> getProductConfigsForClosedRange(ConstStringRef rangeFrom, ConstStringRef rangeTo, OclocArgHelper *argHelper) {
std::vector<DeviceMapping> requestedConfigs;
std::vector<DeviceMapping> allSupportedDeviceConfigs = argHelper->getAllSupportedDeviceConfigs();
if (argHelper->isGen(rangeFrom.str())) {
if (false == argHelper->isGen(rangeTo.str())) {
argHelper->printf("Ranges mixing configs and architecture is not supported, should be architectureFrom-architectureTo or configFrom-configTo\n");
return {};
}
auto coreFrom = argHelper->returnIGFXforGen(rangeFrom.str());
auto coreTo = argHelper->returnIGFXforGen(rangeTo.str());
if (static_cast<GFXCORE_FAMILY>(coreFrom) > static_cast<GFXCORE_FAMILY>(coreTo)) {
std::swap(coreFrom, coreTo);
}
while (coreFrom <= coreTo) {
argHelper->getProductConfigsForGfxCoreFamily(static_cast<GFXCORE_FAMILY>(coreFrom), requestedConfigs);
coreFrom = static_cast<GFXCORE_FAMILY>(static_cast<unsigned int>(coreFrom) + 1);
}
} else {
auto configFrom = argHelper->findConfigMatch(rangeFrom.str(), true);
if (configFrom == PRODUCT_CONFIG::UNKNOWN_ISA) {
argHelper->printf("Unknown device range : %s\n", rangeFrom.str().c_str());
return {};
}
auto configTo = argHelper->findConfigMatch(rangeTo.str(), false);
if (configTo == PRODUCT_CONFIG::UNKNOWN_ISA) {
argHelper->printf("Unknown device range : %s\n", rangeTo.str().c_str());
return {};
}
if (configFrom > configTo) {
configFrom = argHelper->findConfigMatch(rangeTo.str(), true);
configTo = argHelper->findConfigMatch(rangeFrom.str(), false);
}
for (auto &deviceConfig : allSupportedDeviceConfigs) {
if (deviceConfig.config >= configFrom && deviceConfig.config <= configTo) {
requestedConfigs.push_back(deviceConfig);
}
}
}
return requestedConfigs;
}
std::vector<ConstStringRef> getPlatformsForClosedRange(ConstStringRef rangeFrom, ConstStringRef rangeTo, PRODUCT_FAMILY platformFrom, OclocArgHelper *argHelper) {
std::vector<PRODUCT_FAMILY> requestedPlatforms;
std::vector<PRODUCT_FAMILY> allSupportedPlatforms = getAllSupportedTargetPlatforms();
auto platformTo = asProductId(rangeTo, allSupportedPlatforms);
if (IGFX_UNKNOWN == platformTo) {
argHelper->printf("Unknown device : %s\n", rangeTo.str().c_str());
auto target = rangeFromStr + ":" + rangeToStr;
argHelper->printf("Failed to parse target : %s.\n", target.c_str());
return {};
}
if (platformFrom > platformTo) {
std::swap(platformFrom, platformTo);
}
auto from = std::find(allSupportedPlatforms.begin(), allSupportedPlatforms.end(), platformFrom);
auto to = std::find(allSupportedPlatforms.begin(), allSupportedPlatforms.end(), platformTo) + 1;
requestedPlatforms.insert(requestedPlatforms.end(), from, to);
return toProductNames(requestedPlatforms);
return requestedProducts;
}
std::vector<ConstStringRef> getPlatformsForOpenRange(ConstStringRef openRange, PRODUCT_FAMILY prodId, OclocArgHelper *argHelper, bool rangeTo) {
std::vector<PRODUCT_FAMILY> requestedPlatforms;
std::vector<PRODUCT_FAMILY> allSupportedPlatforms = getAllSupportedTargetPlatforms();
std::vector<ConstStringRef> getProductForOpenRange(ConstStringRef openRange, OclocArgHelper *argHelper, bool rangeTo) {
std::vector<ConstStringRef> requestedProducts = {};
auto openRangeStr = openRange.str();
auto prodIt = std::find(allSupportedPlatforms.begin(), allSupportedPlatforms.end(), prodId);
assert(prodIt != allSupportedPlatforms.end());
if (rangeTo) {
requestedPlatforms.insert(requestedPlatforms.end(), allSupportedPlatforms.begin(), prodIt + 1);
} else {
requestedPlatforms.insert(requestedPlatforms.end(), prodIt, allSupportedPlatforms.end());
}
return toProductNames(requestedPlatforms);
}
std::vector<DeviceMapping> getProductConfigsForSpecificTargets(CompilerOptions::TokenizedString targets, OclocArgHelper *argHelper) {
std::vector<DeviceMapping> requestedConfigs;
std::vector<DeviceMapping> allSupportedDeviceConfigs = argHelper->getAllSupportedDeviceConfigs();
for (auto &target : targets) {
if (argHelper->isGen(target.str())) {
auto coreId = argHelper->returnIGFXforGen(target.str());
argHelper->getProductConfigsForGfxCoreFamily(static_cast<GFXCORE_FAMILY>(coreId), requestedConfigs);
if (argHelper->isFamily(openRangeStr)) {
auto family = ProductConfigHelper::returnFamilyForAcronym(openRangeStr);
if (rangeTo) {
unsigned int familyFrom = AOT::UNKNOWN_FAMILY;
++familyFrom;
getProductsForTargetRange(static_cast<AOT::FAMILY>(familyFrom), family, requestedProducts, argHelper);
} else {
auto configFirstEl = argHelper->findConfigMatch(target.str(), true);
if (configFirstEl == PRODUCT_CONFIG::UNKNOWN_ISA) {
argHelper->printf("Unknown device range : %s\n", target.str().c_str());
return {};
}
unsigned int familyTo = AOT::FAMILY_MAX;
--familyTo;
getProductsForTargetRange(family, static_cast<AOT::FAMILY>(familyTo), requestedProducts, argHelper);
}
} else if (argHelper->isRelease(openRangeStr)) {
auto release = ProductConfigHelper::returnReleaseForAcronym(openRangeStr);
if (rangeTo) {
unsigned int releaseFrom = AOT::UNKNOWN_FAMILY;
++releaseFrom;
getProductsForTargetRange(static_cast<AOT::RELEASE>(releaseFrom), release, requestedProducts, argHelper);
} else {
unsigned int releaseTo = AOT::RELEASE_MAX;
--releaseTo;
getProductsForTargetRange(release, static_cast<AOT::RELEASE>(releaseTo), requestedProducts, argHelper);
}
} else if (argHelper->isProductConfig(openRangeStr)) {
auto product = ProductConfigHelper::returnProductConfigForAcronym(openRangeStr);
if (rangeTo) {
unsigned int productFrom = AOT::UNKNOWN_ISA;
++productFrom;
getProductsForRange(productFrom, static_cast<unsigned int>(product), requestedProducts, argHelper);
} else {
unsigned int productTo = AOT::CONFIG_MAX_PLATFORM;
--productTo;
getProductsForRange(product, static_cast<AOT::PRODUCT_CONFIG>(productTo), requestedProducts, argHelper);
}
}
return requestedProducts;
}
auto configLastEl = argHelper->findConfigMatch(target.str(), false);
for (auto &deviceConfig : allSupportedDeviceConfigs) {
if (deviceConfig.config >= configFirstEl && deviceConfig.config <= configLastEl) {
requestedConfigs.push_back(deviceConfig);
}
}
std::vector<ConstStringRef> getProductForSpecificTarget(CompilerOptions::TokenizedString targets, OclocArgHelper *argHelper) {
std::vector<ConstStringRef> requestedConfigs;
for (const auto &target : targets) {
auto targetStr = target.str();
if (argHelper->isFamily(targetStr)) {
auto family = ProductConfigHelper::returnFamilyForAcronym(targetStr);
getProductsAcronymsForTarget(requestedConfigs, family, argHelper);
} else if (argHelper->isRelease(targetStr)) {
auto release = ProductConfigHelper::returnReleaseForAcronym(targetStr);
getProductsAcronymsForTarget(requestedConfigs, release, argHelper);
} else if (argHelper->isProductConfig(targetStr)) {
requestedConfigs.push_back(target);
} else {
argHelper->printf("Failed to parse target : %s - invalid device:\n", targetStr.c_str());
return {};
}
}
return requestedConfigs;
}
std::vector<ConstStringRef> getPlatformsForSpecificTargets(CompilerOptions::TokenizedString targets, OclocArgHelper *argHelper) {
std::vector<PRODUCT_FAMILY> requestedPlatforms;
std::vector<PRODUCT_FAMILY> allSupportedPlatforms = getAllSupportedTargetPlatforms();
for (auto &target : targets) {
auto prodId = asProductId(target, allSupportedPlatforms);
if (IGFX_UNKNOWN == prodId) {
argHelper->printf("Unknown device : %s\n", target.str().c_str());
return {};
}
requestedPlatforms.push_back(prodId);
}
return toProductNames(requestedPlatforms);
}
bool isDeviceWithPlatformAbbreviation(ConstStringRef deviceArg, OclocArgHelper *argHelper) {
std::vector<PRODUCT_FAMILY> allSupportedPlatforms = getAllSupportedTargetPlatforms();
PRODUCT_FAMILY prodId = IGFX_UNKNOWN;
auto sets = CompilerOptions::tokenize(deviceArg, ',');
if (sets[0].contains("-")) {
auto range = CompilerOptions::tokenize(deviceArg, '-');
prodId = asProductId(range[0], allSupportedPlatforms);
} else {
prodId = asProductId(sets[0], allSupportedPlatforms);
}
return prodId != IGFX_UNKNOWN;
}
std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef deviceArg, OclocArgHelper *argHelper) {
std::vector<PRODUCT_FAMILY> allSupportedPlatforms = getAllSupportedTargetPlatforms();
std::vector<ConstStringRef> getTargetProductsForFatbinary(ConstStringRef deviceArg, OclocArgHelper *argHelper) {
std::vector<ConstStringRef> retVal;
auto sets = CompilerOptions::tokenize(deviceArg, ',');
if (sets[0].contains("-")) {
auto range = CompilerOptions::tokenize(deviceArg, '-');
if (range.size() > 2) {
argHelper->printf("Invalid range : %s - should be from-to or -to or from-\n", sets[0].str().c_str());
return {};
}
auto prodId = asProductId(range[0], allSupportedPlatforms);
if (range.size() == 1) {
bool rangeTo = ('-' == sets[0][0]);
retVal = getPlatformsForOpenRange(range[0], prodId, argHelper, rangeTo);
} else {
retVal = getPlatformsForClosedRange(range[0], range[1], prodId, argHelper);
}
} else {
retVal = getPlatformsForSpecificTargets(sets, argHelper);
}
return retVal;
}
std::vector<DeviceMapping> getTargetConfigsForFatbinary(ConstStringRef deviceArg, OclocArgHelper *argHelper) {
if (deviceArg == "*") {
return argHelper->getAllSupportedDeviceConfigs();
}
std::vector<DeviceMapping> retVal;
auto sets = CompilerOptions::tokenize(deviceArg, ',');
if (sets[0].contains("-")) {
auto range = CompilerOptions::tokenize(deviceArg, '-');
if (range.size() > 2) {
argHelper->printf("Invalid range : %s - should be from-to or -to or from-\n", sets[0].str().c_str());
return {};
}
if (range.size() == 1) {
bool rangeTo = ('-' == sets[0][0]);
retVal = getProductConfigsForOpenRange(range[0], argHelper, rangeTo);
} else {
retVal = getProductConfigsForClosedRange(range[0], range[1], argHelper);
}
return argHelper->getEnabledProductAcronyms();
} else {
retVal = getProductConfigsForSpecificTargets(sets, argHelper);
auto sets = CompilerOptions::tokenize(deviceArg, ',');
if (sets[0].contains(":")) {
auto range = CompilerOptions::tokenize(deviceArg, ':');
if (range.size() > 2) {
argHelper->printf("Invalid range : %s - should be from:to or :to or from:\n", sets[0].str().c_str());
return {};
}
if (range.size() == 1) {
bool rangeTo = (':' == sets[0][0]);
retVal = getProductForOpenRange(range[0], argHelper, rangeTo);
} else {
retVal = getProductForClosedRange(range[0], range[1], argHelper);
}
} else {
retVal = getProductForSpecificTarget(sets, argHelper);
}
}
return retVal;
}
int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy, std::string pointerSize, Ar::ArEncoder &fatbinary,
OfflineCompiler *pCompiler, OclocArgHelper *argHelper, const std::string &deviceConfig) {
OfflineCompiler *pCompiler, OclocArgHelper *argHelper, const std::string &product) {
if (retVal == 0) {
retVal = buildWithSafetyGuard(pCompiler);
@ -321,9 +221,9 @@ int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy
}
if (retVal == 0) {
if (!pCompiler->isQuiet())
argHelper->printf("Build succeeded for : %s.\n", deviceConfig.c_str());
argHelper->printf("Build succeeded for : %s.\n", product.c_str());
} else {
argHelper->printf("Build failed for : %s with error code: %d\n", deviceConfig.c_str(), retVal);
argHelper->printf("Build failed for : %s with error code: %d\n", product.c_str(), retVal);
argHelper->printf("Command was:");
for (const auto &arg : argsCopy)
argHelper->printf(" %s", arg.c_str());
@ -333,7 +233,8 @@ int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy
if (retVal) {
return retVal;
}
fatbinary.appendFileEntry(pointerSize + "." + deviceConfig, pCompiler->getPackedDeviceBinaryOutput());
auto productConfig = ProductConfigHelper::parseMajorMinorRevisionValue(ProductConfigHelper::returnProductConfigForAcronym(product));
fatbinary.appendFileEntry(pointerSize + "." + productConfig, pCompiler->getPackedDeviceBinaryOutput());
return retVal;
}
@ -384,56 +285,25 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
}
Ar::ArEncoder fatbinary(true);
if (isDeviceWithPlatformAbbreviation(ConstStringRef(args[deviceArgIndex]), argHelper)) {
std::vector<ConstStringRef> targetPlatforms;
targetPlatforms = getTargetPlatformsForFatbinary(ConstStringRef(args[deviceArgIndex]), argHelper);
if (targetPlatforms.empty()) {
argHelper->printf("Failed to parse target devices from : %s\n", args[deviceArgIndex].c_str());
return 1;
}
for (auto &targetPlatform : targetPlatforms) {
int retVal = 0;
argsCopy[deviceArgIndex] = targetPlatform.str();
std::vector<ConstStringRef> targetProducts;
targetProducts = getTargetProductsForFatbinary(ConstStringRef(args[deviceArgIndex]), argHelper);
if (targetProducts.empty()) {
argHelper->printf("Failed to parse target devices from : %s\n", args[deviceArgIndex].c_str());
return 1;
}
for (const auto &product : targetProducts) {
int retVal = 0;
argsCopy[deviceArgIndex] = product.str();
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(argsCopy.size(), argsCopy, false, retVal, argHelper)};
if (OclocErrorCode::SUCCESS != retVal) {
argHelper->printf("Error! Couldn't create OfflineCompiler. Exiting.\n");
return retVal;
}
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;
}
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(argsCopy.size(), argsCopy, false, retVal, argHelper)};
if (OclocErrorCode::SUCCESS != retVal) {
argHelper->printf("Error! Couldn't create OfflineCompiler. Exiting.\n");
return retVal;
}
} else {
std::vector<DeviceMapping> targetConfigs;
targetConfigs = getTargetConfigsForFatbinary(ConstStringRef(args[deviceArgIndex]), argHelper);
if (targetConfigs.empty()) {
argHelper->printf("Failed to parse target devices from : %s\n", args[deviceArgIndex].c_str());
return 1;
}
for (auto &targetConfig : targetConfigs) {
int retVal = 0;
argHelper->setFatbinary(true);
argHelper->setDeviceInfoForFatbinaryTarget(targetConfig);
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(argsCopy.size(), argsCopy, false, retVal, argHelper)};
if (OclocErrorCode::SUCCESS != retVal) {
argHelper->printf("Error! Couldn't create OfflineCompiler. Exiting.\n");
return retVal;
}
auto targetConfigStr = ProductConfigHelper::parseMajorMinorRevisionValue(targetConfig.config);
retVal = buildFatBinaryForTarget(retVal, argsCopy, pointerSizeInBits, fatbinary, pCompiler.get(), argHelper, targetConfigStr);
if (retVal) {
return retVal;
}
retVal = buildFatBinaryForTarget(retVal, argsCopy, pointerSizeInBits, fatbinary, pCompiler.get(), argHelper, product.str());
if (retVal) {
return retVal;
}
}

View File

@ -34,19 +34,9 @@ inline int buildFatBinary(int argc, const char *argv[], OclocArgHelper *argHelpe
return buildFatBinary(args, argHelper);
}
bool isDeviceWithPlatformAbbreviation(ConstStringRef deviceArg, OclocArgHelper *argHelper);
std::vector<PRODUCT_FAMILY> getAllSupportedTargetPlatforms();
std::vector<PRODUCT_CONFIG> getAllMatchedConfigs(const std::string device, OclocArgHelper *argHelper);
std::vector<DeviceMapping> getTargetConfigsForFatbinary(ConstStringRef deviceArg, OclocArgHelper *argHelper);
std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef deviceArg, OclocArgHelper *argHelper);
std::vector<DeviceMapping> getProductConfigsForOpenRange(ConstStringRef openRange, OclocArgHelper *argHelper, bool rangeTo);
std::vector<DeviceMapping> getProductConfigsForClosedRange(ConstStringRef rangeFrom, ConstStringRef rangeTo, OclocArgHelper *argHelper);
std::vector<ConstStringRef> getPlatformsForClosedRange(ConstStringRef rangeFrom, ConstStringRef rangeTo, PRODUCT_FAMILY platformFrom, OclocArgHelper *argHelper);
std::vector<ConstStringRef> getPlatformsForOpenRange(ConstStringRef openRange, PRODUCT_FAMILY prodId, OclocArgHelper *argHelper, bool rangeTo);
std::vector<DeviceMapping> getProductConfigsForSpecificTargets(CompilerOptions::TokenizedString targets, OclocArgHelper *argHelper);
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);
template <typename Target>
void getProductsAcronymsForTarget(std::vector<NEO::ConstStringRef> &out, Target target, OclocArgHelper *argHelper);
std::vector<ConstStringRef> getTargetProductsForFatbinary(ConstStringRef deviceArg, OclocArgHelper *argHelper);
int buildFatBinaryForTarget(int retVal, const std::vector<std::string> &argsCopy, std::string pointerSize, Ar::ArEncoder &fatbinary,
OfflineCompiler *pCompiler, OclocArgHelper *argHelper, const std::string &deviceConfig);
int appendGenericIr(Ar::ArEncoder &fatbinary, const std::string &inputFile, OclocArgHelper *argHelper);

View File

@ -327,75 +327,75 @@ void OfflineCompiler::setFamilyType() {
familyNameWithType.append(hwInfo.capabilityTable.platformType);
}
int OfflineCompiler::initHardwareInfo(std::string deviceName) {
int retVal = INVALID_DEVICE;
int OfflineCompiler::initHardwareInfoForDeprecatedAcronyms(std::string deviceName, int deviceId) {
std::vector<PRODUCT_FAMILY> allSupportedProduct{ALL_SUPPORTED_PRODUCT_FAMILIES};
for (const auto &product : allSupportedProduct) {
if (0 == strcmp(deviceName.c_str(), hardwarePrefix[product])) {
hwInfo = *hardwareInfoTable[product];
if (revisionId != -1) {
hwInfo.platform.usRevId = revisionId;
}
if (deviceId != -1) {
hwInfo.platform.usDeviceID = deviceId;
}
auto hwInfoConfig = defaultHardwareInfoConfigTable[hwInfo.platform.eProductFamily];
setHwInfoValuesFromConfig(hwInfoConfig, hwInfo);
hardwareInfoBaseSetup[hwInfo.platform.eProductFamily](&hwInfo, true);
setFamilyType();
return SUCCESS;
}
}
return INVALID_DEVICE;
}
if (deviceName.empty()) {
return retVal;
int OfflineCompiler::initHardwareInfoForProductConfig(std::string deviceName) {
AheadOfTimeConfig aotConfig{AOT::UNKNOWN_ISA};
if (deviceName.find(".") != std::string::npos) {
aotConfig = argHelper->getMajorMinorRevision(deviceName);
if (aotConfig.ProductConfig == AOT::UNKNOWN_ISA) {
argHelper->printf("Could not determine device target: %s\n", deviceName.c_str());
}
} else if (argHelper->isProductConfig(deviceName)) {
aotConfig.ProductConfig = ProductConfigHelper::returnProductConfigForAcronym(deviceName);
}
if (argHelper->isFatbinary()) {
argHelper->setHwInfoForFatbinaryTarget(hwInfo);
setFamilyType();
retVal = SUCCESS;
if (aotConfig.ProductConfig != AOT::UNKNOWN_ISA) {
if (argHelper->getHwInfoForProductConfig(aotConfig.ProductConfig, hwInfo)) {
if (revisionId != -1) {
hwInfo.platform.usRevId = revisionId;
}
deviceConfig = static_cast<AOT::PRODUCT_CONFIG>(aotConfig.ProductConfig);
setFamilyType();
return SUCCESS;
}
argHelper->printf("Could not determine target based on product config: %s\n", deviceName.c_str());
}
return INVALID_DEVICE;
}
int OfflineCompiler::initHardwareInfo(std::string deviceName) {
int retVal = INVALID_DEVICE;
if (deviceName.empty()) {
return retVal;
}
overridePlatformName(deviceName);
std::transform(deviceName.begin(), deviceName.end(), deviceName.begin(), ::tolower);
const char hexPrefix = 2;
auto deviceId = -1;
std::string product("");
int deviceId = -1;
auto numeration = argHelper->getMajorMinorRevision(deviceName);
if (!numeration.empty()) {
uint32_t productConfig = argHelper->getProductConfig(numeration);
if (argHelper->getHwInfoForProductConfig(productConfig, hwInfo)) {
deviceConfig = static_cast<PRODUCT_CONFIG>(productConfig);
setFamilyType();
retVal = SUCCESS;
return retVal;
}
argHelper->printf("Could not determine target based on product config: %s\n", deviceName.c_str());
return retVal;
} else if (deviceName.find(".") != std::string::npos) {
argHelper->printf("Could not determine target based on product config: %s\n", deviceName.c_str());
retVal = initHardwareInfoForProductConfig(deviceName);
if (retVal == SUCCESS) {
return retVal;
}
if (deviceName.substr(0, hexPrefix) == "0x" && std::all_of(deviceName.begin() + hexPrefix, deviceName.end(), (::isxdigit))) {
deviceId = stoi(deviceName, 0, 16);
product = argHelper->returnProductNameForDevice(deviceId);
if (!product.empty()) {
argHelper->printf("Auto-detected target based on %s device id: %s\n", deviceName.c_str(), product.c_str());
deviceName = product;
} else {
argHelper->printf("Could not determine target based on device id: %s\n", deviceName.c_str());
deviceId = std::stoi(deviceName, 0, 16);
if (!argHelper->setAcronymForDeviceId(deviceName)) {
return retVal;
}
}
for (unsigned int productId = 0; productId < IGFX_MAX_PRODUCT; ++productId) {
if (hardwarePrefix[productId] && (0 == strcmp(deviceName.c_str(), hardwarePrefix[productId]))) {
if (hardwareInfoTable[productId]) {
hwInfo = *hardwareInfoTable[productId];
if (revisionId != -1) {
hwInfo.platform.usRevId = revisionId;
}
if (deviceId != -1) {
hwInfo.platform.usDeviceID = deviceId;
}
auto hwInfoConfig = defaultHardwareInfoConfigTable[hwInfo.platform.eProductFamily];
setHwInfoValuesFromConfig(hwInfoConfig, hwInfo);
hardwareInfoBaseSetup[hwInfo.platform.eProductFamily](&hwInfo, true);
setFamilyType();
retVal = SUCCESS;
break;
}
}
}
retVal = initHardwareInfoForDeprecatedAcronyms(deviceName, deviceId);
return retVal;
}
@ -756,51 +756,52 @@ std::string OfflineCompiler::getFileNameTrunk(std::string &filePath) {
return fileTrunk;
}
std::string getDevicesTypes() {
std::list<std::string> prefixes;
template <typename EqComparableT>
auto findDuplicate(const EqComparableT &lhs) {
return [&lhs](const auto &rhs) { return lhs == rhs; };
}
std::string OfflineCompiler::getDeprecatedDevicesTypes() {
std::vector<std::string> prefixes;
for (int j = 0; j < IGFX_MAX_PRODUCT; j++) {
if (hardwarePrefix[j] == nullptr)
continue;
prefixes.push_back(hardwarePrefix[j]);
}
std::ostringstream os;
for (auto it = prefixes.begin(); it != prefixes.end(); it++) {
if (it != prefixes.begin())
os << ", ";
os << *it;
std::vector<NEO::ConstStringRef> enabledAcronyms{};
auto enabledConfigs = argHelper->getAllSupportedDeviceConfigs();
for (const auto &device : enabledConfigs) {
enabledAcronyms.insert(enabledAcronyms.end(), device.acronyms.begin(), device.acronyms.end());
}
return os.str();
}
std::string getDevicesFamilies() {
std::list<std::string> prefixes;
for (unsigned int i = 0; i < IGFX_MAX_CORE; ++i) {
if (familyName[i] == nullptr)
std::ostringstream os;
for (const auto &prefix : prefixes) {
if (std::any_of(enabledAcronyms.begin(), enabledAcronyms.end(), findDuplicate(prefix)))
continue;
prefixes.push_back(familyName[i]);
}
std::ostringstream os;
for (auto it = prefixes.begin(); it != prefixes.end(); it++) {
if (it != prefixes.begin())
if (os.tellp())
os << ", ";
os << *it;
os << prefix;
}
return os.str();
}
std::string OfflineCompiler::getDevicesConfigs() {
std::list<std::string> configNum;
auto allSupportedConfigs = argHelper->getAllSupportedProductConfigs();
std::string OfflineCompiler::getDevicesReleasesAndFamilies() {
auto acronyms = argHelper->getEnabledReleasesAcronyms();
auto familiesAcronyms = argHelper->getEnabledFamiliesAcronyms();
for (const auto &family : familiesAcronyms) {
if (!std::any_of(acronyms.begin(), acronyms.end(), findDuplicate(family))) {
acronyms.push_back(family);
}
}
std::ostringstream os;
for (auto it = allSupportedConfigs.begin(); it != allSupportedConfigs.end(); it++) {
if (it != allSupportedConfigs.begin())
for (const auto &acronym : acronyms) {
if (os.tellp())
os << ", ";
os << ProductConfigHelper::parseMajorMinorRevisionValue(*it);
os << acronym.str();
}
return os.str();
@ -818,14 +819,9 @@ Usage: ocloc [compile] -file <filename> -device <device_type> [-output <filename
OpenCL C kernel language).
-device <device_type> Target device.
<device_type> can be: %s, %s or hexadecimal value with 0x prefix - can be single or multiple target devices.
The <major>[<minor>[.<revision>]] numbers:
<major> - family of graphics products,
<minor> - can be omitted, then ocloc will
compile for all of the <major> matching devices.
<revision> - can be omitted, then ocloc will
compile for all of the <major>.<minor> matching
devices.
<device_type> can be: %s, %s, version or hexadecimal value with 0x prefix - can be single or multiple target devices.
The version is a representation of the
<major>.<minor>.<revision> value.
The hexadecimal value represents device ID.
If such value is provided, ocloc will try to
match it with corresponding device type.
@ -836,41 +832,31 @@ Usage: ocloc [compile] -file <filename> -device <device_type> [-output <filename
create a fatbinary archive that contains all of
device binaries produced this way.
Supported -device patterns examples:
-device 0xFF20 ; will compile 1 target (tgllp)
-device 12.0.7 ; will compile 1 target (dg1)
-device 11 ; will compile the architecture
(gen11)
-device 9.0,11.0 ; will compile 2 targets
(skl & icllp)
-device 9.0-11.0 ; will compile all targets
in range (inclusive)
-device 9.0- ; will compile all targets
newer/same as provided
-device -9.0 ; will compile all targets
older/same as provided
-device * ; will compile all targets
known to ocloc
-device 0x4905 ; will compile 1 target (dg1)
-device 12.10.0 ; will compile 1 target (dg1)
-device dg1 ; will compile 1 target
-device dg1,acm-g10 ; will compile 2 targets
-device dg1:acm-g10 ; will compile all targets
in range (inclusive)
-device dg1: ; will compile all targets
newer/same as provided
-device :dg1 ; will compile all targets
older/same as provided
-device xe-hpg ; will compile all targets
matching the same release
-device xe ; will compile all targets
matching the same family
-device xe-hpg:xe-hpc ; will compile all targets
in range (inclusive)
-device xe-hpg: ; will compile all targets
newer/same as provided
-device :xe-hpg ; will compile all targets
older/same as provided
known to ocloc
Deprecated notation that is still supported:
<device_type> can be: %s
- can be single or multiple target devices.
Supported -device patterns examples:
-device skl ; will compile 1 target
-device skl,icllp ; will compile 2 targets
-device skl-icllp ; will compile all targets
in range (inclusive)
-device skl- ; will compile all targets
newer/same as provided
-device -skl ; will compile all targets
older/same as provided
-device gen9 ; will compile all targets
matching the same gen
-device gen9-gen11 ; will compile all targets
in range (inclusive)
-device gen9- ; will compile all targets
newer/same as provided
-device -gen9 ; will compile all targets
older/same as provided
- can be single target device.
-output <filename> Optional output file base name.
Default is input file's base name.
@ -962,9 +948,9 @@ Examples :
Compile file to Intel Compute GPU device binary (out = source_file_Gen9core.bin)
ocloc -file source_file.cl -device skl
)===",
getDevicesConfigs().c_str(),
NEO::getDevicesFamilies().c_str(),
NEO::getDevicesTypes().c_str());
argHelper->getAllSupportedAcronyms().c_str(),
getDevicesReleasesAndFamilies().c_str(),
getDeprecatedDevicesTypes().c_str());
}
void OfflineCompiler::storeBinary(

View File

@ -29,7 +29,6 @@ class OsLibrary;
std::string convertToPascalCase(const std::string &inString);
std::string generateFilePath(const std::string &directory, const std::string &fileNameBase, const char *extension);
std::string getDevicesTypes();
class OfflineCompiler {
public:
@ -39,7 +38,8 @@ class OfflineCompiler {
MOCKABLE_VIRTUAL int build();
std::string &getBuildLog();
void printUsage();
std::string getDevicesConfigs();
std::string getDevicesReleasesAndFamilies();
std::string getDeprecatedDevicesTypes();
static constexpr ConstStringRef queryHelp =
"Depending on <query_option> will generate file\n"
@ -91,6 +91,9 @@ class OfflineCompiler {
void setFamilyType();
int initHardwareInfo(std::string deviceName);
int initHardwareInfoForProductConfig(std::string deviceName);
int initHardwareInfoForDeprecatedAcronyms(std::string deviceName, int deviceId);
std::string getStringWithinDelimiters(const std::string &src);
int initialize(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles);
int parseCommandLine(size_t numArgs, const std::vector<std::string> &allArgs);
@ -120,7 +123,7 @@ class OfflineCompiler {
void enforceFormat(std::string &format);
HardwareInfo hwInfo;
PRODUCT_CONFIG deviceConfig = UNKNOWN_ISA;
AOT::PRODUCT_CONFIG deviceConfig = AOT::UNKNOWN_ISA;
std::string deviceName;
std::string familyNameWithType;
std::string inputFile;