diff --git a/shared/offline_compiler/source/multi_command.cpp b/shared/offline_compiler/source/multi_command.cpp index 0684309303..24bc9cf141 100644 --- a/shared/offline_compiler/source/multi_command.cpp +++ b/shared/offline_compiler/source/multi_command.cpp @@ -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 namespace NEO { -int MultiCommand::singleBuild(const std::vector &allArgs) { +int MultiCommand::singleBuild(const std::vector &args) { int retVal = SUCCESS; - std::unique_ptr pCompiler{OfflineCompiler::create(allArgs.size(), allArgs, true, retVal, argHelper)}; + + if (requestedFatBinary(args)) { + retVal = buildFatBinary(args, argHelper); + } else { + std::unique_ptr 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++; diff --git a/shared/offline_compiler/source/ocloc_api.cpp b/shared/offline_compiler/source/ocloc_api.cpp index 3c7c4d226a..405056f03f 100644 --- a/shared/offline_compiler/source/ocloc_api.cpp +++ b/shared/offline_compiler/source/ocloc_api.cpp @@ -90,8 +90,8 @@ int oclocInvoke(unsigned int numArgs, const char *argv[], int retValue = ErrorCode::SUCCESS; std::unique_ptr 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; diff --git a/shared/offline_compiler/source/ocloc_fatbinary.cpp b/shared/offline_compiler/source/ocloc_fatbinary.cpp index ce7604d6b7..1cf29daecb 100644 --- a/shared/offline_compiler/source/ocloc_fatbinary.cpp +++ b/shared/offline_compiler/source/ocloc_fatbinary.cpp @@ -20,16 +20,15 @@ #include #include #include -#include 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 &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 getTargetPlatformsForFatbinary(ConstStringRef device return toProductNames(requestedPlatforms); } -int buildFatbinary(int argc, const char *argv[], OclocArgHelper *argHelper) { +int buildFatBinary(const std::vector &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 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 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 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 pCompiler{OfflineCompiler::create(argc, argsCopy, false, retVal, argHelper)}; + std::unique_ptr 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"); } } diff --git a/shared/offline_compiler/source/ocloc_fatbinary.h b/shared/offline_compiler/source/ocloc_fatbinary.h index b25864b4bd..fc00c22501 100644 --- a/shared/offline_compiler/source/ocloc_fatbinary.h +++ b/shared/offline_compiler/source/ocloc_fatbinary.h @@ -11,14 +11,25 @@ #include "igfxfmid.h" +#include #include class OclocArgHelper; namespace NEO { -bool requestedFatBinary(int argc, const char *argv[]); +bool requestedFatBinary(const std::vector &args); +inline bool requestedFatBinary(int argc, const char *argv[]) { + std::vector args; + args.assign(argv, argv + argc); + return requestedFatBinary(args); +} -int buildFatbinary(int argc, const char *argv[], OclocArgHelper *argHelper); +int buildFatBinary(const std::vector &args, OclocArgHelper *argHelper); +inline int buildFatBinary(int argc, const char *argv[], OclocArgHelper *argHelper) { + std::vector args; + args.assign(argv, argv + argc); + return buildFatBinary(args, argHelper); +} std::vector getAllSupportedTargetPlatforms(); std::vector toProductNames(const std::vector &productIds);