refactor: ocloc - folding error codes to lib api header

These error codes are used as return codes from ocloc api.
As such, it's useful to have them defined in the ocloc api header.

Signed-off-by: Chodor, Jaroslaw <jaroslaw.chodor@intel.com>
This commit is contained in:
Chodor, Jaroslaw
2023-09-05 17:13:13 +00:00
committed by Compute-Runtime-Automation
parent 8a66ac7097
commit 49edbc3b60
28 changed files with 447 additions and 464 deletions

View File

@@ -98,7 +98,6 @@ set(CLOC_LIB_SRCS_LIB
${OCLOC_DIRECTORY}/source/ocloc_concat.h
${OCLOC_DIRECTORY}/source/ocloc_dll_options.cpp
${OCLOC_DIRECTORY}/source/ocloc_dll_options.h
${OCLOC_DIRECTORY}/source/ocloc_error_code.h
${OCLOC_DIRECTORY}/source/ocloc_fatbinary.cpp
${OCLOC_DIRECTORY}/source/ocloc_fatbinary.h
${OCLOC_DIRECTORY}/source/ocloc_fcl_facade.cpp

View File

@@ -8,8 +8,8 @@
#include "zebin_manipulator.h"
#include "shared/offline_compiler/source/decoder/iga_wrapper.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/source/device_binary_format/device_binary_formats.h"
#include "shared/source/device_binary_format/elf/elf_decoder.h"
#include "shared/source/device_binary_format/elf/elf_encoder.h"
@@ -51,21 +51,21 @@ ErrorCode parseIntelGTNotesSectionForDevice(const std::vector<Zebin::Elf::IntelG
}
if (IGFX_UNKNOWN != hwInfo.platform.eProductFamily) {
iga->setProductFamily(hwInfo.platform.eProductFamily);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
} else if (productFamilyNoteId != std::numeric_limits<size_t>::max()) {
UNRECOVERABLE_IF(sizeof(PRODUCT_FAMILY) != intelGTNotes[productFamilyNoteId].data.size());
auto productFamily = *reinterpret_cast<const PRODUCT_FAMILY *>(intelGTNotes[productFamilyNoteId].data.begin());
iga->setProductFamily(productFamily);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
} else if (gfxCoreNoteId != std::numeric_limits<size_t>::max()) {
UNRECOVERABLE_IF(sizeof(GFXCORE_FAMILY) != intelGTNotes[gfxCoreNoteId].data.size());
auto gfxCore = *reinterpret_cast<const GFXCORE_FAMILY *>(intelGTNotes[gfxCoreNoteId].data.begin());
iga->setGfxCore(gfxCore);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
return OclocErrorCode::INVALID_DEVICE;
return OCLOC_INVALID_DEVICE;
}
ErrorCode validateInput(const std::vector<std::string> &args, IgaWrapper *iga, OclocArgHelper *argHelper, Arguments &outArguments) {
@@ -81,7 +81,7 @@ ErrorCode validateInput(const std::vector<std::string> &args, IgaWrapper *iga, O
addSlash(outArguments.pathToDump);
} else if ("--help" == currArg) {
outArguments.showHelp = true;
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
} else if ("-q" == currArg) {
argHelper->getPrinterRef().setSuppressMessages(true);
iga->setMessagePrinter(argHelper->getPrinterRef());
@@ -89,13 +89,13 @@ ErrorCode validateInput(const std::vector<std::string> &args, IgaWrapper *iga, O
outArguments.skipIGAdisassembly = true;
} else {
argHelper->printf("Unknown argument %s\n", currArg.c_str());
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
}
if (outArguments.binaryFile.empty()) {
argHelper->printf("Error: Missing -file argument\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
if (outArguments.pathToDump.empty()) {
@@ -103,7 +103,7 @@ ErrorCode validateInput(const std::vector<std::string> &args, IgaWrapper *iga, O
outArguments.pathToDump = "dump/";
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
bool is64BitZebin(OclocArgHelper *argHelper, const std::string &sectionsInfoFilepath) {
@@ -170,7 +170,7 @@ ErrorCode ZebinDecoder<numBits>::decode() {
ElfT elf;
ErrorCode retVal = decodeZebin(ArrayRef<const uint8_t>::fromAny(zebinBinary.data(), zebinBinary.size()), elf);
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Error while decoding zebin.\n");
return retVal;
}
@@ -179,11 +179,11 @@ ErrorCode ZebinDecoder<numBits>::decode() {
auto intelGTNotes = getIntelGTNotes(elf);
if (intelGTNotes.empty()) {
argHelper->printf("Error missing or invalid Intel GT Notes section.\n");
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
retVal = parseIntelGTNotesSectionForDevice(intelGTNotes, iga.get(), argHelper);
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Error while parsing Intel GT Notes section for device.\n");
return retVal;
}
@@ -197,7 +197,7 @@ ErrorCode ZebinDecoder<numBits>::decode() {
auto sectionsInfo = dumpElfSections(elf);
dumpSectionInfo(sectionsInfo);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template ErrorCode ZebinDecoder<Elf::EI_CLASS_32>::validateInput(const std::vector<std::string> &args);
@@ -321,10 +321,10 @@ ErrorCode ZebinDecoder<numBits>::decodeZebin(ArrayRef<const uint8_t> zebin, ElfT
if (false == errors.empty()) {
argHelper->printf("decodeElf error: %s\n", errors.c_str());
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>
@@ -385,17 +385,17 @@ template ErrorCode ZebinEncoder<Elf::EI_CLASS_32>::encode();
template ErrorCode ZebinEncoder<Elf::EI_CLASS_64>::encode();
template <Elf::ELF_IDENTIFIER_CLASS numBits>
ErrorCode ZebinEncoder<numBits>::encode() {
ErrorCode retVal = OclocErrorCode::SUCCESS;
ErrorCode retVal = OCLOC_SUCCESS;
std::vector<SectionInfo> sectionInfos;
retVal = loadSectionsInfo(sectionInfos);
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Error while loading sections file.\n");
return retVal;
}
retVal = checkIfAllFilesExist(sectionInfos);
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Error: Missing one or more section files.\n");
return retVal;
}
@@ -403,7 +403,7 @@ ErrorCode ZebinEncoder<numBits>::encode() {
auto intelGTNotesSectionData = getIntelGTNotesSection(sectionInfos);
auto intelGTNotes = getIntelGTNotes(intelGTNotesSectionData);
retVal = parseIntelGTNotesSectionForDevice(intelGTNotes, iga.get(), argHelper);
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Error while parsing Intel GT Notes section for device.\n");
return retVal;
}
@@ -413,7 +413,7 @@ ErrorCode ZebinEncoder<numBits>::encode() {
elfEncoder.getElfFileHeader().type = Zebin::Elf::ELF_TYPE_ZEBIN::ET_ZEBIN_EXE;
retVal = appendSections(elfEncoder, sectionInfos);
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Error while appending elf sections.\n");
return retVal;
}
@@ -421,7 +421,7 @@ ErrorCode ZebinEncoder<numBits>::encode() {
auto zebin = elfEncoder.encode();
argHelper->saveOutput(getFilePath(arguments.binaryFile), zebin.data(), zebin.size());
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template ErrorCode ZebinEncoder<Elf::EI_CLASS_32>::validateInput(const std::vector<std::string> &args);
@@ -487,7 +487,7 @@ ErrorCode ZebinEncoder<numBits>::loadSectionsInfo(std::vector<SectionInfo> &sect
std::vector<std::string> sectionsInfoLines;
argHelper->readFileToVectorOfStrings(getFilePath(sectionsInfoFilename.data()), sectionsInfoLines);
if (sectionsInfoLines.size() <= 2) {
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
sectionInfos.resize(sectionsInfoLines.size() - 2);
@@ -498,7 +498,7 @@ ErrorCode ZebinEncoder<numBits>::loadSectionsInfo(std::vector<SectionInfo> &sect
sectionInfo.name = elements[0];
sectionInfo.type = static_cast<uint32_t>(std::stoull(elements[1]));
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>
@@ -511,10 +511,10 @@ ErrorCode ZebinEncoder<numBits>::checkIfAllFilesExist(const std::vector<SectionI
if (false == fileExists) {
argHelper->printf("Error: Could not find the file \"%s\"\n", sectionInfo.name.c_str());
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>
@@ -528,7 +528,7 @@ ErrorCode ZebinEncoder<numBits>::appendSections(ElfEncoderT &encoder, const std:
}
}
ErrorCode retVal = OclocErrorCode::SUCCESS;
ErrorCode retVal = OCLOC_SUCCESS;
for (const auto &section : sectionInfos) {
if (section.type == Elf::SHT_SYMTAB) {
retVal |= appendSymtab(encoder, section, sectionInfos.size() + 1, secNameToId);
@@ -551,13 +551,13 @@ ErrorCode ZebinEncoder<numBits>::appendRel(ElfEncoderT &encoder, const SectionIn
argHelper->readFileToVectorOfStrings(getFilePath(section.name), relocationLines);
if (relocationLines.empty()) {
argHelper->printf("Error: Empty relocations file: %s\n", section.name.c_str());
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
auto relocs = parseRel(relocationLines);
auto &sec = encoder.appendSection(Elf::SHT_REL, section.name, ArrayRef<const uint8_t>::fromAny(relocs.data(), relocs.size()));
sec.info = static_cast<uint32_t>(targetSecId);
sec.link = static_cast<uint32_t>(symtabSecId);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>
@@ -566,13 +566,13 @@ ErrorCode ZebinEncoder<numBits>::appendRela(ElfEncoderT &encoder, const SectionI
argHelper->readFileToVectorOfStrings(getFilePath(section.name), relocationLines);
if (relocationLines.empty()) {
argHelper->printf("Error: Empty relocations file: %s\n", section.name.c_str());
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
auto relocs = parseRela(relocationLines);
auto &sec = encoder.appendSection(Elf::SHT_RELA, section.name, ArrayRef<const uint8_t>::fromAny(relocs.data(), relocs.size()));
sec.info = static_cast<uint32_t>(targetSecId);
sec.link = static_cast<uint32_t>(symtabSecId);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>
@@ -601,7 +601,7 @@ ErrorCode ZebinEncoder<numBits>::appendKernel(ElfEncoderT &encoder, const Sectio
auto data = argHelper->readBinaryFile(getFilePath(section.name));
encoder.appendSection(Elf::SHT_PROGBITS, section.name, ArrayRef<const uint8_t>::fromAny(data.data(), data.size()));
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>
@@ -610,7 +610,7 @@ ErrorCode ZebinEncoder<numBits>::appendSymtab(ElfEncoderT &encoder, const Sectio
argHelper->readFileToVectorOfStrings(getFilePath(section.name), symTabLines);
if (symTabLines.empty()) {
argHelper->printf("Error: Empty symtab file: %s\n", section.name.c_str());
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
size_t numLocalSymbols = 0;
@@ -619,14 +619,14 @@ ErrorCode ZebinEncoder<numBits>::appendSymtab(ElfEncoderT &encoder, const Sectio
auto &symtabSection = encoder.appendSection(section.type, section.name, ArrayRef<const uint8_t>::fromAny(symbols.data(), symbols.size()));
symtabSection.info = static_cast<uint32_t>(numLocalSymbols);
symtabSection.link = static_cast<uint32_t>(strtabSecId);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>
ErrorCode ZebinEncoder<numBits>::appendOther(ElfEncoderT &encoder, const SectionInfo &section) {
auto sectionData = argHelper->readBinaryFile(getFilePath(section.name));
encoder.appendSection(section.type, section.name, ArrayRef<const uint8_t>::fromAny(sectionData.data(), sectionData.size()));
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
template <Elf::ELF_IDENTIFIER_CLASS numBits>

View File

@@ -7,8 +7,8 @@
#include "shared/offline_compiler/source/multi_command.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/ocloc_fatbinary.h"
#include "shared/offline_compiler/source/offline_compiler.h"
#include "shared/offline_compiler/source/utilities/get_current_dir.h"
@@ -19,13 +19,13 @@
namespace NEO {
int MultiCommand::singleBuild(const std::vector<std::string> &args) {
int retVal = OclocErrorCode::SUCCESS;
int retVal = OCLOC_SUCCESS;
if (requestedFatBinary(args, argHelper)) {
retVal = buildFatBinary(args, argHelper);
} else {
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(args.size(), args, true, retVal, argHelper)};
if (retVal == OclocErrorCode::SUCCESS) {
if (retVal == OCLOC_SUCCESS) {
retVal = buildWithSafetyGuard(pCompiler.get());
std::string &buildLog = pCompiler->getBuildLog();
@@ -35,14 +35,14 @@ int MultiCommand::singleBuild(const std::vector<std::string> &args) {
}
outFileName += ".bin";
}
if (retVal == OclocErrorCode::SUCCESS) {
if (retVal == OCLOC_SUCCESS) {
if (!quiet)
argHelper->printf("Build succeeded.\n");
} else {
argHelper->printf("Build failed with error code: %d\n", retVal);
}
if (retVal == OclocErrorCode::SUCCESS) {
if (retVal == OCLOC_SUCCESS) {
outputFile << getCurrentDirectoryOwn(outDirForBuilds) + outFileName;
} else {
outputFile << "Unsuccesful build";
@@ -53,7 +53,7 @@ int MultiCommand::singleBuild(const std::vector<std::string> &args) {
}
MultiCommand *MultiCommand::create(const std::vector<std::string> &args, int &retVal, OclocArgHelper *helper) {
retVal = OclocErrorCode::SUCCESS;
retVal = OCLOC_SUCCESS;
auto pMultiCommand = new MultiCommand();
if (pMultiCommand) {
@@ -61,7 +61,7 @@ MultiCommand *MultiCommand::create(const std::vector<std::string> &args, int &re
retVal = pMultiCommand->initialize(args);
}
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
delete pMultiCommand;
pMultiCommand = nullptr;
}
@@ -112,7 +112,7 @@ int MultiCommand::initialize(const std::vector<std::string> &args) {
} else {
argHelper->printf("Invalid option (arg %zu): %s\n", argIndex, currArg.c_str());
printHelp();
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
}
@@ -121,11 +121,11 @@ int MultiCommand::initialize(const std::vector<std::string> &args) {
argHelper->readFileToVectorOfStrings(pathToCommandFile, lines);
if (lines.empty()) {
argHelper->printf("Command file was empty.\n");
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
} else {
argHelper->printf("Could not find/open file with builds argument.s\n");
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
runBuilds(args[0]);
@@ -141,7 +141,7 @@ void MultiCommand::runBuilds(const std::string &argZero) {
std::vector<std::string> args = {argZero};
int retVal = splitLineInSeparateArgs(args, lines[i], i);
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
retValues.push_back(retVal);
continue;
}
@@ -193,22 +193,22 @@ int MultiCommand::splitLineInSeparateArgs(std::vector<std::string> &qargs, const
}
if (end == std::string::npos) {
argHelper->printf("One of the quotes is open in build number %zu\n", numberOfBuild + 1);
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
argLen = end - start;
i = end;
qargs.push_back(commandsLine.substr(start, argLen));
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
int MultiCommand::showResults() {
int retValue = OclocErrorCode::SUCCESS;
int retValue = OCLOC_SUCCESS;
int indexRetVal = 0;
for (int retVal : retValues) {
retValue |= retVal;
if (!quiet) {
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Build command %d: failed. Error code: %d\n", indexRetVal, retVal);
} else {
argHelper->printf("Build command %d: successful\n", indexRetVal);

View File

@@ -7,8 +7,8 @@
#include "ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/ocloc_interface.h"
#include <iostream>
@@ -29,7 +29,7 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
try {
if (numArgs <= 1 || NEO::ConstStringRef("-h") == args[1] || NEO::ConstStringRef("--help") == args[1]) {
printHelp(*helper);
return NEO::OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
auto &command = args[1];
if (command == CommandNames::disassemble) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -24,6 +24,17 @@ typedef enum _ocloc_version_t {
OCLOC_VERSION_FORCE_UINT32 = 0x7fffffff
} ocloc_version_t;
typedef enum _ocloc_error_t {
OCLOC_SUCCESS = 0,
OCLOC_OUT_OF_HOST_MEMORY = -6,
OCLOC_BUILD_PROGRAM_FAILURE = -11,
OCLOC_INVALID_DEVICE = -33,
OCLOC_INVALID_PROGRAM = -44,
OCLOC_INVALID_COMMAND_LINE = -5150,
OCLOC_INVALID_FILE = -5151,
OCLOC_COMPILATION_CRASH = -5152,
} ocloc_error_t;
#ifdef _WIN32
#define SIGNATURE __declspec(dllexport) int __cdecl
#else

View File

@@ -7,8 +7,8 @@
#include "shared/offline_compiler/source/ocloc_concat.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/source/device_binary_format/ar/ar_decoder.h"
#include "shared/source/device_binary_format/ar/ar_encoder.h"
#include "shared/source/device_binary_format/elf/elf_decoder.h"
@@ -34,7 +34,7 @@ OclocConcat::ErrorCode OclocConcat::parseArguments(const std::vector<std::string
if (NEO::ConstStringRef("-out") == args[i]) {
if (i + 1 >= args.size()) {
argHelper->printf("Missing out file name after \"-out\" argument\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
fatBinaryName = args[++i];
} else {
@@ -44,10 +44,10 @@ OclocConcat::ErrorCode OclocConcat::parseArguments(const std::vector<std::string
if (fileNamesToConcat.empty()) {
argHelper->printf("No files to concatenate were provided.\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
OclocConcat::ErrorCode OclocConcat::checkIfFatBinariesExist() {
@@ -59,7 +59,7 @@ OclocConcat::ErrorCode OclocConcat::checkIfFatBinariesExist() {
argHelper->printf(errorMsg.c_str());
}
}
return filesExist ? OclocErrorCode::SUCCESS : OclocErrorCode::INVALID_COMMAND_LINE;
return filesExist ? OCLOC_SUCCESS : OCLOC_INVALID_COMMAND_LINE;
}
void OclocConcat::printMsg(ConstStringRef fileName, const std::string &message) {
@@ -113,7 +113,7 @@ OclocConcat::ErrorCode OclocConcat::concatenate() {
if (false == errors.empty()) {
printMsg(fileName, errors);
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
printMsg(fileName, warnings);
@@ -128,7 +128,7 @@ OclocConcat::ErrorCode OclocConcat::concatenate() {
auto productConfig = getAOTProductConfigFromBinary(fileRef, errors);
if (false == errors.empty()) {
printMsg(fileName, errors);
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
auto entryName = ProductConfigHelper::parseMajorMinorRevisionValue(productConfig);
arEncoder.appendFileEntry(entryName, fileRef);
@@ -137,7 +137,7 @@ OclocConcat::ErrorCode OclocConcat::concatenate() {
auto arFile = arEncoder.encode();
argHelper->saveOutput(fatBinaryName, arFile.data(), arFile.size());
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
void OclocConcat::printHelp() {

View File

@@ -1,23 +0,0 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
namespace NEO::OclocErrorCode {
enum {
SUCCESS = 0,
OUT_OF_HOST_MEMORY = -6,
BUILD_PROGRAM_FAILURE = -11,
INVALID_DEVICE = -33,
INVALID_PROGRAM = -44,
INVALID_COMMAND_LINE = -5150,
INVALID_FILE = -5151,
COMPILATION_CRASH = -5152,
};
} // namespace NEO::OclocErrorCode

View File

@@ -7,8 +7,8 @@
#include "shared/offline_compiler/source/ocloc_fatbinary.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/offline_compiler.h"
#include "shared/offline_compiler/source/utilities/safety_caller.h"
#include "shared/source/compiler_interface/compiler_options.h"
@@ -343,7 +343,7 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
if (deviceArgIndex == static_cast<size_t>(-1)) {
argHelper->printf("Error! Command does not contain device argument!\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
Ar::ArEncoder fatbinary(true);
@@ -365,7 +365,7 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
argsCopy[deviceArgIndex] = product.str();
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(argsCopy.size(), argsCopy, false, retVal, argHelper)};
if (OclocErrorCode::SUCCESS != retVal) {
if (OCLOC_SUCCESS != retVal) {
argHelper->printf("Error! Couldn't create OfflineCompiler. Exiting.\n");
return retVal;
}
@@ -381,7 +381,7 @@ int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelp
if (shouldPreserveGenericIr) {
const auto errorCode = appendGenericIr(fatbinary, inputFileName, argHelper, optionsForIr);
if (errorCode != OclocErrorCode::SUCCESS) {
if (errorCode != OCLOC_SUCCESS) {
argHelper->printf("Error! Couldn't append generic IR file!\n");
return errorCode;
}
@@ -405,7 +405,7 @@ int appendGenericIr(Ar::ArEncoder &fatbinary, const std::string &inputFile, Oclo
std::unique_ptr<char[]> fileContents = argHelper->loadDataFromFile(inputFile, fileSize);
if (fileSize == 0) {
argHelper->printf("Error! Couldn't read input file!\n");
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
const auto ir = ArrayRef<const uint8_t>::fromAny(fileContents.get(), fileSize);
@@ -413,14 +413,14 @@ int appendGenericIr(Ar::ArEncoder &fatbinary, const std::string &inputFile, Oclo
if (!isSpirVBitcode(ir)) {
argHelper->printf("Error! Input file is not in supported generic IR format! "
"Currently supported format is SPIR-V.\n");
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
const auto encodedElf = createEncodedElfWithSpirv(ir, opt);
ArrayRef<const uint8_t> genericIrFile{encodedElf.data(), encodedElf.size()};
fatbinary.appendFileEntry("generic_ir", genericIrFile);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
std::vector<uint8_t> createEncodedElfWithSpirv(const ArrayRef<const uint8_t> &spirv, const ArrayRef<const uint8_t> &options) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Intel Corporation
* Copyright (C) 2022-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,8 +7,8 @@
#include "shared/offline_compiler/source/ocloc_fcl_facade.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/source/compiler_interface/igc_platform_helper.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/hw_info.h"
@@ -32,19 +32,19 @@ int OclocFclFacade::initialize(const HardwareInfo &hwInfo) {
fclLib = loadFclLibrary();
if (!fclLib) {
argHelper->printf("Error! Loading of FCL library has failed! Filename: %s\n", Os::frontEndDllName);
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
const auto fclCreateMainFunction = loadCreateFclMainFunction();
if (!fclCreateMainFunction) {
argHelper->printf("Error! Cannot load required functions from FCL library.\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
fclMain = createFclMain(fclCreateMainFunction);
if (!fclMain) {
argHelper->printf("Error! Cannot create FCL main component!\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
if (!isFclInterfaceCompatible()) {
@@ -52,13 +52,13 @@ int OclocFclFacade::initialize(const HardwareInfo &hwInfo) {
argHelper->printf("Error! Incompatible interface in FCL: %s\n", incompatibleInterface.c_str());
DEBUG_BREAK_IF(true);
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
fclDeviceCtx = createFclDeviceContext();
if (!fclDeviceCtx) {
argHelper->printf("Error! Cannot create FCL device context!\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
fclDeviceCtx->SetOclApiVersion(hwInfo.capabilityTable.clVersionSupport * 10);
@@ -67,14 +67,14 @@ int OclocFclFacade::initialize(const HardwareInfo &hwInfo) {
const auto platform = getPlatformHandle();
if (!platform) {
argHelper->printf("Error! FCL device context has not been properly created!\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
populateFclInterface(*platform, hwInfo);
}
initialized = true;
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
std::unique_ptr<OsLibrary> OclocFclFacade::loadFclLibrary() const {

View File

@@ -7,8 +7,8 @@
#include "shared/offline_compiler/source/ocloc_igc_facade.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/source/compiler_interface/igc_platform_helper.h"
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
#include "shared/source/helpers/compiler_product_helper.h"
@@ -36,7 +36,7 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
igcLib = loadIgcLibrary();
if (!igcLib) {
argHelper->printf("Error! Loading of IGC library has failed! Filename: %s\n", Os::igcDllName);
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
std::string igcPath = igcLib->getFullPath();
@@ -46,13 +46,13 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
const auto igcCreateMainFunction = loadCreateIgcMainFunction();
if (!igcCreateMainFunction) {
argHelper->printf("Error! Cannot load required functions from IGC library.\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
igcMain = createIgcMain(igcCreateMainFunction);
if (!igcMain) {
argHelper->printf("Error! Cannot create IGC main component!\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
const std::vector<CIF::InterfaceId_t> interfacesToIgnore = {IGC::OclGenBinaryBase::GetInterfaceId()};
@@ -61,12 +61,12 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
argHelper->printf("Error! Incompatible interface in IGC: %s\n", incompatibleInterface.c_str());
DEBUG_BREAK_IF(true);
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
if (!isPatchtokenInterfaceSupported()) {
argHelper->printf("Error! Patchtoken interface is missing.\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
{
@@ -83,7 +83,7 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
igcDeviceCtx = createIgcDeviceContext();
if (!igcDeviceCtx) {
argHelper->printf("Error! Cannot create IGC device context!\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
igcDeviceCtx->SetProfilingTimerResolution(static_cast<float>(hwInfo.capabilityTable.defaultProfilingTimerResolution));
@@ -94,7 +94,7 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
if (!igcPlatform || !igcGtSystemInfo || !igcFtrWa) {
argHelper->printf("Error! IGC device context has not been properly created!\n");
return OclocErrorCode::OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
auto compilerProductHelper = NEO::CompilerProductHelper::create(hwInfo.platform.eProductFamily);
@@ -109,7 +109,7 @@ int OclocIgcFacade::initialize(const HardwareInfo &hwInfo) {
populateWithFeatures(igcFtrWa.get(), copyHwInfo, compilerProductHelper.get());
initialized = true;
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
std::unique_ptr<OsLibrary> OclocIgcFacade::loadIgcLibrary() const {

View File

@@ -11,8 +11,8 @@
#include "shared/offline_compiler/source/decoder/binary_encoder.h"
#include "shared/offline_compiler/source/decoder/zebin_manipulator.h"
#include "shared/offline_compiler/source/multi_command.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_concat.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/ocloc_fatbinary.h"
#include "shared/offline_compiler/source/ocloc_validator.h"
#include "shared/offline_compiler/source/offline_compiler.h"
@@ -123,10 +123,10 @@ int compile(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
return NEO::buildFatBinary(args, argHelper);
}
int retVal = OclocErrorCode::SUCCESS;
int retVal = OCLOC_SUCCESS;
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(args.size(), args, true, retVal, argHelper)};
if (retVal == OclocErrorCode::SUCCESS) {
if (retVal == OCLOC_SUCCESS) {
if (pCompiler->showHelpOnly()) {
return retVal;
}
@@ -137,7 +137,7 @@ int compile(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
argHelper->printf("%s\n", buildLog.c_str());
}
if (retVal == OclocErrorCode::SUCCESS) {
if (retVal == OCLOC_SUCCESS) {
if (!pCompiler->isQuiet())
argHelper->printf("Build succeeded.\n");
} else {
@@ -145,7 +145,7 @@ int compile(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
}
}
if (retVal != OclocErrorCode::SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
printOclocOptionsReadFromFile(*argHelper, pCompiler.get());
printOclocCmdLine(*argHelper, args);
}
@@ -153,7 +153,7 @@ int compile(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
};
int link(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
int createResult{OclocErrorCode::SUCCESS};
int createResult{OCLOC_SUCCESS};
const auto linker{OfflineLinker::create(args.size(), args, createResult, argHelper)};
const auto linkingResult{linkWithSafetyGuard(linker.get())};
@@ -162,7 +162,7 @@ int link(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
argHelper->printf("%s\n", buildLog.c_str());
}
if (createResult == OclocErrorCode::SUCCESS && linkingResult == OclocErrorCode::SUCCESS) {
if (createResult == OCLOC_SUCCESS && linkingResult == OCLOC_SUCCESS) {
argHelper->printf("Linker execution has succeeded!\n");
}
@@ -175,9 +175,9 @@ int disassemble(OclocArgHelper *argHelper, const std::vector<std::string> &args)
int retVal = decoder.validateInput(args);
if (decoder.showHelp) {
decoder.printHelp();
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
return (retVal == OclocErrorCode::SUCCESS) ? decoder.decode() : retVal;
return (retVal == OCLOC_SUCCESS) ? decoder.decode() : retVal;
};
if (binaryFormat == Zebin::Manipulator::BinaryFormats::PatchTokens) {
@@ -199,9 +199,9 @@ int assemble(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
int retVal = encoder.validateInput(args);
if (encoder.showHelp) {
encoder.printHelp();
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
return (retVal == OclocErrorCode::SUCCESS) ? encoder.encode() : retVal;
return (retVal == OCLOC_SUCCESS) ? encoder.encode() : retVal;
};
if (binaryFormat == Zebin::Manipulator::BinaryFormats::PatchTokens) {
BinaryEncoder assembler(argHelper);
@@ -216,7 +216,7 @@ int assemble(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
}
int multi(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
int retValue = OclocErrorCode::SUCCESS;
int retValue = OCLOC_SUCCESS;
std::unique_ptr<MultiCommand> pMulti{(MultiCommand::create(args, retValue, argHelper))};
return retValue;
}
@@ -236,7 +236,7 @@ int ids(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
int concat(OclocArgHelper *argHelper, const std::vector<std::string> &args) {
auto arConcat = NEO::OclocConcat(argHelper);
auto error = arConcat.initialize(args);
if (OclocErrorCode::SUCCESS != error) {
if (OCLOC_SUCCESS != error) {
arConcat.printHelp();
return error;
}

View File

@@ -7,8 +7,8 @@
#include "offline_compiler.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/ocloc_fcl_facade.h"
#include "shared/offline_compiler/source/ocloc_igc_facade.h"
#include "shared/offline_compiler/source/queries.h"
@@ -45,8 +45,6 @@
#define GetCurrentWorkingDirectory getcwd
#endif
using namespace NEO::OclocErrorCode;
namespace NEO {
std::string convertToPascalCase(const std::string &inString) {
@@ -89,7 +87,7 @@ OfflineCompiler::~OfflineCompiler() {
}
OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles, int &retVal, OclocArgHelper *helper) {
retVal = SUCCESS;
retVal = OCLOC_SUCCESS;
auto pOffCompiler = new OfflineCompiler();
if (pOffCompiler) {
@@ -99,7 +97,7 @@ OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::
retVal = pOffCompiler->initialize(numArgs, allArgs, dumpFiles);
}
if (retVal != SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
delete pOffCompiler;
pOffCompiler = nullptr;
}
@@ -114,10 +112,10 @@ void printQueryHelp(OclocArgHelper *helper) {
int OfflineCompiler::query(size_t numArgs, const std::vector<std::string> &allArgs, OclocArgHelper *helper) {
if (allArgs.size() != 3) {
helper->printf("Error: Invalid command line. Expected ocloc query <argument>");
return INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
auto retVal = SUCCESS;
auto retVal = OCLOC_SUCCESS;
auto &arg = allArgs[2];
if (Queries::queryNeoRevision == arg) {
@@ -130,7 +128,7 @@ int OfflineCompiler::query(size_t numArgs, const std::vector<std::string> &allAr
printQueryHelp(helper);
} else {
helper->printf("Error: Invalid command line. Unknown argument %s.", arg.c_str());
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
}
return retVal;
@@ -142,11 +140,11 @@ void printAcronymIdsHelp(OclocArgHelper *helper) {
int OfflineCompiler::queryAcronymIds(size_t numArgs, const std::vector<std::string> &allArgs, OclocArgHelper *helper) {
const size_t numArgRequested = 3u;
auto retVal = SUCCESS;
auto retVal = OCLOC_SUCCESS;
if (numArgs != numArgRequested) {
helper->printf("Error: Invalid command line. Expected ocloc ids <acronym>.\n");
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
return retVal;
} else if ((ConstStringRef("-h") == allArgs[2] || ConstStringRef("--help") == allArgs[2])) {
printAcronymIdsHelp(helper);
@@ -183,7 +181,7 @@ int OfflineCompiler::queryAcronymIds(size_t numArgs, const std::vector<std::stri
}
} else {
helper->printf("Error: Invalid command line. Unknown acronym %s.\n", allArgs[2].c_str());
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
return retVal;
}
@@ -206,7 +204,7 @@ struct OfflineCompiler::buildInfo {
};
int OfflineCompiler::buildIrBinary() {
int retVal = SUCCESS;
int retVal = OCLOC_SUCCESS;
if (allowCaching) {
const std::string igcRevision = igcFacade->getIgcRevision();
@@ -258,13 +256,13 @@ int OfflineCompiler::buildIrBinary() {
if (true == NEO::areNotNullptr(err->GetMemory<char>())) {
updateBuildLog(err->GetMemory<char>(), err->GetSizeRaw());
retVal = BUILD_PROGRAM_FAILURE;
retVal = OCLOC_BUILD_PROGRAM_FAILURE;
return retVal;
}
if (false == NEO::areNotNullptr(fclSrc.get(), pBuildInfo->fclOptions.get(), pBuildInfo->fclInternalOptions.get(),
fclTranslationCtx.get())) {
retVal = OUT_OF_HOST_MEMORY;
retVal = OCLOC_OUT_OF_HOST_MEMORY;
return retVal;
}
@@ -272,7 +270,7 @@ int OfflineCompiler::buildIrBinary() {
pBuildInfo->fclInternalOptions.get(), nullptr, 0);
if (pBuildInfo->fclOutput == nullptr) {
retVal = OUT_OF_HOST_MEMORY;
retVal = OCLOC_OUT_OF_HOST_MEMORY;
return retVal;
}
@@ -281,7 +279,7 @@ int OfflineCompiler::buildIrBinary() {
if (pBuildInfo->fclOutput->Successful() == false) {
updateBuildLog(pBuildInfo->fclOutput->GetBuildLog()->GetMemory<char>(), pBuildInfo->fclOutput->GetBuildLog()->GetSizeRaw());
retVal = BUILD_PROGRAM_FAILURE;
retVal = OCLOC_BUILD_PROGRAM_FAILURE;
return retVal;
}
@@ -325,10 +323,10 @@ std::string OfflineCompiler::validateInputType(const std::string &input, bool is
}
int OfflineCompiler::buildSourceCode() {
int retVal = SUCCESS;
int retVal = OCLOC_SUCCESS;
if (sourceCode.empty()) {
return INVALID_PROGRAM;
return OCLOC_INVALID_PROGRAM;
}
const std::string igcRevision = igcFacade->getIgcRevision();
@@ -378,7 +376,7 @@ int OfflineCompiler::buildSourceCode() {
bool inputIsIntermediateRepresentation = inputFileLlvm || inputFileSpirV;
if (false == inputIsIntermediateRepresentation) {
retVal = buildIrBinary();
if (retVal != SUCCESS)
if (retVal != OCLOC_SUCCESS)
return retVal;
auto igcTranslationCtx = igcFacade->createTranslationContext(pBuildInfo->intermediateRepresentation, IGC::CodeType::oclGenBin);
@@ -396,7 +394,7 @@ int OfflineCompiler::buildSourceCode() {
igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);
}
if (igcOutput == nullptr) {
return OUT_OF_HOST_MEMORY;
return OCLOC_OUT_OF_HOST_MEMORY;
}
UNRECOVERABLE_IF(igcOutput->GetBuildLog() == nullptr);
UNRECOVERABLE_IF(igcOutput->GetOutput() == nullptr);
@@ -415,13 +413,13 @@ int OfflineCompiler::buildSourceCode() {
cache->cacheBinary(dbgHash, debugDataBinary, static_cast<uint32_t>(debugDataBinarySize));
}
retVal = igcOutput->Successful() ? SUCCESS : BUILD_PROGRAM_FAILURE;
retVal = igcOutput->Successful() ? OCLOC_SUCCESS : OCLOC_BUILD_PROGRAM_FAILURE;
return retVal;
}
int OfflineCompiler::build() {
int retVal = SUCCESS;
int retVal = OCLOC_SUCCESS;
if (isOnlySpirV()) {
retVal = buildIrBinary();
} else {
@@ -477,10 +475,10 @@ int OfflineCompiler::initHardwareInfoForDeprecatedAcronyms(std::string deviceNam
productFamilyName = hardwarePrefix[hwInfo.platform.eProductFamily];
releaseHelper = NEO::ReleaseHelper::create(hwInfo.ipVersion);
return SUCCESS;
return OCLOC_SUCCESS;
}
}
return INVALID_DEVICE;
return OCLOC_INVALID_DEVICE;
}
bool OfflineCompiler::isArgumentDeviceId(const std::string &argument) const {
@@ -496,37 +494,37 @@ int OfflineCompiler::initHardwareInfoForProductConfig(std::string deviceName) {
auto deviceID = static_cast<unsigned short>(std::stoi(deviceName, 0, 16));
productConfig = argHelper->getProductConfigAndSetHwInfoBasedOnDeviceAndRevId(hwInfo, deviceID, revisionId, compilerProductHelper, releaseHelper);
if (productConfig == AOT::UNKNOWN_ISA) {
return INVALID_DEVICE;
return OCLOC_INVALID_DEVICE;
}
auto product = argHelper->productConfigHelper->getAcronymForProductConfig(productConfig);
argHelper->printf("Auto-detected target based on %s device id: %s\n", deviceName.c_str(), product.c_str());
} else if (revisionId == -1) {
productConfig = argHelper->productConfigHelper->getProductConfigFromDeviceName(deviceName);
if (!argHelper->setHwInfoForProductConfig(productConfig, hwInfo, compilerProductHelper, releaseHelper)) {
return INVALID_DEVICE;
return OCLOC_INVALID_DEVICE;
}
} else {
return INVALID_DEVICE;
return OCLOC_INVALID_DEVICE;
}
argHelper->setHwInfoForHwInfoConfig(hwInfo, hwInfoConfig, compilerProductHelper, releaseHelper);
deviceConfig = hwInfo.ipVersion.value;
productFamilyName = hardwarePrefix[hwInfo.platform.eProductFamily];
return SUCCESS;
return OCLOC_SUCCESS;
}
int OfflineCompiler::initHardwareInfo(std::string deviceName) {
int retVal = INVALID_DEVICE;
int retVal = OCLOC_INVALID_DEVICE;
if (deviceName.empty()) {
return retVal;
}
retVal = initHardwareInfoForProductConfig(deviceName);
if (retVal == SUCCESS) {
if (retVal == OCLOC_SUCCESS) {
return retVal;
}
retVal = initHardwareInfoForDeprecatedAcronyms(deviceName, compilerProductHelper, releaseHelper);
if (retVal != SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Could not determine device target: %s.\n", deviceName.c_str());
}
return retVal;
@@ -550,7 +548,7 @@ std::string OfflineCompiler::getStringWithinDelimiters(const std::string &src) {
int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles) {
this->dumpFiles = dumpFiles;
int retVal = SUCCESS;
int retVal = OCLOC_SUCCESS;
const char *source = nullptr;
std::unique_ptr<char[]> sourceFromFile;
size_t sourceFromFileSize = 0;
@@ -561,7 +559,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
if (showHelp) {
printUsage();
return retVal;
} else if (retVal != SUCCESS) {
} else if (retVal != OCLOC_SUCCESS) {
return retVal;
}
@@ -583,7 +581,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
std::istream_iterator<std::string>{iss}, std::istream_iterator<std::string>{}};
retVal = parseCommandLine(tokens.size(), tokens);
if (retVal != SUCCESS) {
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Failed with ocloc options from file:\n%s\n", oclocOptionsFromFile.c_str());
return retVal;
}
@@ -615,8 +613,8 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
}
}
retVal = deviceName.empty() ? SUCCESS : initHardwareInfo(deviceName.c_str());
if (retVal != SUCCESS) {
retVal = deviceName.empty() ? OCLOC_SUCCESS : initHardwareInfo(deviceName.c_str());
if (retVal != OCLOC_SUCCESS) {
argHelper->printf("Error: Cannot get HW Info for device %s.\n", deviceName.c_str());
return retVal;
}
@@ -649,7 +647,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
// set up the device inside the program
sourceFromFile = argHelper->loadDataFromFile(inputFile, sourceFromFileSize);
if (sourceFromFileSize == 0) {
retVal = INVALID_FILE;
retVal = OCLOC_INVALID_FILE;
return retVal;
}
@@ -664,7 +662,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
if ((inputFileSpirV == false) && (inputFileLlvm == false)) {
const auto fclInitializationResult = fclFacade->initialize(hwInfo);
if (fclInitializationResult != SUCCESS) {
if (fclInitializationResult != OCLOC_SUCCESS) {
argHelper->printf("Error! FCL initialization failure. Error code = %d\n", fclInitializationResult);
return fclInitializationResult;
}
@@ -678,7 +676,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
}
const auto igcInitializationResult = igcFacade->initialize(hwInfo);
if (igcInitializationResult != SUCCESS) {
if (igcInitializationResult != OCLOC_SUCCESS) {
argHelper->printf("Error! IGC initialization failure. Error code = %d\n", igcInitializationResult);
return igcInitializationResult;
}
@@ -692,7 +690,7 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
}
int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::string> &argv) {
int retVal = SUCCESS;
int retVal = OCLOC_SUCCESS;
bool compile32 = false;
bool compile64 = false;
std::set<std::string> deviceAcronymsFromDeviceOptions;
@@ -770,7 +768,7 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
outputNoSuffix = true;
} else if ("--help" == currArg) {
showHelp = true;
return SUCCESS;
return OCLOC_SUCCESS;
} else if (("-revision_id" == currArg) && hasMoreArgs) {
revisionId = std::stoi(argv[argIndex + 1], nullptr, 0);
argIndex++;
@@ -783,7 +781,7 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
parseHwInfoConfigString(argv[argIndex + 1], hwInfoConfig);
if (!hwInfoConfig) {
argHelper->printf("Error: Invalid config.\n");
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
break;
}
argIndex++;
@@ -791,7 +789,7 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
allowCaching = true;
} else {
argHelper->printf("Invalid option (arg %d): %s\n", argIndex, argv[argIndex].c_str());
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
break;
}
}
@@ -802,7 +800,7 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
if (!binaryOutputFile.empty() && (useGenFile || useCppFile || outputNoSuffix || !outputFile.empty())) {
argHelper->printf("Error: options: -gen_file/-cpp_file/-output_no_suffix/-output cannot be used with -o\n");
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
return retVal;
}
unifyExcludeIrFlags();
@@ -811,15 +809,15 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
revisionId = static_cast<unsigned short>(DebugManager.flags.OverrideRevision.get());
}
if (retVal == SUCCESS) {
if (retVal == OCLOC_SUCCESS) {
if (compile32 && compile64) {
argHelper->printf("Error: Cannot compile for 32-bit and 64-bit, please choose one.\n");
retVal |= INVALID_COMMAND_LINE;
retVal |= OCLOC_INVALID_COMMAND_LINE;
}
if (deviceName.empty() && (false == onlySpirV)) {
argHelper->printf("Error: Device name missing.\n");
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
}
for (const auto &device : deviceAcronymsFromDeviceOptions) {
@@ -837,17 +835,17 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
}
if (!isDeprecatedName) {
argHelper->printf("Error: Invalid device acronym passed to -device_options: %s\n", device.c_str());
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
}
}
}
if (inputFile.empty()) {
argHelper->printf("Error: Input file name missing.\n");
retVal = INVALID_COMMAND_LINE;
retVal = OCLOC_INVALID_COMMAND_LINE;
} else if (!argHelper->fileExists(inputFile)) {
argHelper->printf("Error: Input file %s missing.\n", inputFile.c_str());
retVal = INVALID_FILE;
retVal = OCLOC_INVALID_FILE;
}
}

View File

@@ -7,8 +7,8 @@
#include "offline_linker.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/ocloc_igc_facade.h"
#include "shared/source/compiler_interface/intermediate_representations.h"
#include "shared/source/device_binary_format/elf/elf_encoder.h"
@@ -42,43 +42,43 @@ OfflineLinker::~OfflineLinker() = default;
int OfflineLinker::initialize(size_t argsCount, const std::vector<std::string> &args) {
const auto parsingResult{parseCommand(argsCount, args)};
if (parsingResult != OclocErrorCode::SUCCESS) {
if (parsingResult != OCLOC_SUCCESS) {
return parsingResult;
}
// If a user requested help, then stop here.
if (operationMode == OperationMode::SHOW_HELP) {
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
const auto verificationResult{verifyLinkerCommand()};
if (verificationResult != OclocErrorCode::SUCCESS) {
if (verificationResult != OCLOC_SUCCESS) {
return verificationResult;
}
const auto loadingResult{loadInputFilesContent()};
if (loadingResult != OclocErrorCode::SUCCESS) {
if (loadingResult != OCLOC_SUCCESS) {
return loadingResult;
}
const auto hwInfoInitializationResult{initHardwareInfo()};
if (hwInfoInitializationResult != OclocErrorCode::SUCCESS) {
if (hwInfoInitializationResult != OCLOC_SUCCESS) {
return hwInfoInitializationResult;
}
const auto igcPreparationResult{igcFacade->initialize(hwInfo)};
if (igcPreparationResult != OclocErrorCode::SUCCESS) {
if (igcPreparationResult != OCLOC_SUCCESS) {
return igcPreparationResult;
}
operationMode = OperationMode::LINK_FILES;
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
int OfflineLinker::parseCommand(size_t argsCount, const std::vector<std::string> &args) {
if (argsCount < 2u) {
operationMode = OperationMode::SHOW_HELP;
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
for (size_t argIndex = 1u; argIndex < argsCount; ++argIndex) {
@@ -104,14 +104,14 @@ int OfflineLinker::parseCommand(size_t argsCount, const std::vector<std::string>
++argIndex;
} else if (currentArg == "--help") {
operationMode = OperationMode::SHOW_HELP;
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
} else {
argHelper->printf("Invalid option (arg %zd): %s\n", argIndex, currentArg.c_str());
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
IGC::CodeType::CodeType_t OfflineLinker::parseOutputFormat(const std::string &outputFormatName) {
@@ -131,27 +131,27 @@ IGC::CodeType::CodeType_t OfflineLinker::parseOutputFormat(const std::string &ou
int OfflineLinker::verifyLinkerCommand() {
if (inputFilenames.empty()) {
argHelper->printf("Error: Input name is missing! At least one input file is required!\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
for (const auto &filename : inputFilenames) {
if (filename.empty()) {
argHelper->printf("Error: Empty filename cannot be used!\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
if (!argHelper->fileExists(filename)) {
argHelper->printf("Error: Input file %s missing.\n", filename.c_str());
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
}
if (outputFormat == IGC::CodeType::invalid) {
argHelper->printf("Error: Invalid output type!\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
int OfflineLinker::loadInputFilesContent() {
@@ -166,19 +166,19 @@ int OfflineLinker::loadInputFilesContent() {
bytes = argHelper->loadDataFromFile(filename, size);
if (size == 0) {
argHelper->printf("Error: Cannot read input file: %s\n", filename.c_str());
return OclocErrorCode::INVALID_FILE;
return OCLOC_INVALID_FILE;
}
codeType = detectCodeType(bytes.get(), size);
if (codeType == IGC::CodeType::invalid) {
argHelper->printf("Error: Unsupported format of input file: %s\n", filename.c_str());
return OclocErrorCode::INVALID_PROGRAM;
return OCLOC_INVALID_PROGRAM;
}
inputFilesContent.emplace_back(std::move(bytes), size, codeType);
}
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
IGC::CodeType::CodeType_t OfflineLinker::detectCodeType(char *bytes, size_t size) const {
@@ -208,12 +208,12 @@ int OfflineLinker::initHardwareInfo() {
setHwInfoValuesFromConfig(hwInfoConfig, hwInfo);
hardwareInfoSetup[hwInfo.platform.eProductFamily](&hwInfo, true, hwInfoConfig, *compilerProductHelper);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
}
argHelper->printf("Error! Cannot retrieve any valid hardware information!\n");
return OclocErrorCode::INVALID_DEVICE;
return OCLOC_INVALID_DEVICE;
}
ArrayRef<const HardwareInfo *> OfflineLinker::getHardwareInfoTable() const {
@@ -230,7 +230,7 @@ int OfflineLinker::execute() {
[[fallthrough]];
default:
argHelper->printf("Error: Linker cannot be executed due to unsuccessful initialization!\n");
return OclocErrorCode::INVALID_COMMAND_LINE;
return OCLOC_INVALID_COMMAND_LINE;
}
}
@@ -271,18 +271,18 @@ Examples:
argHelper->printf(help);
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
int OfflineLinker::link() {
const auto encodedElfFile{createSingleInputFile()};
if (outputFormat == IGC::CodeType::elf) {
argHelper->saveOutput(outputFilename, encodedElfFile.data(), encodedElfFile.size());
return OclocErrorCode::SUCCESS;
return OCLOC_SUCCESS;
}
const auto [translationResult, translatedBitcode] = translateToOutputFormat(encodedElfFile);
if (translationResult == OclocErrorCode::SUCCESS) {
if (translationResult == OCLOC_SUCCESS) {
argHelper->saveOutput(outputFilename, translatedBitcode.data(), translatedBitcode.size());
}
@@ -318,7 +318,7 @@ std::pair<int, std::vector<uint8_t>> OfflineLinker::translateToOutputFormat(cons
std::vector<uint8_t> outputFileContent{};
if (!igcOutput) {
argHelper->printf("Error: Translation has failed! IGC output is nullptr!\n");
return {OclocErrorCode::OUT_OF_HOST_MEMORY, std::move(outputFileContent)};
return {OCLOC_OUT_OF_HOST_MEMORY, std::move(outputFileContent)};
}
if (igcOutput->GetOutput()->GetSizeRaw() != 0) {
@@ -328,8 +328,8 @@ std::pair<int, std::vector<uint8_t>> OfflineLinker::translateToOutputFormat(cons
tryToStoreBuildLog(igcOutput->GetBuildLog()->GetMemory<char>(), igcOutput->GetBuildLog()->GetSizeRaw());
const auto errorCode{igcOutput->Successful() && !outputFileContent.empty() ? OclocErrorCode::SUCCESS : OclocErrorCode::BUILD_PROGRAM_FAILURE};
if (errorCode != OclocErrorCode::SUCCESS) {
const auto errorCode{igcOutput->Successful() && !outputFileContent.empty() ? OCLOC_SUCCESS : OCLOC_BUILD_PROGRAM_FAILURE};
if (errorCode != OCLOC_SUCCESS) {
argHelper->printf("Error: Translation has failed! IGC returned empty output.\n");
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/offline_compiler.h"
#include "shared/offline_compiler/source/offline_linker.h"
#include "shared/offline_compiler/source/utilities/linux/safety_guard_linux.h"
@@ -15,14 +15,14 @@ using namespace NEO;
int buildWithSafetyGuard(OfflineCompiler *compiler) {
SafetyGuardLinux safetyGuard;
int retVal = NEO::OclocErrorCode::COMPILATION_CRASH;
int retVal = OCLOC_COMPILATION_CRASH;
return safetyGuard.call<int, OfflineCompiler, decltype(&OfflineCompiler::build)>(compiler, &OfflineCompiler::build, retVal);
}
int linkWithSafetyGuard(OfflineLinker *linker) {
SafetyGuardLinux safetyGuard{};
int returnValueOnCrash{NEO::OclocErrorCode::COMPILATION_CRASH};
int returnValueOnCrash{OCLOC_COMPILATION_CRASH};
return safetyGuard.call(linker, &OfflineLinker::execute, returnValueOnCrash);
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/offline_compiler/source/ocloc_error_code.h"
#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/offline_compiler.h"
#include "shared/offline_compiler/source/offline_linker.h"
#include "shared/offline_compiler/source/utilities/windows/safety_guard_windows.h"
@@ -14,13 +14,13 @@ using namespace NEO;
int buildWithSafetyGuard(OfflineCompiler *compiler) {
SafetyGuardWindows safetyGuard;
int retVal = NEO::OclocErrorCode::COMPILATION_CRASH;
int retVal = OCLOC_COMPILATION_CRASH;
return safetyGuard.call<int, OfflineCompiler, decltype(&OfflineCompiler::build)>(compiler, &OfflineCompiler::build, retVal);
}
int linkWithSafetyGuard(OfflineLinker *linker) {
SafetyGuardWindows safetyGuard{};
int returnValueOnCrash{NEO::OclocErrorCode::COMPILATION_CRASH};
int returnValueOnCrash{OCLOC_COMPILATION_CRASH};
return safetyGuard.call(linker, &OfflineLinker::execute, returnValueOnCrash);
}