1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
/*
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/source/compiler_interface/compiler_options.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/helpers/string_helpers.h"
#include "shared/source/utilities/arrayref.h"
#include "shared/source/utilities/const_stringref.h"
#include "ocl_igc_interface/code_type.h"
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
class OclocArgHelper;
namespace Ocloc {
enum class SupportedDevicesMode;
};
namespace NEO {
class CompilerCache;
class CompilerProductHelper;
class OclocFclFacadeBase;
class OclocIgcFacade;
std::string convertToPascalCase(const std::string &inString);
std::string generateFilePath(const std::string &directory, const std::string &fileNameBase, const char *extension);
std::string getSupportedDevices(OclocArgHelper *helper);
struct NameVersionPair : ocloc_name_version {
NameVersionPair(ConstStringRef name, unsigned int version);
};
static_assert(sizeof(NameVersionPair) == sizeof(ocloc_name_version));
const HardwareInfo *getHwInfoForDeprecatedAcronym(const std::string &deviceName);
constexpr bool isIntermediateRepresentation(IGC::CodeType::CodeType_t codeType) {
return false == ((IGC::CodeType::oclC == codeType) || (IGC::CodeType::oclCpp == codeType) || (IGC::CodeType::oclGenBin == codeType));
}
inline std::string getFileExtension(IGC::CodeType::CodeType_t codeType) {
switch (codeType) {
default:
return "." + StringHelpers::toLower(IGC::CodeType::CodeTypeCoder::Dec(codeType));
case IGC::CodeType::oclGenBin:
case IGC::CodeType::elf:
case IGC::CodeType::undefined:
case IGC::CodeType::invalid:
return ".bin";
case IGC::CodeType::llvmBc:
return ".bc";
case IGC::CodeType::llvmLl:
return ".ll";
case IGC::CodeType::spirV:
return ".spv";
case IGC::CodeType::oclC:
return ".cl";
case IGC::CodeType::oclCpp:
return ".cl";
}
}
class OfflineCompiler : NEO::NonCopyableAndNonMovableClass {
public:
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);
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);
MOCKABLE_VIRTUAL int build();
std::string &getBuildLog();
void printUsage();
static constexpr ConstStringRef queryHelp =
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
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
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(
Depending on <acronym> will return all
matched versions (<major>.<minor>.<revision>)
that correspond to the given name.
All supported acronyms: %s.
)OCLOC_HELP";
MOCKABLE_VIRTUAL ~OfflineCompiler();
bool isQuiet() const {
return quiet;
}
bool isOnlySpirV() const {
return onlySpirV;
}
std::string parseBinAsCharArray(uint8_t *binary, size_t size, std::string &fileName);
static bool readOptionsFromFile(std::string &optionsOut, const std::string &file, OclocArgHelper *helper);
ArrayRef<const uint8_t> getPackedDeviceBinaryOutput() {
return this->elfBinary;
}
static std::string getFileNameTrunk(std::string &filePath);
const HardwareInfo &getHardwareInfo() const {
return hwInfo;
}
std::string getOptionsReadFromFile() const {
return optionsReadFromFile;
}
std::string getInternalOptionsReadFromFile() const {
return internalOptionsReadFromFile;
}
bool showHelpOnly() const { return showHelp; }
std::string getOptions() {
return options;
}
protected:
OfflineCompiler();
int initHardwareInfo(std::string deviceName);
int initHardwareInfoForProductConfig(std::string deviceName);
int initHardwareInfoForDeprecatedAcronyms(const std::string &deviceName, std::unique_ptr<NEO::CompilerProductHelper> &compilerProductHelper, std::unique_ptr<NEO::ReleaseHelper> &releaseHelper);
bool isArgumentDeviceId(const std::string &argument) const;
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);
int parseCommandLineExt(size_t numArgs, const std::vector<std::string> &allArgs, uint32_t &argIndex);
void setStatelessToStatefulBufferOffsetFlag();
void appendExtraInternalOptions(std::string &internalOptions);
void parseDebugSettings();
void storeBinary(char *&pDst, size_t &dstSize, const void *pSrc, const size_t srcSize);
MOCKABLE_VIRTUAL int buildSourceCode();
MOCKABLE_VIRTUAL std::string validateInputType(const std::string &input, bool isLlvm, bool isSpirv);
MOCKABLE_VIRTUAL int buildToIrBinary();
void updateBuildLog(const char *pErrorString, const size_t errorStringSize);
MOCKABLE_VIRTUAL bool generateElfBinary();
std::string generateFilePathForIr(const std::string &fileNameBase) {
auto ext = getFileExtension(intermediateRepresentation);
return generateFilePath(outputDirectory, fileNameBase, ext.c_str());
}
std::string generateOptsSuffix() {
std::string suffix{useOptionsSuffix ? options : ""};
std::replace(suffix.begin(), suffix.end(), ' ', '_');
return suffix;
}
MOCKABLE_VIRTUAL void writeOutAllFiles();
MOCKABLE_VIRTUAL int createDir(const std::string &path);
bool useIgcAsFcl();
void unifyExcludeIrFlags();
void enforceFormat(std::string &format);
HardwareInfo hwInfo{};
uint32_t deviceConfig = {};
std::string deviceName;
std::string productFamilyName;
std::string inputFile;
std::string outputFile;
std::string binaryOutputFile;
std::string outputDirectory;
std::string options;
std::unordered_map<std::string, std::string> perDeviceOptions;
std::string internalOptions;
std::string sourceCode;
std::string buildLog;
std::string optionsReadFromFile = "";
std::string internalOptionsReadFromFile = "";
std::string formatToEnforce = "";
std::string addressingMode = "default";
CompilerOptions::HeaplessMode heaplessMode = CompilerOptions::HeaplessMode::defaultMode;
std::string irHash, genHash, dbgHash, elfHash;
std::string cacheDir;
std::string specConstantsFile;
std::map<uint32_t, uint64_t> specConstants;
bool allowCaching = false;
bool dumpFiles = true;
bool useCppFile = false;
bool useGenFile = false;
bool useOptionsSuffix = false;
bool quiet = false;
bool onlySpirV = false;
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;
}
bool outputNoSuffix = false;
bool forceStatelessToStatefulOptimization = false;
bool showHelp = false;
bool excludeIr = false;
int loadSpecializationConstants(const std::string &filename);
std::vector<uint8_t> elfBinary;
size_t elfBinarySize = 0;
char *genBinary = nullptr;
size_t genBinarySize = 0;
char *irBinary = nullptr;
size_t irBinarySize = 0;
char *debugDataBinary = nullptr;
size_t debugDataBinarySize = 0;
struct BuildInfo;
std::unique_ptr<BuildInfo> pBuildInfo;
int revisionId = -1;
uint64_t hwInfoConfig = 0u;
std::unique_ptr<OclocIgcFacade> igcFacade;
std::unique_ptr<OclocFclFacadeBase> fclFacade;
std::unique_ptr<CompilerCache> cache;
std::unique_ptr<CompilerProductHelper> compilerProductHelper;
std::unique_ptr<ReleaseHelper> releaseHelper;
IGC::CodeType::CodeType_t preferredIntermediateRepresentation;
IGC::CodeType::CodeType_t intermediateRepresentation = IGC::CodeType::undefined;
OclocArgHelper *argHelper = nullptr;
MOCKABLE_VIRTUAL void createTempSourceFileForDebug();
};
static_assert(NEO::NonCopyableAndNonMovable<OfflineCompiler>);
} // namespace NEO
|