ocloc help cleanup

Change-Id: Iaae89f0805d4cbb55f2d5bc261ede2823de7bd71
This commit is contained in:
Krystian
2019-07-01 16:42:45 +02:00
committed by sys_ocldev
parent 40b00c7e8a
commit 3f76ab4469
7 changed files with 181 additions and 47 deletions

View File

@ -243,10 +243,37 @@ void BinaryDecoder::parseTokens() {
}
void BinaryDecoder::printHelp() {
messagePrinter.printf("Usage:\n-file <Opencl elf binary file> -patch <path to folder containing patchlist> -dump <path to dumping folder> -device <device_type>\n");
messagePrinter.printf("e.g. -file C:/my_folder/my_binary.bin -patch C:/igc/inc -dump C:/my_folder/dump\n");
messagePrinter.printf(" -device <device_type> Indicates which device for which we will compile.\n");
messagePrinter.printf(" <device_type> can be: %s\n", NEO::getDevicesTypes().c_str());
printf(R"===(Disassembles Intel OCL GPU device binary.
Usage: ocloc disasm -file <file> [-patch <patchtokens_dir>] [-dump <dump_dir>] [-device <device_type>]
-file <file> Input file to be disassembled.
This file should be an Intel OCL GPU device binary.
-patch <patchtokens_dir> Optional path to the directory containing
patchtoken definitions (patchlist.h, etc.)
as defined in intel-graphics-compiler (IGC) repo,
IGC subdirectory :
IGC/AdaptorOCL/ocl_igc_shared/executable_format
By default (when patchtokens_dir is not provided)
patchtokens won't be decoded.
-dump <dump_dir> Optional path for files representing decoded binary.
Default is './dump'.
-device <device_type> Optional target device of input binary
<device_type> can be: %s
By default ocloc will pick base device within
a generation - i.e. both skl and kbl will
fallback to skl. If specific product (e.g. kbl)
is needed, provide it as device_type.
--help Print this usage message.
Examples:
Disassemble Intel OCL GPU device binary
ocloc disasm -file source_file_Gen9core.bin
)===",
NEO::getDevicesTypes().c_str());
}
int BinaryDecoder::processBinary(void *&ptr, std::ostream &ptmFile) {

View File

@ -139,10 +139,30 @@ int BinaryEncoder::createElf() {
}
void BinaryEncoder::printHelp() {
messagePrinter.printf("Usage:\n-dump <path to dumping folder> -out <new elf file> -device <device_type>\n");
messagePrinter.printf("e.g. -dump C:/my_folder/dump -out C:/my_folder/new_binary.bin\n");
messagePrinter.printf(" -device <device_type> Indicates which device for which we will compile.\n");
messagePrinter.printf(" <device_type> can be: %s\n", NEO::getDevicesTypes().c_str());
printf(R"===(Assembles Intel OCL GPU device binary.
Usage: ocloc asm -out <out_file> [-dump <dump_dir>] [-device <device_type>]
-out <out_file> Filename for newly assembled binary.
-dump <dumping_dir> Path to the input directory containing
disassembled binary (as disassembled
by ocloc's disasm command).
Default is './dump'.
-device <device_type> Optional target device of output binary
<device_type> can be: %s
By default ocloc will pick base device within
a generation - i.e. both skl and kbl will
fallback to skl. If specific product (e.g. kbl)
is needed, provide it as device_type.
--help Print this usage message.
Examples:
Assemble to Intel OCL GPU device binary (after above disasm)
ocloc asm -out reassembled.bin
)===",
NEO::getDevicesTypes().c_str());
}
int BinaryEncoder::encode() {

View File

@ -18,9 +18,40 @@
using namespace NEO;
void printHelp() {
printf(R"===(ocloc is a tool for offline compilation to Intel OCL GPU device binary files.
It can be used for generation as well as manipulation (decoding/modifying)
of such binary files.
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 OCL GPU device binary.
disasm Disassembles Intel OCL GPU device binary.
asm Assembles Intel OCL GPU device binary.
multi Compiles multiple files using a config file.
Default command (when none provided) is 'compile'.
Examples:
Compile file to Intel OCL GPU device binary (out = source_file_Gen9core.bin)
ocloc -file source_file.cl -device skl
Disassemble Intel OCL GPU device binary
ocloc disasm -file source_file_Gen9core.bin
Assemble to Intel OCL GPU device binary (after above disasm)
ocloc asm -out reassembled.bin
)===");
}
int main(int numArgs, const char *argv[]) {
try {
if (numArgs > 1 && !strcmp(argv[1], "disasm")) {
if (numArgs == 1 || (numArgs > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) {
printHelp();
} else if (numArgs > 1 && !strcmp(argv[1], "disasm")) {
BinaryDecoder disasm;
int retVal = disasm.validateInput(numArgs, argv);
if (retVal == 0) {
@ -36,11 +67,9 @@ int main(int numArgs, const char *argv[]) {
} else {
return retVal;
}
} else if (numArgs > 1 && !strcmp(argv[1], "-multi")) {
} else if (numArgs > 1 && (!strcmp(argv[1], "multi") || !strcmp(argv[1], "-multi"))) {
int retValue = CL_SUCCESS;
auto pMulti = std::unique_ptr<MultiCommand>(MultiCommand::create(numArgs, argv, retValue));
return retValue;
} else {
int retVal = CL_SUCCESS;

View File

@ -103,10 +103,15 @@ void MultiCommand::addAdditionalOptionsToSingleCommandLine(std::vector<std::stri
int MultiCommand::initialize(int numArgs, const char *argv[]) {
int retVal = CL_SUCCESS;
if (!strcmp(argv[numArgs - 1], "--help")) {
printHelp();
return -1;
}
if (numArgs > 2)
pathToCMD = argv[2];
else {
printf("Lack of file with build arguments\n");
printHelp();
return INVALID_COMMAND_LINE;
}
if (numArgs > 3 && strcmp(argv[3], "-q") == 0)
@ -137,8 +142,24 @@ int MultiCommand::initialize(int numArgs, const char *argv[]) {
}
return showResults();
} else
} else {
printHelp();
return INVALID_COMMAND_LINE;
}
}
void MultiCommand::printHelp() {
printf(R"===(Compiles multiple files using a config file.
Usage: ocloc multi <file_name>
<file_name> Input file containing a list of arguments for subsequent
ocloc invocations.
Expected format of each line inside such file is:
'-file <filename> -device <device_type> [compile_options].
See 'ocloc compile --help' for available compile_options.
Results of subsequent compilations will be dumped into
a directory with name indentical file_name's base name.
)===");
}
int MultiCommand::splitLineInSeparateArgs(std::vector<std::string> &qargs, const std::string &command, int numberOfBuild) {

View File

@ -35,6 +35,7 @@ class MultiCommand {
int splitLineInSeparateArgs(std::vector<std::string> &qargs, const std::string &command, int numberOfBuild);
void openFileWithBuildsArguments();
void addAdditionalOptionsToSingleCommandLine(std::vector<std::string> &, int);
void printHelp();
int initialize(int numArgs, const char *argv[]);
int showResults();
int singleBuild(size_t numArgs, const std::vector<std::string> &allArgs);

View File

@ -465,8 +465,10 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
}
for (uint32_t argIndex = 1; argIndex < numArgs; argIndex++) {
if ((stringsAreEqual(argv[argIndex], "-file")) &&
(argIndex + 1 < numArgs)) {
if (stringsAreEqual(argv[argIndex], "compile")) {
//skip it
} else if ((stringsAreEqual(argv[argIndex], "-file")) &&
(argIndex + 1 < numArgs)) {
inputFile = argv[argIndex + 1];
argIndex++;
} else if ((stringsAreEqual(argv[argIndex], "-output")) &&
@ -509,7 +511,7 @@ int OfflineCompiler::parseCommandLine(size_t numArgs, const std::vector<std::str
argIndex++;
} else if (stringsAreEqual(argv[argIndex], "-q")) {
quiet = true;
} else if (stringsAreEqual(argv[argIndex], "-?")) {
} else if (stringsAreEqual(argv[argIndex], "--help")) {
printUsage();
retVal = PRINT_USAGE;
} else {
@ -655,36 +657,70 @@ std::string getDevicesTypes() {
// PrintUsage
////////////////////////////////////////////////////////////////////////////////
void OfflineCompiler::printUsage() {
printf(R"===(Compiles input file to Intel OCL GPU device binary.
Additionally, outputs intermediate representation (e.g. spirV).
Different input and intermediate file formats are available.
printf("Compiles CL files into llvm (.bc or .ll), gen isa (.gen), and binary files (.bin)\n\n");
printf("ocloc -file <filename> -device <device_type> [OPTIONS]\n\n");
printf(" -file <filename> Indicates the CL kernel file to be compiled.\n");
printf(" -device <device_type> Indicates which device for which we will compile.\n");
printf(" <device_type> can be: %s\n", getDevicesTypes().c_str());
printf("\n");
printf(" -multi <filename> Indicates the txt file with multi commands\n");
printf(" where each line is a single build in format:\n");
printf(" '-file <filename> -device <device_type> [OPTIONS]'\n");
printf(" Argument '-multi' must be first argument. \n");
printf(" Result of builds will be output in directory named \n");
printf(" like .txt file with build commands.\n");
printf("\n");
printf(" -output <filename> Indicates output files core name.\n");
printf(" -out_dir <output_dir> Indicates the directory into which the compiled files\n");
printf(" will be placed.\n");
printf(" -cpp_file Cpp file with scheduler program binary will be generated.\n");
printf("\n");
printf(" -32 Force compile to 32-bit binary.\n");
printf(" -64 Force compile to 64-bit binary.\n");
printf(" -internal_options <options> Compiler internal options.\n");
printf(" -llvm_text Readable LLVM text will be output in a .ll file instead of\n");
printf(" through the default lllvm binary (.bc) file.\n");
printf(" -llvm_input Indicates input file is llvm source\n");
printf(" -spirv_input Indicates input file is a SpirV binary\n");
printf(" -options <options> Compiler options.\n");
printf(" -options_name Add suffix with compile options to filename\n");
printf(" -q Be more quiet. print only warnings and errors.\n");
printf(" -? Print this usage message.\n");
Usage: ocloc [compile] -file <filename> -device <device_type> [-output <filename>] [-out_dir <output_dir>] [-options <options>] [-32|-64] [-internal_options <options>] [-llvm_text] [-llvm_input|-spirv_input] [-options_name] [-q] [-cpp_file] [--help]
-file <filename> The input file to be compiled
(by default input source format is
OCL C kernel language).
-device <device_type> Target device.
<device_type> can be: %s
-output <filename> Optional output file base name.
Default is input file's base name.
-out_dir <output_dir> Optional output directory.
Default is current working directory.
-options <options> Optional OCL C compilation options
as defined by OCL spec.
-32 Forces target architecture to 32-bit pointers.
Default is based on ocloc bittness.
This option is exclusive with -64.
-64 Forces target architecture to 64-bit pointers.
Default is based on ocloc bittness.
This option is exclusive with -32.
-internal_options <options> Optional compiler internal options
as defined by compilers used underneath.
Check intel-graphics-compiler (IGC) project
for details on available internal options.
-llvm_text Forces intermediate representation (IR) format
to human-readable LLVM IR (.ll).
Default IR is spirV.
-llvm_input Indicates that input file is an llvm binary.
Default is OCL C kernel language.
This option is exclusive with -spirv_input.
-spirv_input Indicates that input file is a spirV binary.
Default is OCL C kernel language format.
This option is exclusive with -llvm_input.
-options_name Will add suffix to generated files.
This suffix will be based on input options.
(Useful when rebuilding with different
set of options to not overwrite results).
-q Will silence most of output messages.
-cpp_file Will generate c++ file with C-array
containing Intel OCL device binary.
--help Print this usage message.
Examples :
Compile file to Intel OCL GPU device binary (out = source_file_Gen9core.bin)
ocloc -file source_file.cl -device skl
)===",
NEO::getDevicesTypes().c_str());
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -381,7 +381,7 @@ TEST_F(OfflineCompilerTests, GoodBuildTestWithOutputDir) {
TEST_F(OfflineCompilerTests, PrintUsage) {
std::vector<std::string> argv = {
"ocloc",
"-?"};
"--help"};
testing::internal::CaptureStdout();
pOfflineCompiler = OfflineCompiler::create(argv.size(), argv, retVal);