2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2025-02-18 22:35:36 +08:00
|
|
|
* Copyright (C) 2018-2025 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-10 06:59:57 +08:00
|
|
|
|
2023-11-17 00:48:56 +08:00
|
|
|
#include "shared/offline_compiler/source/ocloc_api.h"
|
2025-02-21 23:12:49 +08:00
|
|
|
#include "shared/source/compiler_interface/compiler_options.h"
|
2020-07-01 06:22:10 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2025-02-18 22:35:36 +08:00
|
|
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/arrayref.h"
|
|
|
|
#include "shared/source/utilities/const_stringref.h"
|
2020-02-10 06:59:57 +08:00
|
|
|
|
2022-04-22 00:06:40 +08:00
|
|
|
#include "ocl_igc_interface/code_type.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <memory>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <string>
|
2023-06-06 19:52:03 +08:00
|
|
|
#include <unordered_map>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-07-27 20:00:51 +08:00
|
|
|
class OclocArgHelper;
|
|
|
|
|
2024-07-11 00:54:24 +08:00
|
|
|
namespace Ocloc {
|
|
|
|
enum class SupportedDevicesMode;
|
|
|
|
};
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-08-29 17:13:10 +08:00
|
|
|
class CompilerCache;
|
2023-11-16 22:24:12 +08:00
|
|
|
class CompilerProductHelper;
|
2025-04-08 22:43:25 +08:00
|
|
|
class OclocFclFacadeBase;
|
2023-07-27 20:00:51 +08:00
|
|
|
class OclocIgcFacade;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
std::string convertToPascalCase(const std::string &inString);
|
|
|
|
|
2018-06-18 20:36:23 +08:00
|
|
|
std::string generateFilePath(const std::string &directory, const std::string &fileNameBase, const char *extension);
|
2022-07-05 20:24:35 +08:00
|
|
|
std::string getSupportedDevices(OclocArgHelper *helper);
|
2018-06-18 20:36:23 +08:00
|
|
|
|
2023-11-17 00:48:56 +08:00
|
|
|
struct NameVersionPair : ocloc_name_version {
|
|
|
|
NameVersionPair(ConstStringRef name, unsigned int version);
|
|
|
|
};
|
|
|
|
static_assert(sizeof(NameVersionPair) == sizeof(ocloc_name_version));
|
|
|
|
|
2024-02-13 00:41:21 +08:00
|
|
|
const HardwareInfo *getHwInfoForDeprecatedAcronym(const std::string &deviceName);
|
|
|
|
|
2025-01-24 20:14:19 +08:00
|
|
|
constexpr bool isIntermediateRepresentation(IGC::CodeType::CodeType_t codeType) {
|
|
|
|
return false == ((IGC::CodeType::oclC == codeType) || (IGC::CodeType::oclCpp == codeType) || (IGC::CodeType::oclGenBin == codeType));
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr const char *getFileExtension(IGC::CodeType::CodeType_t codeType) {
|
|
|
|
switch (codeType) {
|
|
|
|
default:
|
|
|
|
return ".bin";
|
|
|
|
case IGC::CodeType::llvmBc:
|
|
|
|
return ".bc";
|
|
|
|
case IGC::CodeType::llvmLl:
|
|
|
|
return ".ll";
|
|
|
|
case IGC::CodeType::spirV:
|
|
|
|
return ".spv";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-02-18 22:35:36 +08:00
|
|
|
class OfflineCompiler : NEO::NonCopyableAndNonMovableClass {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2023-11-17 00:48:56 +08:00
|
|
|
static std::vector<NameVersionPair> getExtensions(ConstStringRef product, bool needVersions, OclocArgHelper *helper);
|
|
|
|
static std::vector<NameVersionPair> getOpenCLCVersions(ConstStringRef product, OclocArgHelper *helper);
|
|
|
|
static std::vector<NameVersionPair> getOpenCLCFeatures(ConstStringRef product, OclocArgHelper *helper);
|
2021-03-12 01:22:38 +08:00
|
|
|
static int query(size_t numArgs, const std::vector<std::string> &allArgs, OclocArgHelper *helper);
|
2022-07-05 20:24:35 +08:00
|
|
|
static int queryAcronymIds(size_t numArgs, const std::vector<std::string> &allArgs, OclocArgHelper *helper);
|
2024-07-11 00:54:24 +08:00
|
|
|
static int querySupportedDevices(Ocloc::SupportedDevicesMode mode, OclocArgHelper *helper);
|
2021-08-05 20:50:37 +08:00
|
|
|
|
|
|
|
static OfflineCompiler *create(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles, int &retVal, OclocArgHelper *helper);
|
2022-07-05 20:24:35 +08:00
|
|
|
|
2022-03-25 20:12:31 +08:00
|
|
|
MOCKABLE_VIRTUAL int build();
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string &getBuildLog();
|
|
|
|
void printUsage();
|
|
|
|
|
2021-08-09 19:41:12 +08:00
|
|
|
static constexpr ConstStringRef queryHelp =
|
2023-11-17 00:48:56 +08:00
|
|
|
R"OCLOC_HELP(Depending on <query_option> will generate file
|
|
|
|
(with a name identical to query_option) containing requested information.
|
|
|
|
|
|
|
|
Usage: ocloc query <query_option> [-device device_filter]
|
|
|
|
|
|
|
|
-device device_filter defines optional filter for which devices the query is being made (where applicable)."
|
|
|
|
For allowed combinations of devices see "ocloc compile --help".
|
|
|
|
When filter matches multiple devices, then query will return common traits
|
|
|
|
supported by all matched devices.
|
|
|
|
|
|
|
|
Supported query options:
|
|
|
|
OCL_DRIVER_VERSION ; driver version
|
|
|
|
NEO_REVISION ; NEO revision hash
|
|
|
|
IGC_REVISION ; IGC revision hash
|
|
|
|
CL_DEVICE_EXTENSIONS ; list of extensions supported by device_filter
|
|
|
|
CL_DEVICE_EXTENSIONS_WITH_VERSION ; list of extensions and their versions supported by device_filter
|
|
|
|
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
|
2024-07-11 00:54:24 +08:00
|
|
|
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
|
2023-11-17 00:48:56 +08:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
ocloc query OCL_DRIVER_VERSION
|
|
|
|
ocloc query CL_DEVICE_EXTENSIONS -device tgllp
|
|
|
|
ocloc query CL_DEVICE_OPENCL_C_ALL_VERSIONS -device "*"
|
|
|
|
)OCLOC_HELP";
|
|
|
|
|
|
|
|
static constexpr ConstStringRef idsHelp = R"OCLOC_HELP(
|
2022-07-05 20:24:35 +08:00
|
|
|
Depending on <acronym> will return all
|
|
|
|
matched versions (<major>.<minor>.<revision>)
|
|
|
|
that correspond to the given name.
|
|
|
|
All supported acronyms: %s.
|
2023-11-17 00:48:56 +08:00
|
|
|
)OCLOC_HELP";
|
2022-07-05 20:24:35 +08:00
|
|
|
|
2020-06-01 23:51:25 +08:00
|
|
|
MOCKABLE_VIRTUAL ~OfflineCompiler();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
bool isQuiet() const {
|
|
|
|
return quiet;
|
|
|
|
}
|
|
|
|
|
2020-07-07 00:59:05 +08:00
|
|
|
bool isOnlySpirV() const {
|
|
|
|
return onlySpirV;
|
|
|
|
}
|
|
|
|
|
2018-04-18 00:11:50 +08:00
|
|
|
std::string parseBinAsCharArray(uint8_t *binary, size_t size, std::string &fileName);
|
2020-02-07 21:06:50 +08:00
|
|
|
|
2020-03-10 21:02:09 +08:00
|
|
|
static bool readOptionsFromFile(std::string &optionsOut, const std::string &file, OclocArgHelper *helper);
|
2020-02-07 21:06:50 +08:00
|
|
|
|
2020-02-10 06:59:57 +08:00
|
|
|
ArrayRef<const uint8_t> getPackedDeviceBinaryOutput() {
|
|
|
|
return this->elfBinary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getFileNameTrunk(std::string &filePath);
|
|
|
|
const HardwareInfo &getHardwareInfo() const {
|
2020-07-01 06:22:10 +08:00
|
|
|
return hwInfo;
|
2020-02-10 06:59:57 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-12-23 23:28:36 +08:00
|
|
|
std::string getOptionsReadFromFile() const {
|
|
|
|
return optionsReadFromFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getInternalOptionsReadFromFile() const {
|
|
|
|
return internalOptionsReadFromFile;
|
|
|
|
}
|
2023-03-06 17:01:46 +08:00
|
|
|
bool showHelpOnly() const { return showHelp; }
|
2021-12-23 23:28:36 +08:00
|
|
|
|
2023-07-11 20:21:32 +08:00
|
|
|
std::string getOptions() {
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
|
|
|
OfflineCompiler();
|
|
|
|
|
2021-10-26 23:25:20 +08:00
|
|
|
int initHardwareInfo(std::string deviceName);
|
2022-06-14 07:13:43 +08:00
|
|
|
int initHardwareInfoForProductConfig(std::string deviceName);
|
2024-02-13 00:41:21 +08:00
|
|
|
int initHardwareInfoForDeprecatedAcronyms(const std::string &deviceName, std::unique_ptr<NEO::CompilerProductHelper> &compilerProductHelper, std::unique_ptr<NEO::ReleaseHelper> &releaseHelper);
|
2022-11-16 22:01:51 +08:00
|
|
|
bool isArgumentDeviceId(const std::string &argument) const;
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string getStringWithinDelimiters(const std::string &src);
|
2020-02-10 06:59:57 +08:00
|
|
|
int initialize(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles);
|
2019-05-14 22:47:35 +08:00
|
|
|
int parseCommandLine(size_t numArgs, const std::vector<std::string> &allArgs);
|
2025-01-24 20:14:19 +08:00
|
|
|
int parseCommandLineExt(size_t numArgs, const std::vector<std::string> &allArgs, uint32_t &argIndex);
|
2022-07-14 09:12:22 +08:00
|
|
|
void setStatelessToStatefulBufferOffsetFlag();
|
2021-12-31 23:51:45 +08:00
|
|
|
void appendExtraInternalOptions(std::string &internalOptions);
|
2017-12-21 07:45:38 +08:00
|
|
|
void parseDebugSettings();
|
|
|
|
void storeBinary(char *&pDst, size_t &dstSize, const void *pSrc, const size_t srcSize);
|
2020-06-01 23:51:25 +08:00
|
|
|
MOCKABLE_VIRTUAL int buildSourceCode();
|
2020-11-02 23:24:48 +08:00
|
|
|
MOCKABLE_VIRTUAL std::string validateInputType(const std::string &input, bool isLlvm, bool isSpirv);
|
2025-01-24 20:14:19 +08:00
|
|
|
MOCKABLE_VIRTUAL int buildToIrBinary();
|
2017-12-21 07:45:38 +08:00
|
|
|
void updateBuildLog(const char *pErrorString, const size_t errorStringSize);
|
2020-06-01 23:51:25 +08:00
|
|
|
MOCKABLE_VIRTUAL bool generateElfBinary();
|
2018-06-18 20:36:23 +08:00
|
|
|
std::string generateFilePathForIr(const std::string &fileNameBase) {
|
2025-01-24 20:14:19 +08:00
|
|
|
const char *ext = getFileExtension(intermediateRepresentation);
|
|
|
|
return generateFilePath(outputDirectory, fileNameBase, ext);
|
2018-06-18 20:36:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string generateOptsSuffix() {
|
|
|
|
std::string suffix{useOptionsSuffix ? options : ""};
|
|
|
|
std::replace(suffix.begin(), suffix.end(), ' ', '_');
|
|
|
|
return suffix;
|
|
|
|
}
|
2022-04-12 20:53:04 +08:00
|
|
|
|
2020-06-01 23:51:25 +08:00
|
|
|
MOCKABLE_VIRTUAL void writeOutAllFiles();
|
2025-04-18 20:32:18 +08:00
|
|
|
MOCKABLE_VIRTUAL int createDir(const std::string &path);
|
2025-04-08 22:43:25 +08:00
|
|
|
bool useIgcAsFcl();
|
2021-12-17 00:15:46 +08:00
|
|
|
void unifyExcludeIrFlags();
|
2022-04-29 22:18:26 +08:00
|
|
|
void enforceFormat(std::string &format);
|
2023-07-27 20:00:51 +08:00
|
|
|
HardwareInfo hwInfo{};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-04-18 00:11:43 +08:00
|
|
|
uint32_t deviceConfig = {};
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string deviceName;
|
2023-01-03 19:46:57 +08:00
|
|
|
std::string productFamilyName;
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string inputFile;
|
|
|
|
std::string outputFile;
|
2023-05-05 23:16:46 +08:00
|
|
|
std::string binaryOutputFile;
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string outputDirectory;
|
|
|
|
std::string options;
|
2023-06-06 19:52:03 +08:00
|
|
|
std::unordered_map<std::string, std::string> perDeviceOptions;
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string internalOptions;
|
|
|
|
std::string sourceCode;
|
|
|
|
std::string buildLog;
|
2021-12-23 23:28:36 +08:00
|
|
|
std::string optionsReadFromFile = "";
|
|
|
|
std::string internalOptionsReadFromFile = "";
|
2023-09-07 21:31:57 +08:00
|
|
|
std::string formatToEnforce = "";
|
2024-06-12 02:22:10 +08:00
|
|
|
std::string addressingMode = "default";
|
2025-02-21 23:12:49 +08:00
|
|
|
CompilerOptions::HeaplessMode heaplessMode = CompilerOptions::HeaplessMode::defaultMode;
|
2022-08-29 17:13:10 +08:00
|
|
|
std::string irHash, genHash, dbgHash, elfHash;
|
|
|
|
std::string cacheDir;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-08-29 17:13:10 +08:00
|
|
|
bool allowCaching = false;
|
2021-08-06 22:44:04 +08:00
|
|
|
bool dumpFiles = true;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool useCppFile = false;
|
2022-02-16 20:01:15 +08:00
|
|
|
bool useGenFile = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool useOptionsSuffix = false;
|
|
|
|
bool quiet = false;
|
2020-07-07 00:59:05 +08:00
|
|
|
bool onlySpirV = false;
|
2025-01-24 20:14:19 +08:00
|
|
|
bool useLlvmTxt = false;
|
|
|
|
|
|
|
|
IGC::CodeType::CodeType_t inputCodeType = IGC::CodeType::oclC;
|
|
|
|
|
|
|
|
bool inputFileLlvm() const {
|
|
|
|
return (IGC::CodeType::llvmBc == inputCodeType) || (IGC::CodeType::llvmLl == inputCodeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inputFileSpirV() const {
|
|
|
|
return IGC::CodeType::spirV == inputCodeType;
|
|
|
|
}
|
|
|
|
|
2019-09-11 16:57:31 +08:00
|
|
|
bool outputNoSuffix = false;
|
2020-01-28 18:24:36 +08:00
|
|
|
bool forceStatelessToStatefulOptimization = false;
|
2021-08-06 22:44:04 +08:00
|
|
|
bool showHelp = false;
|
2021-12-08 21:40:26 +08:00
|
|
|
bool excludeIr = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-26 02:18:48 +08:00
|
|
|
std::vector<uint8_t> elfBinary;
|
2022-08-29 17:13:10 +08:00
|
|
|
size_t elfBinarySize = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
char *genBinary = nullptr;
|
|
|
|
size_t genBinarySize = 0;
|
2018-06-18 20:36:23 +08:00
|
|
|
char *irBinary = nullptr;
|
|
|
|
size_t irBinarySize = 0;
|
2018-04-18 21:48:03 +08:00
|
|
|
char *debugDataBinary = nullptr;
|
|
|
|
size_t debugDataBinarySize = 0;
|
2024-10-02 19:52:07 +08:00
|
|
|
struct BuildInfo;
|
|
|
|
std::unique_ptr<BuildInfo> pBuildInfo;
|
2020-07-29 20:40:56 +08:00
|
|
|
int revisionId = -1;
|
2022-07-04 21:24:55 +08:00
|
|
|
uint64_t hwInfoConfig = 0u;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-07-27 20:00:51 +08:00
|
|
|
std::unique_ptr<OclocIgcFacade> igcFacade;
|
2025-04-08 22:43:25 +08:00
|
|
|
std::unique_ptr<OclocFclFacadeBase> fclFacade;
|
2022-08-29 17:13:10 +08:00
|
|
|
std::unique_ptr<CompilerCache> cache;
|
2023-01-31 20:34:59 +08:00
|
|
|
std::unique_ptr<CompilerProductHelper> compilerProductHelper;
|
2023-05-09 09:56:50 +08:00
|
|
|
std::unique_ptr<ReleaseHelper> releaseHelper;
|
2018-06-18 20:36:23 +08:00
|
|
|
IGC::CodeType::CodeType_t preferredIntermediateRepresentation;
|
2025-01-24 20:14:19 +08:00
|
|
|
IGC::CodeType::CodeType_t intermediateRepresentation = IGC::CodeType::undefined;
|
2020-02-07 21:06:50 +08:00
|
|
|
|
2020-03-10 21:02:09 +08:00
|
|
|
OclocArgHelper *argHelper = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2022-04-05 00:09:41 +08:00
|
|
|
|
2025-02-18 22:35:36 +08:00
|
|
|
static_assert(NEO::NonCopyableAndNonMovable<OfflineCompiler>);
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|