Ocloc: allow enforcing binary format specified by user

This commit adds ocloc option for specifying binary format.
When a --format flag is passed, the internal options will be changed
accordingly to the format specified (zebin/patchtokens) or a warning
will be printed if an unknown format will be passed.
Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
Kacper Nowak
2022-04-29 14:18:26 +00:00
committed by Compute-Runtime-Automation
parent bd6c9a222b
commit dd393d11a2
3 changed files with 75 additions and 0 deletions

View File

@@ -2777,6 +2777,57 @@ TEST(OclocCompile, givenSpirvInputThenDontGenerateSpirvFile) {
EXPECT_FALSE(compilerOutputExists("offline_compiler_test/binary_with_zeroes", "spv"));
}
TEST(OclocCompile, givenFormatFlagWithKnownFormatPassedThenEnforceSpecifiedFormatAccordingly) {
MockOfflineCompiler ocloc;
std::vector<std::string> argvEnforcedFormatPatchtokens = {
"ocloc",
"-q",
"-file",
"test_files/copybuffer.cl",
"-spv_only",
"--format",
"patchtokens"};
std::vector<std::string> argvEnforcedFormatZebin = {
"ocloc",
"-q",
"-file",
"test_files/copybuffer.cl",
"-spv_only",
"--format",
"zebin"};
int retVal = ocloc.initialize(argvEnforcedFormatZebin.size(), argvEnforcedFormatZebin);
ASSERT_EQ(0, retVal);
EXPECT_TRUE(hasSubstr(ocloc.internalOptions, std::string{CompilerOptions::allowZebin}));
ocloc.internalOptions.clear();
retVal = ocloc.initialize(argvEnforcedFormatPatchtokens.size(), argvEnforcedFormatPatchtokens);
ASSERT_EQ(0, retVal);
EXPECT_FALSE(hasSubstr(ocloc.internalOptions, std::string{CompilerOptions::allowZebin}));
}
TEST(OclocCompile, givenFormatFlagWithUnknownFormatPassedThenPrintWarning) {
MockOfflineCompiler ocloc;
std::vector<std::string> argvUnknownFormatEnforced = {
"ocloc",
"-file",
"test_files/copybuffer.cl",
"-spv_only",
"--format",
"banana"};
::testing::internal::CaptureStdout();
int retVal = ocloc.initialize(argvUnknownFormatEnforced.size(), argvUnknownFormatEnforced);
const auto output = testing::internal::GetCapturedStdout();
ASSERT_EQ(0, retVal);
const auto expectedOutput{"Invalid format passed: banana. Ignoring.\n"};
EXPECT_EQ(expectedOutput, output);
}
TEST(OfflineCompilerTest, GivenDebugFlagWhenSetStatelessToStatefullBufferOffsetFlagThenStatelessToStatefullOptimizationIsSetCorrectly) {
DebugManagerStateRestore stateRestore;
MockOfflineCompiler mockOfflineCompiler;