mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-19 06:24:51 +08:00
feature: add SUPPORTED_DEVICES query to ocloc
New query option ocloc query SUPPORTED_DEVICE allows to generate a YAML file containing information about supported devices for: - the current version of ocloc on Windows - the current and previous versions of ocloc on Linux Each version of ocloc build needs to set NEO_OCLOC_CURRENT_LIB_NAME NEO_OCLOC_FORMER_LIB_NAME cmake defines for the ocloc to be able to find a previous lib and query its supported devices. Example of correct format: NEO_OCLOC_FORMER_LIB_NAME=libocloc-1.0.so NEO_OCLOC_CURRENT_LIB_NAME=libocloc-2.0.so Related-To: NEO-9630 Signed-off-by: Fabian Zwoliński <fabian.zwolinski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
d469d551fb
commit
359f4d5b56
@@ -111,6 +111,8 @@ set(CLOC_LIB_SRCS_LIB
|
||||
${OCLOC_DIRECTORY}/source/ocloc_igc_facade.h
|
||||
${OCLOC_DIRECTORY}/source/ocloc_interface.cpp
|
||||
${OCLOC_DIRECTORY}/source/ocloc_interface.h
|
||||
${OCLOC_DIRECTORY}/source/ocloc_supported_devices_helper.cpp
|
||||
${OCLOC_DIRECTORY}/source/ocloc_supported_devices_helper.h
|
||||
${OCLOC_DIRECTORY}/source/ocloc_validator.cpp
|
||||
${OCLOC_DIRECTORY}/source/ocloc_validator.h
|
||||
${OCLOC_DIRECTORY}/source/offline_compiler.cpp
|
||||
@@ -147,6 +149,7 @@ if(WIN32)
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/windows/os_library_win.h
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/windows/sys_calls.cpp
|
||||
${NEO_SHARED_DIRECTORY}/utilities/windows/directory.cpp
|
||||
${OCLOC_DIRECTORY}/source/windows/ocloc_supported_devices_helper_windows.cpp
|
||||
)
|
||||
else()
|
||||
list(APPEND CLOC_LIB_SRCS_LIB
|
||||
@@ -160,6 +163,7 @@ else()
|
||||
${NEO_SHARED_DIRECTORY}/os_interface/linux/sys_calls_linux.cpp
|
||||
${NEO_SHARED_DIRECTORY}/utilities/linux/directory.cpp
|
||||
${OCLOC_DIRECTORY}/source/linux/os_library_ocloc_helper.cpp
|
||||
${OCLOC_DIRECTORY}/source/linux/ocloc_supported_devices_helper_linux.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -454,6 +458,9 @@ endif()
|
||||
set_target_properties(${OCLOC_NAME} PROPERTIES OUTPUT_NAME ${OCLOC_NAME}${OCLOC_OUTPUT_NAME_SUFFIX})
|
||||
set_target_properties(${OCLOC_NAME}_lib PROPERTIES OUTPUT_NAME ${OCLOC_NAME}${LIBOCLOC_OUTPUT_NAME_SUFFIX})
|
||||
|
||||
add_definitions(-DNEO_OCLOC_CURRENT_LIB_NAME="${NEO_OCLOC_CURRENT_LIB_NAME}")
|
||||
add_definitions(-DNEO_OCLOC_FORMER_LIB_NAME="${NEO_OCLOC_FORMER_LIB_NAME}")
|
||||
|
||||
add_custom_target(copy_compiler_files DEPENDS ${NEO__IGC_TARGETS})
|
||||
set_target_properties(copy_compiler_files PROPERTIES FOLDER ${OCLOC_FOLDER_NAME})
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_api.h"
|
||||
#include "shared/offline_compiler/source/ocloc_supported_devices_helper.h"
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
|
||||
namespace Ocloc {
|
||||
using namespace NEO;
|
||||
|
||||
std::string SupportedDevicesHelper::getOutputFilenameSuffix(SupportedDevicesMode mode) const {
|
||||
return "_supported_devices_" + toStr(mode) + fileExtension.data();
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocCurrentVersionOutputFilename() const {
|
||||
return getOclocCurrentVersion() + getOutputFilenameSuffix(mode);
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocCurrentLibName() const {
|
||||
#ifdef NEO_OCLOC_CURRENT_LIB_NAME
|
||||
return std::string(NEO_OCLOC_CURRENT_LIB_NAME);
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocFormerLibName() const {
|
||||
#ifdef NEO_OCLOC_FORMER_LIB_NAME
|
||||
return std::string(NEO_OCLOC_FORMER_LIB_NAME);
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocCurrentVersion() const {
|
||||
return extractOclocVersion(getOclocCurrentLibName());
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocFormerVersion() const {
|
||||
return extractOclocVersion(getOclocFormerLibName());
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::extractOclocVersion(std::string_view oclocLibNameWithVersion) const {
|
||||
// libocloc-2.0.so -> ocloc-2.0
|
||||
std::string_view view(oclocLibNameWithVersion);
|
||||
auto start = view.find("ocloc-");
|
||||
if (start == std::string_view::npos) {
|
||||
return "ocloc";
|
||||
}
|
||||
|
||||
auto end = view.find(".so", start);
|
||||
if (end == std::string_view::npos) {
|
||||
return "ocloc";
|
||||
}
|
||||
|
||||
return std::string(view.substr(start, end - start));
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getDataFromFormerOclocVersion() const {
|
||||
if (getOclocFormerLibName().empty() ||
|
||||
getOclocFormerLibName() == getOclocCurrentLibName()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::unique_ptr<OsLibrary> oclocLib(OsLibrary::load(getOclocFormerLibName()));
|
||||
|
||||
if (!oclocLib ||
|
||||
!oclocLib->isLoaded()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string retData;
|
||||
|
||||
auto oclocInvokeFunc = reinterpret_cast<pOclocInvoke>(oclocLib->getProcAddress("oclocInvoke"));
|
||||
|
||||
const char *argv[] = {"ocloc", "query", "SUPPORTED_DEVICES", "-concat"};
|
||||
|
||||
unsigned int numArgs = sizeof(argv) / sizeof(argv[0]);
|
||||
uint32_t numOutputs = 0u;
|
||||
unsigned char **dataOutputs = nullptr;
|
||||
size_t *ouputLengths = nullptr;
|
||||
char **outputNames = nullptr;
|
||||
|
||||
oclocInvokeFunc(numArgs, argv,
|
||||
0,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
0,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
&numOutputs,
|
||||
&dataOutputs,
|
||||
&ouputLengths,
|
||||
&outputNames);
|
||||
|
||||
const std::string expectedSubstr = getOutputFilenameSuffix(SupportedDevicesMode::concat);
|
||||
|
||||
for (unsigned int i = 0; i < numOutputs; ++i) {
|
||||
if (std::strstr(outputNames[i], expectedSubstr.c_str()) == nullptr) {
|
||||
continue;
|
||||
}
|
||||
retData = std::string(reinterpret_cast<char *>(dataOutputs[i]), ouputLengths[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
oclocFreeOutput(&numOutputs, &dataOutputs, &ouputLengths, &outputNames);
|
||||
return retData;
|
||||
}
|
||||
|
||||
} // namespace Ocloc
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
* Copyright (C) 2020-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -13,6 +13,12 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
typedef int (*pOclocInvoke)(
|
||||
unsigned int numArgs, const char *argv[],
|
||||
const uint32_t numSources, const uint8_t **dataSources, const uint64_t *lenSources, const char **nameSources,
|
||||
const uint32_t numInputHeaders, const uint8_t **dataInputHeaders, const uint64_t *lenInputHeaders, const char **nameInputHeaders,
|
||||
uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***nameOutputs);
|
||||
|
||||
#ifndef OCLOC_MAKE_VERSION
|
||||
/// Generates ocloc API versions
|
||||
#define OCLOC_MAKE_VERSION(_major, _minor) ((_major << 16) | (_minor & 0x0000ffff))
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_supported_devices_helper.h"
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_api.h"
|
||||
#include "shared/source/device_binary_format/yaml/yaml_parser.h"
|
||||
#include "shared/source/helpers/product_config_helper.h"
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace Ocloc {
|
||||
using namespace NEO;
|
||||
|
||||
SupportedDevicesHelper::SupportedDevicesData SupportedDevicesHelper::collectSupportedDevicesData(
|
||||
const std::vector<DeviceAotInfo> &enabledDevices) const {
|
||||
|
||||
SupportedDevicesData data;
|
||||
|
||||
// Populate IP Versions, Device Infos, Acronyms
|
||||
for (const auto &device : enabledDevices) {
|
||||
data.deviceIpVersions.push_back(device.aotConfig.value);
|
||||
|
||||
for (const auto &deviceId : *device.deviceIds) {
|
||||
data.deviceInfos.push_back({deviceId, device.aotConfig.revision, device.aotConfig.value});
|
||||
}
|
||||
|
||||
for (const auto &acronym : device.deviceAcronyms) {
|
||||
data.acronyms.push_back({acronym.data(), device.aotConfig.value});
|
||||
}
|
||||
}
|
||||
|
||||
// Populate Family groups
|
||||
std::map<AOT::FAMILY, std::vector<uint32_t>> groupedDevices;
|
||||
for (const auto &device : enabledDevices) {
|
||||
groupedDevices[device.family].push_back(device.aotConfig.value);
|
||||
}
|
||||
for (const auto &entry : groupedDevices) {
|
||||
data.familyGroups.push_back({productConfigHelper->getAcronymFromAFamily(entry.first).data(), entry.second});
|
||||
}
|
||||
|
||||
// Populate Release groups
|
||||
std::map<AOT::RELEASE, std::vector<uint32_t>> groupedReleases;
|
||||
for (const auto &device : enabledDevices) {
|
||||
groupedReleases[device.release].push_back(device.aotConfig.value);
|
||||
}
|
||||
for (const auto &entry : groupedReleases) {
|
||||
auto name = productConfigHelper->getAcronymFromARelease(entry.first);
|
||||
if (!name.empty()) {
|
||||
data.releaseGroups.push_back({name.data(), entry.second});
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::serialize(std::string_view oclocVersion, const SupportedDevicesData &data) const {
|
||||
std::ostringstream oss;
|
||||
oss << oclocVersion << ":\n";
|
||||
|
||||
// DeviceIpVersions
|
||||
oss << " " << SupportedDevicesYamlConstants::deviceIpVersions << ":\n";
|
||||
for (const auto &ipVersion : data.deviceIpVersions) {
|
||||
oss << " - 0x" << std::hex << ipVersion << "\n";
|
||||
}
|
||||
|
||||
// IpToDevRevId
|
||||
oss << " " << SupportedDevicesYamlConstants::ipToDevRevId << ":\n";
|
||||
for (const auto &device : data.deviceInfos) {
|
||||
oss << " - " << SupportedDevicesYamlConstants::ip << ": 0x" << std::hex << device.ipVersion << "\n";
|
||||
oss << " " << SupportedDevicesYamlConstants::revisionId << ": " << std::dec << device.revisionId << "\n";
|
||||
oss << " " << SupportedDevicesYamlConstants::deviceId << ": 0x" << std::hex << device.deviceId << "\n";
|
||||
}
|
||||
|
||||
// Acronym
|
||||
oss << " " << SupportedDevicesYamlConstants::acronym << ":\n";
|
||||
for (const auto &[acronym, ipVersion] : data.acronyms) {
|
||||
oss << " " << acronym << ": 0x" << std::hex << ipVersion << "\n";
|
||||
}
|
||||
|
||||
// FamilyGroups
|
||||
oss << " " << SupportedDevicesYamlConstants::familyGroups << ":\n";
|
||||
for (const auto &[family, ipVersions] : data.familyGroups) {
|
||||
oss << " " << family << ": [";
|
||||
for (size_t i = 0; i < ipVersions.size(); ++i) {
|
||||
oss << "0x" << std::hex << ipVersions[i];
|
||||
if (i < ipVersions.size() - 1)
|
||||
oss << ", ";
|
||||
}
|
||||
oss << "]\n";
|
||||
}
|
||||
|
||||
// ReleaseGroups
|
||||
oss << " " << SupportedDevicesYamlConstants::releaseGroups << ":\n";
|
||||
for (const auto &[release, ipVersions] : data.releaseGroups) {
|
||||
oss << " " << release << ": [";
|
||||
for (size_t i = 0; i < ipVersions.size(); ++i) {
|
||||
oss << "0x" << std::hex << ipVersions[i];
|
||||
if (i < ipVersions.size() - 1)
|
||||
oss << ", ";
|
||||
}
|
||||
oss << "]\n";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::map<std::string, SupportedDevicesHelper::SupportedDevicesData> SupportedDevicesHelper::deserialize(std::string_view yamlString) const {
|
||||
std::map<std::string, SupportedDevicesData> result;
|
||||
NEO::Yaml::YamlParser parser;
|
||||
std::string errReason, warning;
|
||||
|
||||
if (!parser.parse(yamlString.data(), errReason, warning)) {
|
||||
DEBUG_BREAK_IF(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
const auto *root = parser.getRoot();
|
||||
for (const auto &oclocVersionNode : parser.createChildrenRange(*root)) {
|
||||
std::string oclocVersion = parser.readKey(oclocVersionNode).str();
|
||||
SupportedDevicesData data;
|
||||
|
||||
const auto *ipVersionsNode = parser.getChild(oclocVersionNode, SupportedDevicesYamlConstants::deviceIpVersions.data());
|
||||
if (ipVersionsNode) {
|
||||
for (const auto &ipNode : parser.createChildrenRange(*ipVersionsNode)) {
|
||||
uint32_t ipVersion;
|
||||
if (parser.readValueChecked(ipNode, ipVersion)) {
|
||||
data.deviceIpVersions.push_back(ipVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto *deviceIdsNode = parser.getChild(oclocVersionNode, SupportedDevicesYamlConstants::ipToDevRevId.data());
|
||||
if (deviceIdsNode) {
|
||||
for (const auto &deviceNode : parser.createChildrenRange(*deviceIdsNode)) {
|
||||
DeviceInfo info;
|
||||
const auto *deviceIdNode = parser.getChild(deviceNode, SupportedDevicesYamlConstants::deviceId.data());
|
||||
const auto *revisionIdNode = parser.getChild(deviceNode, SupportedDevicesYamlConstants::revisionId.data());
|
||||
const auto *ipNode = parser.getChild(deviceNode, SupportedDevicesYamlConstants::ip.data());
|
||||
if (deviceIdNode && revisionIdNode && ipNode) {
|
||||
parser.readValueChecked(*deviceIdNode, info.deviceId);
|
||||
parser.readValueChecked(*revisionIdNode, info.revisionId);
|
||||
parser.readValueChecked(*ipNode, info.ipVersion);
|
||||
data.deviceInfos.push_back(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto *acronymNode = parser.getChild(oclocVersionNode, SupportedDevicesYamlConstants::acronym.data());
|
||||
if (acronymNode) {
|
||||
for (const auto &acrNode : parser.createChildrenRange(*acronymNode)) {
|
||||
std::string acronym = parser.readKey(acrNode).str();
|
||||
uint32_t ipVersion;
|
||||
if (parser.readValueChecked(acrNode, ipVersion)) {
|
||||
data.acronyms.push_back({acronym, ipVersion});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto *familyGroupsNode = parser.getChild(oclocVersionNode, SupportedDevicesYamlConstants::familyGroups.data());
|
||||
if (familyGroupsNode) {
|
||||
for (const auto &familyNode : parser.createChildrenRange(*familyGroupsNode)) {
|
||||
std::string family = parser.readKey(familyNode).str();
|
||||
std::vector<uint32_t> ipVersions;
|
||||
for (const auto &ipVersionNode : parser.createChildrenRange(familyNode)) {
|
||||
uint32_t ipVersion;
|
||||
if (parser.readValueChecked(ipVersionNode, ipVersion)) {
|
||||
ipVersions.push_back(ipVersion);
|
||||
}
|
||||
}
|
||||
if (!ipVersions.empty()) {
|
||||
data.familyGroups.push_back({family, ipVersions});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto *releaseGroupsNode = parser.getChild(oclocVersionNode, SupportedDevicesYamlConstants::releaseGroups.data());
|
||||
if (releaseGroupsNode) {
|
||||
for (const auto &releaseNode : parser.createChildrenRange(*releaseGroupsNode)) {
|
||||
std::string release = parser.readKey(releaseNode).str();
|
||||
std::vector<uint32_t> ipVersions;
|
||||
for (const auto &ipVersionNode : parser.createChildrenRange(releaseNode)) {
|
||||
uint32_t ipVersion;
|
||||
if (parser.readValueChecked(ipVersionNode, ipVersion)) {
|
||||
ipVersions.push_back(ipVersion);
|
||||
}
|
||||
}
|
||||
if (!ipVersions.empty()) {
|
||||
data.releaseGroups.push_back({release, ipVersions});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result[oclocVersion] = data;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::mergeAndSerializeWithFormerVersionData(const SupportedDevicesData ¤tVersionData) const {
|
||||
std::string formerVersionSupportedDevices = getDataFromFormerOclocVersion();
|
||||
|
||||
if (formerVersionSupportedDevices.empty()) {
|
||||
return serialize(getOclocCurrentVersion(), currentVersionData);
|
||||
}
|
||||
|
||||
auto formerVerDeserialized = deserialize(formerVersionSupportedDevices);
|
||||
formerVerDeserialized[getOclocCurrentVersion()] = currentVersionData;
|
||||
|
||||
auto mergedData = mergeOclocVersionData(formerVerDeserialized);
|
||||
return serialize("ocloc", mergedData);
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::concatAndSerializeWithFormerVersionData(const SupportedDevicesData ¤tVersionData) const {
|
||||
std::string output = serialize(getOclocCurrentVersion(), currentVersionData);
|
||||
std::string formerVersionSupportedDevices = getDataFromFormerOclocVersion();
|
||||
if (!formerVersionSupportedDevices.empty()) {
|
||||
output += "\n" + formerVersionSupportedDevices;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
SupportedDevicesHelper::SupportedDevicesData SupportedDevicesHelper::mergeOclocVersionData(const std::map<std::string, SupportedDevicesData> &versionDataMap) const {
|
||||
struct DeviceInfoComparator {
|
||||
bool operator()(const DeviceInfo &lhs, const DeviceInfo &rhs) const {
|
||||
return std::tie(lhs.deviceId, lhs.revisionId, lhs.ipVersion) <
|
||||
std::tie(rhs.deviceId, rhs.revisionId, rhs.ipVersion);
|
||||
}
|
||||
};
|
||||
|
||||
SupportedDevicesData mergedData;
|
||||
std::set<uint32_t> uniqueIpVersions;
|
||||
std::set<DeviceInfo, DeviceInfoComparator> uniqueDeviceInfos;
|
||||
std::set<std::pair<std::string, uint32_t>> uniqueAcronyms;
|
||||
std::map<std::string, std::set<uint32_t>> uniqueFamilyGroups;
|
||||
std::map<std::string, std::set<uint32_t>> uniqueReleaseGroups;
|
||||
|
||||
for (const auto &[version, data] : versionDataMap) {
|
||||
uniqueIpVersions.insert(data.deviceIpVersions.begin(), data.deviceIpVersions.end());
|
||||
for (const auto &deviceInfo : data.deviceInfos) {
|
||||
uniqueDeviceInfos.insert(deviceInfo);
|
||||
}
|
||||
uniqueAcronyms.insert(data.acronyms.begin(), data.acronyms.end());
|
||||
for (const auto &[family, ipVersions] : data.familyGroups) {
|
||||
uniqueFamilyGroups[family].insert(ipVersions.begin(), ipVersions.end());
|
||||
}
|
||||
for (const auto &[release, ipVersions] : data.releaseGroups) {
|
||||
uniqueReleaseGroups[release].insert(ipVersions.begin(), ipVersions.end());
|
||||
}
|
||||
}
|
||||
|
||||
// Sort DeviceIpVersions (ascending)
|
||||
mergedData.deviceIpVersions = std::vector<uint32_t>(uniqueIpVersions.begin(), uniqueIpVersions.end());
|
||||
std::sort(mergedData.deviceIpVersions.begin(), mergedData.deviceIpVersions.end());
|
||||
|
||||
// Sort IpToDevRevId (ascending by ipVersion)
|
||||
mergedData.deviceInfos = std::vector<DeviceInfo>(uniqueDeviceInfos.begin(), uniqueDeviceInfos.end());
|
||||
std::sort(mergedData.deviceInfos.begin(), mergedData.deviceInfos.end(),
|
||||
[](const DeviceInfo &a, const DeviceInfo &b) { return a.ipVersion < b.ipVersion; });
|
||||
|
||||
// Sort Acronyms (ascending by ipVersion)
|
||||
mergedData.acronyms = std::vector<std::pair<std::string, uint32_t>>(uniqueAcronyms.begin(), uniqueAcronyms.end());
|
||||
std::sort(mergedData.acronyms.begin(), mergedData.acronyms.end(),
|
||||
[](const auto &a, const auto &b) { return a.second < b.second; });
|
||||
|
||||
// Sort FamilyGroups (alphabetically by group name)
|
||||
for (const auto &[family, ipVersions] : uniqueFamilyGroups) {
|
||||
mergedData.familyGroups.push_back({family, std::vector<uint32_t>(ipVersions.begin(), ipVersions.end())});
|
||||
}
|
||||
std::sort(mergedData.familyGroups.begin(), mergedData.familyGroups.end(),
|
||||
[](const auto &a, const auto &b) { return a.first < b.first; });
|
||||
|
||||
// Sort ReleaseGroups (alphabetically by group name)
|
||||
for (const auto &[release, ipVersions] : uniqueReleaseGroups) {
|
||||
mergedData.releaseGroups.push_back({release, std::vector<uint32_t>(ipVersions.begin(), ipVersions.end())});
|
||||
}
|
||||
std::sort(mergedData.releaseGroups.begin(), mergedData.releaseGroups.end(),
|
||||
[](const auto &a, const auto &b) { return a.first < b.first; });
|
||||
|
||||
// Sort IP versions within each FAMILY and RELEASE group
|
||||
for (auto &[_, ipVersions] : mergedData.familyGroups) {
|
||||
std::sort(ipVersions.begin(), ipVersions.end());
|
||||
}
|
||||
for (auto &[_, ipVersions] : mergedData.releaseGroups) {
|
||||
std::sort(ipVersions.begin(), ipVersions.end());
|
||||
}
|
||||
|
||||
return mergedData;
|
||||
}
|
||||
} // namespace Ocloc
|
||||
104
shared/offline_compiler/source/ocloc_supported_devices_helper.h
Normal file
104
shared/offline_compiler/source/ocloc_supported_devices_helper.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
|
||||
#include "shared/source/helpers/product_config_helper.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Ocloc {
|
||||
|
||||
namespace SupportedDevicesYamlConstants {
|
||||
constexpr std::string_view deviceIpVersions = "device_ip_versions";
|
||||
constexpr std::string_view ipToDevRevId = "ip_to_dev_rev_id";
|
||||
constexpr std::string_view acronym = "acronym";
|
||||
constexpr std::string_view familyGroups = "family_groups";
|
||||
constexpr std::string_view releaseGroups = "release_groups";
|
||||
|
||||
// Fields in IpToDevRevId section
|
||||
constexpr std::string_view ip = "ip";
|
||||
constexpr std::string_view revisionId = "revision_id";
|
||||
constexpr std::string_view deviceId = "device_id";
|
||||
} // namespace SupportedDevicesYamlConstants
|
||||
|
||||
enum class SupportedDevicesMode {
|
||||
merge,
|
||||
concat,
|
||||
unknown
|
||||
};
|
||||
|
||||
class SupportedDevicesHelper {
|
||||
public:
|
||||
struct DeviceInfo {
|
||||
uint32_t deviceId;
|
||||
uint32_t revisionId;
|
||||
uint32_t ipVersion;
|
||||
};
|
||||
|
||||
struct SupportedDevicesData {
|
||||
std::vector<uint32_t> deviceIpVersions;
|
||||
std::vector<DeviceInfo> deviceInfos;
|
||||
std::vector<std::pair<std::string, uint32_t>> acronyms;
|
||||
std::vector<std::pair<std::string, std::vector<uint32_t>>> familyGroups;
|
||||
std::vector<std::pair<std::string, std::vector<uint32_t>>> releaseGroups;
|
||||
};
|
||||
|
||||
public:
|
||||
SupportedDevicesHelper(SupportedDevicesMode mode, ProductConfigHelper *productConfigHelper)
|
||||
: mode(mode), productConfigHelper(productConfigHelper) {}
|
||||
|
||||
std::string getOclocCurrentVersionOutputFilename() const;
|
||||
SupportedDevicesData collectSupportedDevicesData(const std::vector<DeviceAotInfo> &enabledDevices) const;
|
||||
|
||||
std::string serialize(std::string_view oclocVersion, const SupportedDevicesData &data) const;
|
||||
std::map<std::string, SupportedDevicesData> deserialize(std::string_view yamlString) const;
|
||||
|
||||
std::string mergeAndSerializeWithFormerVersionData(const SupportedDevicesData ¤tVersionData) const;
|
||||
std::string concatAndSerializeWithFormerVersionData(const SupportedDevicesData ¤tVersionData) const;
|
||||
|
||||
MOCKABLE_VIRTUAL std::string getDataFromFormerOclocVersion() const;
|
||||
|
||||
protected:
|
||||
MOCKABLE_VIRTUAL std::string getOclocCurrentLibName() const;
|
||||
MOCKABLE_VIRTUAL std::string getOclocFormerLibName() const;
|
||||
MOCKABLE_VIRTUAL std::string getOclocCurrentVersion() const;
|
||||
std::string getOclocFormerVersion() const;
|
||||
std::string extractOclocVersion(std::string_view oclocLibNameWithVersion) const;
|
||||
SupportedDevicesData mergeOclocVersionData(const std::map<std::string, SupportedDevicesData> &versionDataMap) const;
|
||||
std::string getOutputFilenameSuffix([[maybe_unused]] SupportedDevicesMode mode) const;
|
||||
|
||||
private:
|
||||
SupportedDevicesMode mode;
|
||||
ProductConfigHelper *productConfigHelper;
|
||||
static constexpr std::string_view fileExtension = ".yaml";
|
||||
};
|
||||
|
||||
inline SupportedDevicesMode parseSupportedDevicesMode(std::string_view modeStr) {
|
||||
if (modeStr == "-merge") {
|
||||
return SupportedDevicesMode::merge;
|
||||
} else if (modeStr == "-concat") {
|
||||
return SupportedDevicesMode::concat;
|
||||
} else {
|
||||
return SupportedDevicesMode::unknown;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string toStr(SupportedDevicesMode mode) {
|
||||
switch (mode) {
|
||||
case SupportedDevicesMode::concat:
|
||||
return "concat";
|
||||
case SupportedDevicesMode::merge:
|
||||
return "merge";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
} // namespace Ocloc
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "shared/offline_compiler/source/ocloc_fatbinary.h"
|
||||
#include "shared/offline_compiler/source/ocloc_fcl_facade.h"
|
||||
#include "shared/offline_compiler/source/ocloc_igc_facade.h"
|
||||
#include "shared/offline_compiler/source/ocloc_supported_devices_helper.h"
|
||||
#include "shared/offline_compiler/source/queries.h"
|
||||
#include "shared/offline_compiler/source/utilities/get_git_version_info.h"
|
||||
#include "shared/source/compiler_interface/compiler_options.h"
|
||||
@@ -273,6 +274,8 @@ int OfflineCompiler::query(size_t numArgs, const std::vector<std::string> &allAr
|
||||
return OCLOC_INVALID_COMMAND_LINE;
|
||||
}
|
||||
|
||||
Ocloc::SupportedDevicesMode supportedDevicesMode = Ocloc::SupportedDevicesMode::concat;
|
||||
|
||||
std::vector<ConstStringRef> targetProducts;
|
||||
std::vector<Queries::QueryType> queries;
|
||||
auto argIt = allArgs.begin() + 2;
|
||||
@@ -300,6 +303,15 @@ int OfflineCompiler::query(size_t numArgs, const std::vector<std::string> &allAr
|
||||
queries.push_back(Queries::QueryType::oclDeviceOpenCLCAllVersions);
|
||||
} else if (Queries::queryOCLDeviceOpenCLCFeatures == *argIt) {
|
||||
queries.push_back(Queries::QueryType::oclDeviceOpenCLCFeatures);
|
||||
} else if (Queries::querySupportedDevices == *argIt) {
|
||||
queries.push_back(Queries::QueryType::supportedDevices);
|
||||
if (argIt + 1 != allArgs.end()) {
|
||||
auto newMode = Ocloc::parseSupportedDevicesMode(*(argIt + 1));
|
||||
if (newMode != Ocloc::SupportedDevicesMode::unknown) {
|
||||
supportedDevicesMode = newMode;
|
||||
++argIt;
|
||||
}
|
||||
}
|
||||
} else if ("--help" == *argIt) {
|
||||
printQueryHelp(helper);
|
||||
return 0;
|
||||
@@ -371,6 +383,9 @@ int OfflineCompiler::query(size_t numArgs, const std::vector<std::string> &allAr
|
||||
helper->saveOutput(Queries::queryOCLDeviceOpenCLCFeatures.str(), commonFeaturesVec.data(), commonFeaturesVec.size() * sizeof(NameVersionPair));
|
||||
helper->printf("%s\n", commonFeaturesString.c_str());
|
||||
} break;
|
||||
case Queries::QueryType::supportedDevices: {
|
||||
querySupportedDevices(supportedDevicesMode, helper);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,6 +463,25 @@ int OfflineCompiler::queryAcronymIds(size_t numArgs, const std::vector<std::stri
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int OfflineCompiler::querySupportedDevices(Ocloc::SupportedDevicesMode mode, OclocArgHelper *helper) {
|
||||
auto enabledDevices = helper->productConfigHelper->getDeviceAotInfo();
|
||||
|
||||
Ocloc::SupportedDevicesHelper supportedDevicesHelper(mode, helper->productConfigHelper.get());
|
||||
auto supportedDevicesData = supportedDevicesHelper.collectSupportedDevicesData(enabledDevices);
|
||||
|
||||
std::string output;
|
||||
|
||||
if (mode == Ocloc::SupportedDevicesMode::merge) {
|
||||
output = supportedDevicesHelper.mergeAndSerializeWithFormerVersionData(supportedDevicesData);
|
||||
} else {
|
||||
output = supportedDevicesHelper.concatAndSerializeWithFormerVersionData(supportedDevicesData);
|
||||
}
|
||||
|
||||
helper->saveOutput(supportedDevicesHelper.getOclocCurrentVersionOutputFilename(), output.data(), output.size());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct OfflineCompiler::buildInfo {
|
||||
std::unique_ptr<CIF::Builtins::BufferLatest, CIF::RAII::ReleaseHelper<CIF::Builtins::BufferLatest>> fclOptions;
|
||||
std::unique_ptr<CIF::Builtins::BufferLatest, CIF::RAII::ReleaseHelper<CIF::Builtins::BufferLatest>> fclInternalOptions;
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
|
||||
class OclocArgHelper;
|
||||
|
||||
namespace Ocloc {
|
||||
enum class SupportedDevicesMode;
|
||||
};
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class CompilerCache;
|
||||
@@ -47,6 +51,7 @@ class OfflineCompiler {
|
||||
static std::vector<NameVersionPair> getOpenCLCFeatures(ConstStringRef product, OclocArgHelper *helper);
|
||||
static int query(size_t numArgs, const std::vector<std::string> &allArgs, OclocArgHelper *helper);
|
||||
static int queryAcronymIds(size_t numArgs, const std::vector<std::string> &allArgs, OclocArgHelper *helper);
|
||||
static int querySupportedDevices(Ocloc::SupportedDevicesMode mode, OclocArgHelper *helper);
|
||||
|
||||
static OfflineCompiler *create(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles, int &retVal, OclocArgHelper *helper);
|
||||
|
||||
@@ -74,6 +79,23 @@ Supported query options:
|
||||
CL_DEVICE_PROFILE ; OpenCL device profile supported by device_filter
|
||||
CL_DEVICE_OPENCL_C_ALL_VERSIONS ; OpenCL C versions supported by device_filter
|
||||
CL_DEVICE_OPENCL_C_FEATURES ; OpenCL C features supported by device_filter
|
||||
SUPPORTED_DEVICES ; Generates a YAML file with information about supported devices
|
||||
|
||||
SUPPORTED_DEVICES option:
|
||||
Linux:
|
||||
Description: Generates a YAML file containing information about supported devices
|
||||
for the current and previous versions of ocloc.
|
||||
Usage: ocloc query SUPPORTED_DEVICES [<mode>]
|
||||
Supported Modes:
|
||||
-merge - Combines supported devices from all ocloc versions into a single list (default if not specified)
|
||||
-concat - Lists supported devices for each ocloc version separately
|
||||
Output file: <ocloc_version>_supported_devices_<mode>.yaml
|
||||
|
||||
Windows:
|
||||
Description: Generates a YAML file containing information about supported devices
|
||||
for the current version of ocloc.
|
||||
Usage: ocloc query SUPPORTED_DEVICES
|
||||
Output file: <ocloc_version>_supported_devices.yaml
|
||||
|
||||
Examples:
|
||||
ocloc query OCL_DRIVER_VERSION
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2023 Intel Corporation
|
||||
* Copyright (C) 2021-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -21,7 +21,8 @@ enum class QueryType {
|
||||
oclDeviceExtensionsWithVersion,
|
||||
oclDeviceProfile,
|
||||
oclDeviceOpenCLCAllVersions,
|
||||
oclDeviceOpenCLCFeatures
|
||||
oclDeviceOpenCLCFeatures,
|
||||
supportedDevices
|
||||
};
|
||||
|
||||
inline constexpr ConstStringRef queryNeoRevision = "NEO_REVISION";
|
||||
@@ -32,5 +33,6 @@ inline constexpr ConstStringRef queryOCLDeviceExtensionsWithVersion = "CL_DEVICE
|
||||
inline constexpr ConstStringRef queryOCLDeviceProfile = "CL_DEVICE_PROFILE";
|
||||
inline constexpr ConstStringRef queryOCLDeviceOpenCLCAllVersions = "CL_DEVICE_OPENCL_C_ALL_VERSIONS";
|
||||
inline constexpr ConstStringRef queryOCLDeviceOpenCLCFeatures = "CL_DEVICE_OPENCL_C_FEATURES";
|
||||
inline constexpr ConstStringRef querySupportedDevices = "SUPPORTED_DEVICES";
|
||||
}; // namespace Queries
|
||||
} // namespace NEO
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/offline_compiler/source/ocloc_supported_devices_helper.h"
|
||||
#include "shared/source/helpers/product_config_helper.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Ocloc {
|
||||
using namespace NEO;
|
||||
|
||||
std::string SupportedDevicesHelper::getOutputFilenameSuffix(SupportedDevicesMode mode) const {
|
||||
return std::string("_supported_devices") + fileExtension.data();
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocCurrentVersionOutputFilename() const {
|
||||
return getOclocCurrentVersion() + getOutputFilenameSuffix(SupportedDevicesMode::unknown);
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocCurrentLibName() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocFormerLibName() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocCurrentVersion() const {
|
||||
return "ocloc";
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getOclocFormerVersion() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::extractOclocVersion(std::string_view oclocLibNameWithVersion) const {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string SupportedDevicesHelper::getDataFromFormerOclocVersion() const {
|
||||
return "";
|
||||
}
|
||||
} // namespace Ocloc
|
||||
Reference in New Issue
Block a user