/* * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/offline_compiler/source/ocloc_arg_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/os_interface/os_library.h" #include "shared/source/utilities/arrayref.h" #include "shared/source/utilities/const_stringref.h" #include "cif/common/cif_main.h" #include "ocl_igc_interface/fcl_ocl_device_ctx.h" #include "ocl_igc_interface/igc_ocl_device_ctx.h" #include #include #include namespace NEO { struct HardwareInfo; 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: enum ErrorCode { SUCCESS = 0, OUT_OF_HOST_MEMORY = -6, BUILD_PROGRAM_FAILURE = -11, INVALID_DEVICE = -33, INVALID_PROGRAM = -44, INVALID_COMMAND_LINE = -5150, INVALID_FILE = -5151, }; static int query(size_t numArgs, const std::vector &allArgs, OclocArgHelper *helper); static OfflineCompiler *create(size_t numArgs, const std::vector &allArgs, bool dumpFiles, int &retVal, OclocArgHelper *helper); int build(); std::string &getBuildLog(); void printUsage(); static constexpr ConstStringRef queryHelp = "Depending on will generate file\n" "(with a name adequate to )\n" "containing either driver version or NEO revision hash.\n\n" "Usage: ocloc query \n\n" "Supported query options:\n" " OCL_DRIVER_VERSION ; returns driver version\n" " NEO_REVISION ; returns NEO revision hash\n\n" "Examples:\n" " Extract driver version\n" " ocloc query OCL_DRIVER_VERSION\n"; OfflineCompiler &operator=(const OfflineCompiler &) = delete; OfflineCompiler(const OfflineCompiler &) = delete; 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 getPackedDeviceBinaryOutput() { return this->elfBinary; } static std::string getFileNameTrunk(std::string &filePath); const HardwareInfo &getHardwareInfo() const { return hwInfo; } protected: OfflineCompiler(); int initHardwareInfo(std::string deviceName); std::string getStringWithinDelimiters(const std::string &src); int initialize(size_t numArgs, const std::vector &allArgs, bool dumpFiles); int parseCommandLine(size_t numArgs, const std::vector &allArgs); void setStatelessToStatefullBufferOffsetFlag(); void appendExtraInternalOptions(const HardwareInfo &hwInfo, 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); int buildIrBinary(); void updateBuildLog(const char *pErrorString, const size_t errorStringSize); MOCKABLE_VIRTUAL bool generateElfBinary(); std::string generateFilePathForIr(const std::string &fileNameBase) { const char *ext = (isSpirV) ? ".spv" : ".bc"; return generateFilePath(outputDirectory, fileNameBase, useLlvmText ? ".ll" : ext); } std::string generateOptsSuffix() { std::string suffix{useOptionsSuffix ? options : ""}; std::replace(suffix.begin(), suffix.end(), ' ', '_'); return suffix; } MOCKABLE_VIRTUAL void writeOutAllFiles(); HardwareInfo hwInfo; std::string deviceName; std::string familyNameWithType; std::string inputFile; std::string outputFile; std::string outputDirectory; std::string options; std::string internalOptions; std::string sourceCode; std::string buildLog; bool dumpFiles = true; bool useLlvmText = false; bool useLlvmBc = false; bool useCppFile = false; bool useOptionsSuffix = false; bool quiet = false; bool onlySpirV = false; bool inputFileLlvm = false; bool inputFileSpirV = false; bool outputNoSuffix = false; bool forceStatelessToStatefulOptimization = false; bool isSpirV = false; bool showHelp = false; std::vector elfBinary; 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 pBuildInfo; std::unique_ptr igcLib = nullptr; CIF::RAII::UPtr_t igcMain = nullptr; CIF::RAII::UPtr_t igcDeviceCtx = nullptr; int revisionId = -1; std::unique_ptr fclLib = nullptr; CIF::RAII::UPtr_t fclMain = nullptr; CIF::RAII::UPtr_t fclDeviceCtx = nullptr; IGC::CodeType::CodeType_t preferredIntermediateRepresentation; OclocArgHelper *argHelper = nullptr; }; } // namespace NEO