ocloc - remove CL types

Change-Id: I724d9d64b1f883fccfea3b7c488921c2419bbe37
This commit is contained in:
chmielew 2020-03-04 09:57:37 +01:00 committed by sys_ocldev
parent e6b6f6d85d
commit 3e85c337f3
6 changed files with 56 additions and 179 deletions

View File

@ -1,128 +0,0 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "ocloc_api.h"
#include <iostream>
void printHelp() {
printf(R"===(ocloc is a tool for managing Intel OpenCL GPU device binary format.
It can be used for generation (as part of 'compile' command) as well as
manipulation (decoding/modifying - as part of 'disasm'/'asm' commands) of such
binary files.
Intel OpenCL GPU device binary is a format used by Intel OpenCL GPU runtime
(aka NEO). Intel OpenCL GPU runtime will return this binary format when queried
using clGetProgramInfo(..., CL_PROGRAM_BINARIES, ...). It will also honor
this format as input to clCreateProgramWithBinary function call.
ocloc does not require Intel GPU device to be present in the system nor does it
depend on Intel OpenCL GPU runtime driver to be installed. It does however rely
on the same set of compilers (IGC, common_clang) as the runtime driver.
Usage: ocloc [--help] <command> [<command_args>]
Available commands are listed below.
Use 'ocloc <command> --help' to get help about specific command.
Commands:
compile Compiles input to Intel OpenCL GPU device binary.
disasm Disassembles Intel OpenCL GPU device binary.
asm Assembles Intel OpenCL GPU device binary.
multi Compiles multiple files using a config file.
Default command (when none provided) is 'compile'.
Examples:
Compile file to Intel OpenCL GPU device binary (out = source_file_Gen9core.bin)
ocloc -file source_file.cl -device skl
Disassemble Intel OpenCL GPU device binary
ocloc disasm -file source_file_Gen9core.bin
Assemble to Intel OpenCL GPU device binary (after above disasm)
ocloc asm -out reassembled.bin
)===");
}
extern "C" {
int oclocInvoke(unsigned int numArgs, const char *argv[],
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) {
auto helper = std::make_unique<OclocArgHelper>(
numSources, dataSources, lenSources, nameSources,
numInputHeaders, dataInputHeaders, lenInputHeaders, nameInputHeaders,
numOutputs, dataOutputs, lenOutputs, nameOutputs);
std::vector<std::string> allArgs;
if (numArgs > 1) {
allArgs.assign(argv, argv + numArgs);
}
try {
if (numArgs == 1 || (numArgs > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) {
printHelp();
} else if (numArgs > 1 && !strcmp(argv[1], "disasm")) {
BinaryDecoder disasm(std::move(helper));
int retVal = disasm.validateInput(allArgs);
if (retVal == 0) {
return disasm.decode();
} else {
return retVal;
}
} else if (numArgs > 1 && !strcmp(argv[1], "asm")) {
BinaryEncoder assembler(std::move(helper));
int retVal = assembler.validateInput(allArgs);
if (retVal == 0) {
return assembler.encode();
} else {
return retVal;
}
} else if (numArgs > 1 && (!strcmp(argv[1], "multi") || !strcmp(argv[1], "-multi"))) {
int retValue = CL_SUCCESS;
auto pMulti = std::unique_ptr<MultiCommand>(MultiCommand::create(allArgs, retValue));
return retValue;
} else {
int retVal = CL_SUCCESS;
std::vector<std::string> allArgs;
if (numArgs > 1) {
allArgs.assign(argv, argv + numArgs);
}
OfflineCompiler *pCompiler = OfflineCompiler::create(numArgs, allArgs, true, retVal, std::move(helper));
if (retVal == CL_SUCCESS) {
retVal = buildWithSafetyGuard(pCompiler);
std::string buildLog = pCompiler->getBuildLog();
if (buildLog.empty() == false) {
printf("%s\n", buildLog.c_str());
}
if (retVal == CL_SUCCESS) {
if (!pCompiler->isQuiet())
printf("Build succeeded.\n");
} else {
printf("Build failed with error code: %d\n", retVal);
}
}
delete pCompiler;
return retVal;
}
} catch (const std::exception &e) {
printf("%s\n", e.what());
return -1;
}
return -1;
}
void oclocFreeOutput(uint32_t *numOutputs, uint8_t ***dataOutputs, uint64_t **lenOutputs, char ***nameOutputs) {
for (uint32_t i = 0; i < *numOutputs; i++) {
delete[](*dataOutputs)[i];
delete[](*nameOutputs)[i];
}
delete[](*dataOutputs);
delete[](*lenOutputs);
delete[](*nameOutputs);
}
}

View File

@ -149,7 +149,7 @@ int BinaryEncoder::encode() {
std::stringstream deviceBinary; //(pathToDump + "device_binary.bin", std::ios::binary);
int retVal = processBinary(ptmFile, deviceBinary);
argHelper->saveOutput(pathToDump + "device_binary.bin", deviceBinary.str().c_str(), deviceBinary.str().length());
if (retVal != CL_SUCCESS) {
if (retVal != 0) {
return retVal;
}

View File

@ -9,10 +9,10 @@
namespace NEO {
int MultiCommand::singleBuild(size_t numArgs, const std::vector<std::string> &allArgs) {
int retVal = CL_SUCCESS;
int retVal = ErrorCode::SUCCESS;
std::string buildLog;
OfflineCompiler *pCompiler = OfflineCompiler::create(numArgs, allArgs, true, retVal);
if (retVal == CL_SUCCESS) {
if (retVal == ErrorCode::SUCCESS) {
retVal = buildWithSafetyGuard(pCompiler);
buildLog = pCompiler->getBuildLog();
@ -20,7 +20,7 @@ int MultiCommand::singleBuild(size_t numArgs, const std::vector<std::string> &al
printf("%s\n", buildLog.c_str());
}
if (retVal == CL_SUCCESS) {
if (retVal == ErrorCode::SUCCESS) {
if (!pCompiler->isQuiet())
printf("Build succeeded.\n");
} else {
@ -36,7 +36,7 @@ int MultiCommand::singleBuild(size_t numArgs, const std::vector<std::string> &al
if (outputFileList != "") {
std::ofstream myfile(outputFileList, std::fstream::app);
if (myfile.is_open()) {
if (retVal == CL_SUCCESS)
if (retVal == ErrorCode::SUCCESS)
myfile << getCurrentDirectoryOwn(outDirForBuilds) + OutFileName + ".bin";
else
myfile << "Unsuccesful build";
@ -61,14 +61,14 @@ void MultiCommand::deleteBuildsWithWarnigs() {
}
MultiCommand *MultiCommand::create(const std::vector<std::string> &argv, int &retVal) {
retVal = CL_SUCCESS;
retVal = ErrorCode::SUCCESS;
auto pMultiCommand = new MultiCommand();
if (pMultiCommand) {
retVal = pMultiCommand->initialize(argv);
}
if (retVal != CL_SUCCESS) {
if (retVal != ErrorCode::SUCCESS) {
delete pMultiCommand;
pMultiCommand = nullptr;
}
@ -113,7 +113,7 @@ void MultiCommand::addAdditionalOptionsToSingleCommandLine(std::vector<std::stri
}
int MultiCommand::initialize(const std::vector<std::string> &allArgs) {
int retVal = CL_SUCCESS;
int retVal = ErrorCode::SUCCESS;
size_t numArgs = allArgs.size();
for (uint32_t argIndex = 1; argIndex < numArgs; argIndex++) {
@ -154,7 +154,7 @@ int MultiCommand::initialize(const std::vector<std::string> &allArgs) {
singleLineWithArguments.push_back(allArgs[0]);
retVal = splitLineInSeparateArgs(singleLineWithArguments, lines[i], i);
if (retVal != CL_SUCCESS) {
if (retVal != ErrorCode::SUCCESS) {
retValues.push_back(retVal);
continue;
}
@ -235,7 +235,7 @@ int MultiCommand::splitLineInSeparateArgs(std::vector<std::string> &qargs, const
printf("One of the quotes is open in build number %d\n", numberOfBuild + 1);
return INVALID_COMMAND_LINE;
}
return CL_SUCCESS;
return ErrorCode::SUCCESS;
}
void MultiCommand::openFileWithBuildsArguments() {
@ -260,11 +260,11 @@ void MultiCommand::openFileWithBuildsArguments() {
}
int MultiCommand::showResults() {
int retValue = CL_SUCCESS;
int retValue = ErrorCode::SUCCESS;
int indexRetVal = 0;
for (int retVal : retValues) {
if (retVal != CL_SUCCESS) {
if (retValue == CL_SUCCESS)
if (retVal != ErrorCode::SUCCESS) {
if (retValue == ErrorCode::SUCCESS)
retValue = retVal;
if (!quiet)
printf("Build %d: failed. Error code: %d\n", indexRetVal, retVal);

View File

@ -80,11 +80,11 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
return retVal;
}
} else if (numArgs > 1 && (!strcmp(argv[1], "multi") || !strcmp(argv[1], "-multi"))) {
int retValue = CL_SUCCESS;
int retValue = ErrorCode::SUCCESS;
auto pMulti = std::unique_ptr<MultiCommand>(MultiCommand::create(allArgs, retValue));
return retValue;
} else {
int retVal = CL_SUCCESS;
int retVal = ErrorCode::SUCCESS;
std::vector<std::string> allArgs;
if (numArgs > 1) {
allArgs.assign(argv, argv + numArgs);
@ -92,7 +92,7 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
OfflineCompiler *pCompiler = OfflineCompiler::create(numArgs, allArgs, true, retVal, std::move(helper));
if (retVal == CL_SUCCESS) {
if (retVal == ErrorCode::SUCCESS) {
retVal = buildWithSafetyGuard(pCompiler);
std::string buildLog = pCompiler->getBuildLog();
@ -100,7 +100,7 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
printf("%s\n", buildLog.c_str());
}
if (retVal == CL_SUCCESS) {
if (retVal == ErrorCode::SUCCESS) {
if (!pCompiler->isQuiet())
printf("Build succeeded.\n");
} else {

View File

@ -74,7 +74,7 @@ OfflineCompiler::~OfflineCompiler() {
}
OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles, int &retVal) {
retVal = CL_SUCCESS;
retVal = SUCCESS;
auto pOffCompiler = new OfflineCompiler();
if (pOffCompiler) {
@ -82,7 +82,7 @@ OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::
retVal = pOffCompiler->initialize(numArgs, allArgs, dumpFiles);
}
if (retVal != CL_SUCCESS) {
if (retVal != SUCCESS) {
delete pOffCompiler;
pOffCompiler = nullptr;
}
@ -91,7 +91,7 @@ OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::
}
OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::string> &allArgs, bool dumpFiles, int &retVal, std::unique_ptr<OclocArgHelper> helper) {
retVal = CL_SUCCESS;
retVal = SUCCESS;
auto pOffCompiler = new OfflineCompiler();
if (pOffCompiler) {
@ -99,7 +99,7 @@ OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::
retVal = pOffCompiler->initialize(numArgs, allArgs, dumpFiles);
}
if (retVal != CL_SUCCESS) {
if (retVal != SUCCESS) {
delete pOffCompiler;
pOffCompiler = nullptr;
}
@ -108,11 +108,11 @@ OfflineCompiler *OfflineCompiler::create(size_t numArgs, const std::vector<std::
}
int OfflineCompiler::buildSourceCode() {
int retVal = CL_SUCCESS;
int retVal = SUCCESS;
do {
if (strcmp(sourceCode.c_str(), "") == 0) {
retVal = CL_INVALID_PROGRAM;
retVal = INVALID_PROGRAM;
break;
}
UNRECOVERABLE_IF(igcDeviceCtx == nullptr);
@ -133,7 +133,7 @@ int OfflineCompiler::buildSourceCode() {
if (false == NEO::areNotNullptr(fclSrc.get(), fclOptions.get(), fclInternalOptions.get(),
fclTranslationCtx.get(), igcTranslationCtx.get())) {
retVal = CL_OUT_OF_HOST_MEMORY;
retVal = OUT_OF_HOST_MEMORY;
break;
}
@ -141,7 +141,7 @@ int OfflineCompiler::buildSourceCode() {
fclInternalOptions.get(), nullptr, 0);
if (fclOutput == nullptr) {
retVal = CL_OUT_OF_HOST_MEMORY;
retVal = OUT_OF_HOST_MEMORY;
break;
}
@ -150,7 +150,7 @@ int OfflineCompiler::buildSourceCode() {
if (fclOutput->Successful() == false) {
updateBuildLog(fclOutput->GetBuildLog()->GetMemory<char>(), fclOutput->GetBuildLog()->GetSizeRaw());
retVal = CL_BUILD_PROGRAM_FAILURE;
retVal = BUILD_PROGRAM_FAILURE;
break;
}
@ -170,7 +170,7 @@ int OfflineCompiler::buildSourceCode() {
igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);
}
if (igcOutput == nullptr) {
retVal = CL_OUT_OF_HOST_MEMORY;
retVal = OUT_OF_HOST_MEMORY;
break;
}
UNRECOVERABLE_IF(igcOutput->GetBuildLog() == nullptr);
@ -183,18 +183,18 @@ int OfflineCompiler::buildSourceCode() {
if (igcOutput->GetDebugData()->GetSizeRaw() != 0) {
storeBinary(debugDataBinary, debugDataBinarySize, igcOutput->GetDebugData()->GetMemory<char>(), igcOutput->GetDebugData()->GetSizeRaw());
}
retVal = igcOutput->Successful() ? CL_SUCCESS : CL_BUILD_PROGRAM_FAILURE;
retVal = igcOutput->Successful() ? SUCCESS : BUILD_PROGRAM_FAILURE;
} while (0);
return retVal;
}
int OfflineCompiler::build() {
int retVal = CL_SUCCESS;
int retVal = SUCCESS;
retVal = buildSourceCode();
if (retVal == CL_SUCCESS) {
if (retVal == SUCCESS) {
generateElfBinary();
if (dumpFiles) {
writeOutAllFiles();
@ -220,7 +220,7 @@ std::string &OfflineCompiler::getBuildLog() {
}
int OfflineCompiler::getHardwareInfo(const char *pDeviceName) {
int retVal = CL_INVALID_DEVICE;
int retVal = INVALID_DEVICE;
for (unsigned int productId = 0; productId < IGFX_MAX_PRODUCT; ++productId) {
if (hardwarePrefix[productId] && (0 == strcmp(pDeviceName, hardwarePrefix[productId]))) {
@ -229,7 +229,7 @@ int OfflineCompiler::getHardwareInfo(const char *pDeviceName) {
familyNameWithType.clear();
familyNameWithType.append(familyName[hwInfo->platform.eRenderCoreFamily]);
familyNameWithType.append(hwInfo->capabilityTable.platformType);
retVal = CL_SUCCESS;
retVal = SUCCESS;
break;
}
}
@ -256,13 +256,13 @@ 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 = CL_SUCCESS;
int retVal = SUCCESS;
const char *source = nullptr;
std::unique_ptr<char[]> sourceFromFile;
size_t sourceFromFileSize = 0;
retVal = parseCommandLine(numArgs, allArgs);
if (retVal != CL_SUCCESS) {
if (retVal != SUCCESS) {
return retVal;
}
@ -285,7 +285,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 != CL_SUCCESS) {
if (retVal != SUCCESS) {
return retVal;
}
}
@ -332,33 +332,33 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
auto fclLibFile = OsLibrary::load(Os::frontEndDllName);
if (fclLibFile == nullptr) {
printf("Error: Failed to load %s\n", Os::frontEndDllName);
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
this->fclLib.reset(fclLibFile);
if (this->fclLib == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
auto fclCreateMain = reinterpret_cast<CIF::CreateCIFMainFunc_t>(this->fclLib->getProcAddress(CIF::CreateCIFMainFuncName));
if (fclCreateMain == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
this->fclMain = CIF::RAII::UPtr(createMainNoSanitize(fclCreateMain));
if (this->fclMain == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
if (false == this->fclMain->IsCompatible<IGC::FclOclDeviceCtx>()) {
printf("Incompatible interface in FCL : %s\n", CIF::InterfaceIdCoder::Dec(this->fclMain->FindIncompatible<IGC::FclOclDeviceCtx>()).c_str());
DEBUG_BREAK_IF(true);
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
this->fclDeviceCtx = this->fclMain->CreateInterface<IGC::FclOclDeviceCtxTagOCL>();
if (this->fclDeviceCtx == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
fclDeviceCtx->SetOclApiVersion(hwInfo->capabilityTable.clVersionSupport * 10);
@ -372,42 +372,42 @@ int OfflineCompiler::initialize(size_t numArgs, const std::vector<std::string> &
this->igcLib.reset(OsLibrary::load(Os::igcDllName));
if (this->igcLib == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
auto igcCreateMain = reinterpret_cast<CIF::CreateCIFMainFunc_t>(this->igcLib->getProcAddress(CIF::CreateCIFMainFuncName));
if (igcCreateMain == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
this->igcMain = CIF::RAII::UPtr(createMainNoSanitize(igcCreateMain));
if (this->igcMain == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
std::vector<CIF::InterfaceId_t> interfacesToIgnore = {IGC::OclGenBinaryBase::GetInterfaceId()};
if (false == this->igcMain->IsCompatible<IGC::IgcOclDeviceCtx>(&interfacesToIgnore)) {
printf("Incompatible interface in IGC : %s\n", CIF::InterfaceIdCoder::Dec(this->igcMain->FindIncompatible<IGC::IgcOclDeviceCtx>(&interfacesToIgnore)).c_str());
DEBUG_BREAK_IF(true);
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
CIF::Version_t verMin = 0, verMax = 0;
if (false == this->igcMain->FindSupportedVersions<IGC::IgcOclDeviceCtx>(IGC::OclGenBinaryBase::GetInterfaceId(), verMin, verMax)) {
printf("Patchtoken interface is missing");
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
this->igcDeviceCtx = this->igcMain->CreateInterface<IGC::IgcOclDeviceCtxTagOCL>();
if (this->igcDeviceCtx == nullptr) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
this->igcDeviceCtx->SetProfilingTimerResolution(static_cast<float>(hwInfo->capabilityTable.defaultProfilingTimerResolution));
auto igcPlatform = this->igcDeviceCtx->GetPlatformHandle();
auto igcGtSystemInfo = this->igcDeviceCtx->GetGTSystemInfoHandle();
auto igcFeWa = this->igcDeviceCtx->GetIgcFeaturesAndWorkaroundsHandle();
if ((igcPlatform == nullptr) || (igcGtSystemInfo == nullptr) || (igcFeWa == nullptr)) {
return CL_OUT_OF_HOST_MEMORY;
return OUT_OF_HOST_MEMORY;
}
IGC::PlatformHelper::PopulateInterfaceWith(*igcPlatform.get(), hwInfo->platform);
IGC::GtSysInfoHelper::PopulateInterfaceWith(*igcGtSystemInfo.get(), hwInfo->gtSystemInfo);
@ -447,7 +447,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 = CL_SUCCESS;
int retVal = SUCCESS;
bool compile32 = false;
bool compile64 = false;
@ -515,7 +515,7 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
}
}
if (retVal == CL_SUCCESS) {
if (retVal == SUCCESS) {
if (compile32 && compile64) {
printf("Error: Cannot compile for 32-bit and 64-bit, please choose one.\n");
retVal = INVALID_COMMAND_LINE;
@ -530,7 +530,7 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
retVal = INVALID_FILE;
} else {
retVal = getHardwareInfo(deviceName.c_str());
if (retVal != CL_SUCCESS) {
if (retVal != SUCCESS) {
printf("Error: Cannot get HW Info for device %s.\n", deviceName.c_str());
} else {
std::string extensionsList = getExtensionsList(*hwInfo);

View File

@ -28,6 +28,11 @@ class OsLibrary;
std::string convertToPascalCase(const std::string &inString);
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,
PRINT_USAGE = -5152,