ocloc multi - fatBinary support

Change-Id: I0bb59829fbd01c798b26e8d6ef01c4ccd4280ae1
This commit is contained in:
chmielew
2020-05-18 11:47:20 +02:00
committed by sys_ocldev
parent ce04f0d0e3
commit 5a6144a5ce
4 changed files with 58 additions and 46 deletions

View File

@ -7,32 +7,38 @@
#include "shared/offline_compiler/source/multi_command.h"
#include "shared/offline_compiler/source/ocloc_fatbinary.h"
#include "shared/source/utilities/const_stringref.h"
#include <memory>
namespace NEO {
int MultiCommand::singleBuild(const std::vector<std::string> &allArgs) {
int MultiCommand::singleBuild(const std::vector<std::string> &args) {
int retVal = SUCCESS;
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(allArgs.size(), allArgs, true, retVal, argHelper)};
if (requestedFatBinary(args)) {
retVal = buildFatBinary(args, argHelper);
} else {
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(args.size(), args, true, retVal, argHelper)};
if (retVal == SUCCESS) {
retVal = buildWithSafetyGuard(pCompiler.get());
std::string &buildLog = pCompiler->getBuildLog();
if (buildLog.empty() == false) {
argHelper->printf("%s\n", buildLog.c_str());
}
}
outFileName += ".bin";
}
if (retVal == SUCCESS) {
retVal = buildWithSafetyGuard(pCompiler.get());
std::string &buildLog = pCompiler->getBuildLog();
if (buildLog.empty() == false) {
argHelper->printf("%s\n", buildLog.c_str());
}
if (retVal == ErrorCode::SUCCESS) {
if (!pCompiler->isQuiet())
argHelper->printf("Build succeeded.\n");
} else {
argHelper->printf("Build failed with error code: %d\n", retVal);
}
if (!quiet)
argHelper->printf("Build succeeded.\n");
} else {
argHelper->printf("Build failed with error code: %d\n", retVal);
}
if (retVal == SUCCESS) {
outputFile << getCurrentDirectoryOwn(outDirForBuilds) + outFileName + ".bin";
outputFile << getCurrentDirectoryOwn(outDirForBuilds) + outFileName;
} else {
outputFile << "Unsuccesful build";
}
@ -198,9 +204,9 @@ int MultiCommand::showResults() {
retValue |= retVal;
if (!quiet) {
if (retVal != SUCCESS) {
argHelper->printf("Build %d: failed. Error code: %d\n", indexRetVal, retVal);
argHelper->printf("Build command %d: failed. Error code: %d\n", indexRetVal, retVal);
} else {
argHelper->printf("Build %d: successful\n", indexRetVal);
argHelper->printf("Build command %d: successful\n", indexRetVal);
}
}
indexRetVal++;

View File

@ -90,8 +90,8 @@ int oclocInvoke(unsigned int numArgs, const char *argv[],
int retValue = ErrorCode::SUCCESS;
std::unique_ptr<MultiCommand> pMulti{(MultiCommand::create(allArgs, retValue, helper.get()))};
return retValue;
} else if (requestedFatBinary(numArgs, argv)) {
return buildFatbinary(numArgs, argv, helper.get());
} else if (requestedFatBinary(allArgs)) {
return buildFatBinary(allArgs, helper.get());
} else {
int retVal = ErrorCode::SUCCESS;

View File

@ -20,16 +20,15 @@
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <vector>
namespace NEO {
bool requestedFatBinary(int argc, const char *argv[]) {
for (int argIndex = 1; argIndex < argc; argIndex++) {
const auto &currArg = argv[argIndex];
const bool hasMoreArgs = (argIndex + 1 < argc);
bool requestedFatBinary(const std::vector<std::string> &args) {
for (size_t argIndex = 1; argIndex < args.size(); argIndex++) {
const auto &currArg = args[argIndex];
const bool hasMoreArgs = (argIndex + 1 < args.size());
if ((ConstStringRef("-device") == currArg) && hasMoreArgs) {
ConstStringRef deviceArg(argv[argIndex + 1], strlen(argv[argIndex + 1]));
ConstStringRef deviceArg(args[argIndex + 1]);
return deviceArg.contains("*") || deviceArg.contains("-") || deviceArg.contains(",") || deviceArg.contains("gen");
}
}
@ -203,21 +202,17 @@ std::vector<ConstStringRef> getTargetPlatformsForFatbinary(ConstStringRef device
return toProductNames(requestedPlatforms);
}
int buildFatbinary(int argc, const char *argv[], OclocArgHelper *argHelper) {
int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelper) {
std::string pointerSizeInBits = (sizeof(void *) == 4) ? "32" : "64";
int deviceArgIndex = -1;
size_t deviceArgIndex = -1;
std::string inputFileName = "";
std::string outputFileName = "";
std::string outputDirectory = "";
std::vector<std::string> argsCopy;
if (argc > 1) {
argsCopy.assign(argv, argv + argc);
}
for (int argIndex = 1; argIndex < argc; argIndex++) {
const auto &currArg = argv[argIndex];
const bool hasMoreArgs = (argIndex + 1 < argc);
std::vector<std::string> argsCopy(args);
for (size_t argIndex = 1; argIndex < args.size(); argIndex++) {
const auto &currArg = args[argIndex];
const bool hasMoreArgs = (argIndex + 1 < args.size());
if ((ConstStringRef("-device") == currArg) && hasMoreArgs) {
deviceArgIndex = argIndex + 1;
++argIndex;
@ -226,21 +221,21 @@ int buildFatbinary(int argc, const char *argv[], OclocArgHelper *argHelper) {
} else if ((CompilerOptions::arch64bit == currArg) || (ConstStringRef("-64") == currArg)) {
pointerSizeInBits = "64";
} else if ((ConstStringRef("-file") == currArg) && hasMoreArgs) {
inputFileName = argv[argIndex + 1];
inputFileName = args[argIndex + 1];
++argIndex;
} else if ((ConstStringRef("-output") == currArg) && hasMoreArgs) {
outputFileName = argv[argIndex + 1];
outputFileName = args[argIndex + 1];
++argIndex;
} else if ((ConstStringRef("-out_dir") == currArg) && hasMoreArgs) {
outputDirectory = argv[argIndex + 1];
outputDirectory = args[argIndex + 1];
++argIndex;
}
}
std::vector<ConstStringRef> targetPlatforms;
targetPlatforms = getTargetPlatformsForFatbinary(ConstStringRef(argv[deviceArgIndex], strlen(argv[deviceArgIndex])), argHelper);
targetPlatforms = getTargetPlatformsForFatbinary(ConstStringRef(args[deviceArgIndex]), argHelper);
if (targetPlatforms.empty()) {
argHelper->printf("Failed to parse target devices from : %s\n", argv[deviceArgIndex]);
argHelper->printf("Failed to parse target devices from : %s\n", args[deviceArgIndex].c_str());
return 1;
}
@ -250,7 +245,7 @@ int buildFatbinary(int argc, const char *argv[], OclocArgHelper *argHelper) {
int retVal = 0;
argsCopy[deviceArgIndex] = targetPlatform.str();
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(argc, argsCopy, false, retVal, argHelper)};
std::unique_ptr<OfflineCompiler> pCompiler{OfflineCompiler::create(argsCopy.size(), argsCopy, false, retVal, argHelper)};
if (ErrorCode::SUCCESS != retVal) {
argHelper->printf("Error! Couldn't create OfflineCompiler. Exiting.\n");
return retVal;
@ -271,8 +266,8 @@ int buildFatbinary(int argc, const char *argv[], OclocArgHelper *argHelper) {
} else {
argHelper->printf("Build failed for : %s with error code: %d\n", (targetPlatform.str() + "." + std::to_string(stepping)).c_str(), retVal);
argHelper->printf("Command was:");
for (auto i = 0; i < argc; ++i)
argHelper->printf(" %s", argv[i]);
for (const auto &arg : argsCopy)
argHelper->printf(" %s", arg.c_str());
argHelper->printf("\n");
}
}

View File

@ -11,14 +11,25 @@
#include "igfxfmid.h"
#include <string>
#include <vector>
class OclocArgHelper;
namespace NEO {
bool requestedFatBinary(int argc, const char *argv[]);
bool requestedFatBinary(const std::vector<std::string> &args);
inline bool requestedFatBinary(int argc, const char *argv[]) {
std::vector<std::string> args;
args.assign(argv, argv + argc);
return requestedFatBinary(args);
}
int buildFatbinary(int argc, const char *argv[], OclocArgHelper *argHelper);
int buildFatBinary(const std::vector<std::string> &args, OclocArgHelper *argHelper);
inline int buildFatBinary(int argc, const char *argv[], OclocArgHelper *argHelper) {
std::vector<std::string> args;
args.assign(argv, argv + argc);
return buildFatBinary(args, argHelper);
}
std::vector<PRODUCT_FAMILY> getAllSupportedTargetPlatforms();
std::vector<ConstStringRef> toProductNames(const std::vector<PRODUCT_FAMILY> &productIds);