Skip to content

Commit d106980

Browse files
ocloc: allow options to be used when using spirv input
Related-To: NEO-3128 Change-Id: Ib46e17003c81aff0cec23273674b639b9572c80f Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 20e0d8c commit d106980

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

offline_compiler/offline_compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int OfflineCompiler::buildSourceCode() {
166166

167167
} else {
168168
auto igcSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), sourceCode.c_str(), sourceCode.size());
169-
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
169+
auto igcOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), options.c_str(), options.size());
170170
auto igcInternalOptions = CIF::Builtins::CreateConstBuffer(igcMain.get(), internalOptions.c_str(), internalOptions.size());
171171
auto igcTranslationCtx = igcDeviceCtx->CreateTranslationCtx(inputFileSpirV ? IGC::CodeType::spirV : IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin);
172172
igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);

unit_tests/offline_compiler/offline_compiler_tests.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ TEST(OfflineCompilerTest, givenDefaultOfflineCompilerObjectWhenNoOptionsAreChang
631631
EXPECT_FALSE(mockOfflineCompiler->inputFileSpirV);
632632
}
633633

634-
TEST(OfflineCompilerTest, givenIntermediatedRepresentationInputWhenBuildSourceCodeIsCalledThenProperTranslationContextIsUed) {
634+
TEST(OfflineCompilerTest, givenIntermediatedRepresentationInputWhenBuildSourceCodeIsCalledThenProperTranslationContextIsUsed) {
635635
MockOfflineCompiler mockOfflineCompiler;
636636
auto argv = {
637637
"ocloc",
@@ -676,6 +676,39 @@ TEST(OfflineCompilerTest, givenBinaryInputThenDontTruncateSourceAtFirstZero) {
676676
EXPECT_LT(0U, mockOfflineCompiler->sourceCode.size());
677677
}
678678

679+
TEST(OfflineCompilerTest, givenSpirvInputFileWhenCmdLineHasOptionsThenCorrectOptionsArePassedToCompiler) {
680+
char data[] = {1, 2, 3, 4, 5, 6, 7, 8};
681+
MockCompilerDebugVars igcDebugVars(gEnvironment->igcDebugVars);
682+
igcDebugVars.binaryToReturn = data;
683+
igcDebugVars.binaryToReturnSize = sizeof(data);
684+
685+
NEO::setIgcDebugVars(igcDebugVars);
686+
687+
MockOfflineCompiler mockOfflineCompiler;
688+
auto argv = {
689+
"ocloc",
690+
"-file",
691+
"test_files/emptykernel.cl",
692+
"-spirv_input",
693+
"-device",
694+
gEnvironment->devicePrefix.c_str(),
695+
"-options",
696+
"test_options_passed"};
697+
698+
auto retVal = mockOfflineCompiler.initialize(argv.size(), argv.begin());
699+
auto mockIgcOclDeviceCtx = new NEO::MockIgcOclDeviceCtx();
700+
mockOfflineCompiler.igcDeviceCtx = CIF::RAII::Pack<IGC::IgcOclDeviceCtxLatest>(mockIgcOclDeviceCtx);
701+
ASSERT_EQ(CL_SUCCESS, retVal);
702+
703+
mockOfflineCompiler.inputFileSpirV = true;
704+
705+
retVal = mockOfflineCompiler.buildSourceCode();
706+
EXPECT_EQ(CL_SUCCESS, retVal);
707+
708+
EXPECT_STREQ("test_options_passed", mockOfflineCompiler.options.c_str());
709+
NEO::setIgcDebugVars(gEnvironment->igcDebugVars);
710+
}
711+
679712
TEST(OfflineCompilerTest, givenOutputFileOptionWhenSourceIsCompiledThenOutputFileHasCorrectName) {
680713
auto argv = {
681714
"ocloc",
@@ -773,7 +806,7 @@ TEST(OfflineCompilerTest, givenInternalOptionsWhenCmdLineParsedThenOptionsAreApp
773806
EXPECT_THAT(internalOptions, ::testing::HasSubstr(std::string("myInternalOptions")));
774807
}
775808

776-
TEST(OfflineCompilerTest, givenInputOtpionsAndInternalOptionsFilesWhenOfflineCompilerIsInitializedThenCorrectOptionsAreSetAndRemainAfterBuild) {
809+
TEST(OfflineCompilerTest, givenInputOptionsAndInternalOptionsFilesWhenOfflineCompilerIsInitializedThenCorrectOptionsAreSetAndRemainAfterBuild) {
777810
auto mockOfflineCompiler = std::unique_ptr<MockOfflineCompiler>(new MockOfflineCompiler());
778811
ASSERT_NE(nullptr, mockOfflineCompiler);
779812

0 commit comments

Comments
 (0)