2020-02-07 14:06:50 +01:00
|
|
|
/*
|
2022-01-11 13:03:13 +00:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-02-07 14:06:50 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2022-06-07 09:30:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-03-05 11:49:46 +01:00
|
|
|
#include "shared/offline_compiler/source/decoder/helper.h"
|
2021-08-27 20:32:03 +00:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2022-06-13 23:13:43 +00:00
|
|
|
#include "shared/source/helpers/product_config_helper.h"
|
|
|
|
|
#include "shared/source/utilities/const_stringref.h"
|
2020-03-05 11:49:46 +01:00
|
|
|
|
2022-02-22 15:00:35 +00:00
|
|
|
#include "device_ids_configs.h"
|
2021-03-15 17:01:04 +01:00
|
|
|
#include "hw_cmds.h"
|
2021-08-27 20:32:03 +00:00
|
|
|
#include "platforms.h"
|
2021-03-15 17:01:04 +01:00
|
|
|
|
2020-02-07 14:06:50 +01:00
|
|
|
#include <cctype>
|
|
|
|
|
#include <fstream>
|
2021-04-16 15:25:00 +02:00
|
|
|
#include <map>
|
2020-02-07 14:06:50 +01:00
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-03-05 11:49:46 +01:00
|
|
|
static constexpr auto *oclocStdoutLogName = "stdout.log";
|
|
|
|
|
|
2020-02-07 14:06:50 +01:00
|
|
|
struct Source {
|
|
|
|
|
const uint8_t *data;
|
2020-03-02 13:15:50 +01:00
|
|
|
const size_t length;
|
2020-02-07 14:06:50 +01:00
|
|
|
const char *name;
|
2020-03-02 13:15:50 +01:00
|
|
|
Source(const uint8_t *data, const size_t length, const char *name)
|
2020-02-07 14:06:50 +01:00
|
|
|
: data(data), length(length), name(name){};
|
|
|
|
|
void toVectorOfStrings(std::vector<std::string> &lines, bool replaceTabs = false);
|
|
|
|
|
inline std::vector<char> toBinaryVector() {
|
|
|
|
|
return std::vector<char>(data, data + length);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Output {
|
|
|
|
|
std::string name;
|
|
|
|
|
uint8_t *data;
|
|
|
|
|
const size_t size;
|
|
|
|
|
Output(const std::string &name, const void *data, const size_t &size);
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-15 17:01:04 +01:00
|
|
|
struct DeviceProduct {
|
|
|
|
|
unsigned short deviceId;
|
|
|
|
|
std::string product;
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-27 20:32:03 +00:00
|
|
|
struct DeviceMapping {
|
2022-05-12 12:35:33 +00:00
|
|
|
const NEO::HardwareInfo *hwInfo = nullptr;
|
|
|
|
|
const std::vector<unsigned short> *deviceIds = nullptr;
|
2022-06-13 23:13:43 +00:00
|
|
|
AOT::FAMILY family = AOT::UNKNOWN_FAMILY;
|
|
|
|
|
AOT::RELEASE release = AOT::UNKNOWN_RELEASE;
|
|
|
|
|
AheadOfTimeConfig aotConfig = {0};
|
|
|
|
|
std::vector<NEO::ConstStringRef> acronyms{};
|
2021-08-27 20:32:03 +00:00
|
|
|
|
|
|
|
|
bool operator==(const DeviceMapping &rhs) {
|
2022-06-13 23:13:43 +00:00
|
|
|
return aotConfig.ProductConfig == rhs.aotConfig.ProductConfig && family == rhs.family && release == rhs.release;
|
2021-08-27 20:32:03 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-07 14:06:50 +01:00
|
|
|
class OclocArgHelper {
|
|
|
|
|
protected:
|
|
|
|
|
std::vector<Source> inputs, headers;
|
|
|
|
|
std::vector<Output *> outputs;
|
|
|
|
|
uint32_t *numOutputs = nullptr;
|
|
|
|
|
char ***nameOutputs = nullptr;
|
|
|
|
|
uint8_t ***dataOutputs = nullptr;
|
|
|
|
|
uint64_t **lenOutputs = nullptr;
|
|
|
|
|
bool hasOutput = false;
|
2022-01-11 13:03:13 +00:00
|
|
|
MessagePrinter messagePrinter;
|
2021-03-31 11:28:14 +02:00
|
|
|
const std::vector<DeviceProduct> deviceProductTable;
|
2021-08-27 20:32:03 +00:00
|
|
|
std::vector<DeviceMapping> deviceMap;
|
2020-02-07 14:06:50 +01:00
|
|
|
void moveOutputs();
|
|
|
|
|
Source *findSourceFile(const std::string &filename);
|
|
|
|
|
bool sourceFileExists(const std::string &filename) const;
|
|
|
|
|
|
|
|
|
|
inline void addOutput(const std::string &filename, const void *data, const size_t &size) {
|
|
|
|
|
outputs.push_back(new Output(filename, data, size));
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 20:32:03 +00:00
|
|
|
static bool compareConfigs(DeviceMapping deviceMap0, DeviceMapping deviceMap1) {
|
2022-06-13 23:13:43 +00:00
|
|
|
return deviceMap0.aotConfig.ProductConfig < deviceMap1.aotConfig.ProductConfig;
|
2021-08-27 20:32:03 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-13 23:13:43 +00:00
|
|
|
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; };
|
2022-02-09 17:37:53 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-07 14:06:50 +01:00
|
|
|
public:
|
2021-03-31 11:28:14 +02:00
|
|
|
OclocArgHelper();
|
2020-02-07 14:06:50 +01:00
|
|
|
OclocArgHelper(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);
|
|
|
|
|
virtual ~OclocArgHelper();
|
2021-08-27 20:32:03 +00:00
|
|
|
enum CONFIG_STATUS {
|
|
|
|
|
MISMATCHED_VALUE = -1,
|
|
|
|
|
};
|
2020-02-07 14:06:50 +01:00
|
|
|
MOCKABLE_VIRTUAL bool fileExists(const std::string &filename) const;
|
2021-08-27 20:32:03 +00:00
|
|
|
int parseProductConfigFromString(const std::string &device, size_t begin, size_t end);
|
|
|
|
|
bool getHwInfoForProductConfig(uint32_t config, NEO::HardwareInfo &hwInfo);
|
2022-02-22 15:00:35 +00:00
|
|
|
std::vector<DeviceMapping> &getAllSupportedDeviceConfigs();
|
2022-06-13 23:13:43 +00:00
|
|
|
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);
|
2020-02-07 14:06:50 +01:00
|
|
|
std::vector<std::string> headersToVectorOfStrings();
|
2022-03-31 15:11:55 +00:00
|
|
|
MOCKABLE_VIRTUAL void readFileToVectorOfStrings(const std::string &filename, std::vector<std::string> &lines);
|
2020-02-07 14:06:50 +01:00
|
|
|
MOCKABLE_VIRTUAL std::vector<char> readBinaryFile(const std::string &filename);
|
2021-11-04 03:09:34 +00:00
|
|
|
MOCKABLE_VIRTUAL std::unique_ptr<char[]> loadDataFromFile(const std::string &filename, size_t &retSize);
|
2020-02-07 14:06:50 +01:00
|
|
|
|
2020-12-10 21:59:07 +01:00
|
|
|
bool outputEnabled() const {
|
|
|
|
|
return hasOutput;
|
|
|
|
|
}
|
|
|
|
|
bool hasHeaders() const {
|
|
|
|
|
return headers.size() > 0;
|
|
|
|
|
}
|
|
|
|
|
const std::vector<Source> &getHeaders() const {
|
|
|
|
|
return headers;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 15:27:20 +00:00
|
|
|
MOCKABLE_VIRTUAL void saveOutput(const std::string &filename, const void *pData, const size_t &dataSize);
|
2020-03-05 11:49:46 +01:00
|
|
|
void saveOutput(const std::string &filename, const std::ostream &stream);
|
|
|
|
|
|
|
|
|
|
MessagePrinter &getPrinterRef() { return messagePrinter; }
|
|
|
|
|
void printf(const char *message) {
|
|
|
|
|
messagePrinter.printf(message);
|
|
|
|
|
}
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
void printf(const char *format, Args... args) {
|
|
|
|
|
messagePrinter.printf(format, std::forward<Args>(args)...);
|
|
|
|
|
}
|
2021-08-27 20:32:03 +00:00
|
|
|
|
2022-06-13 23:13:43 +00:00
|
|
|
bool isRelease(const std::string &device);
|
|
|
|
|
bool isFamily(const std::string &device);
|
|
|
|
|
bool isProductConfig(const std::string &device);
|
2022-06-12 20:46:42 +02:00
|
|
|
bool areQuotesRequired(const std::string_view &argName);
|
2022-06-13 23:13:43 +00:00
|
|
|
|
|
|
|
|
std::string returnProductNameForDevice(unsigned short deviceId);
|
2020-02-07 14:06:50 +01:00
|
|
|
};
|