From cab8968e1a554e8de74b103f948d4c0814fab017 Mon Sep 17 00:00:00 2001 From: Jaroslaw Chodor Date: Sat, 2 Nov 2019 13:09:17 +0100 Subject: [PATCH] Fixing regression in rebuildFromIr Change-Id: If1604861180d935575cd06fb2978df114453a070 --- Jenkinsfile | 2 +- .../compiler_interface_tests.cpp | 10 +++---- runtime/program/program.cpp | 11 +++++-- unit_tests/fixtures/program_fixture.cpp | 10 +++---- unit_tests/program/program_tests.cpp | 29 +++++++++++++++++++ 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 30034cc853..f83993baa7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ #!groovy dependenciesRevision='682c4e3d433c6796acebfcbc8f0e2a5135f58412-1330' strategy='EQUAL' -allowedCD=259 +allowedCD=258 allowedF=7 diff --git a/core/unit_tests/compiler_interface/compiler_interface_tests.cpp b/core/unit_tests/compiler_interface/compiler_interface_tests.cpp index 65b936c833..f65385460e 100644 --- a/core/unit_tests/compiler_interface/compiler_interface_tests.cpp +++ b/core/unit_tests/compiler_interface/compiler_interface_tests.cpp @@ -693,7 +693,7 @@ struct LockListener { : device(device) { } - static void Listener(MockCompilerInterface &compInt) { + static void listener(MockCompilerInterface &compInt) { auto data = (LockListener *)compInt.lockListenerData; auto deviceCtx = CIF::RAII::UPtr(new MockDeviceCtx); EXPECT_TRUE(compInt.getDeviceContexts().empty()); @@ -733,7 +733,7 @@ TEST_F(CompilerInterfaceTest, GivenSimultaneousRequestForNewFclTranslationContex using ListenerT = LockListener; ListenerT listenerData(device); this->pCompilerInterface->lockListenerData = &listenerData; - this->pCompilerInterface->lockListener = ListenerT::Listener; + this->pCompilerInterface->lockListener = ListenerT::listener; auto ret = this->pCompilerInterface->createFclTranslationCtx(*device, IGC::CodeType::oclC, IGC::CodeType::spirV); EXPECT_NE(nullptr, ret.get()); @@ -790,7 +790,7 @@ TEST_F(CompilerInterfaceTest, GivenSimultaneousRequestForNewIgcTranslationContex using ListenerT = LockListener; ListenerT listenerData{device}; this->pCompilerInterface->lockListenerData = &listenerData; - this->pCompilerInterface->lockListener = ListenerT::Listener; + this->pCompilerInterface->lockListener = ListenerT::listener; auto ret = this->pCompilerInterface->createIgcTranslationCtx(*device, IGC::CodeType::spirV, IGC::CodeType::oclGenBin); EXPECT_NE(nullptr, ret.get()); @@ -900,7 +900,7 @@ TEST_F(CompilerInterfaceTest, IsCompilerAvailable) { EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::llvmLl, IGC::CodeType::oclGenBin)); EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::llvmBc)); EXPECT_TRUE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::oclGenBin)); - this->pCompilerInterface->fclMain = std::move(befIgcImain); + this->pCompilerInterface->fclMain = std::move(befFclImain); befIgcImain = std::move(this->pCompilerInterface->igcMain); befFclImain = std::move(this->pCompilerInterface->fclMain); @@ -916,7 +916,7 @@ TEST_F(CompilerInterfaceTest, IsCompilerAvailable) { EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::llvmBc)); EXPECT_FALSE(this->pCompilerInterface->isCompilerAvailable(IGC::CodeType::elf, IGC::CodeType::oclGenBin)); this->pCompilerInterface->igcMain = std::move(befIgcImain); - this->pCompilerInterface->fclMain = std::move(befIgcImain); + this->pCompilerInterface->fclMain = std::move(befFclImain); } TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenGetSipKernelBinaryFailsGracefully) { diff --git a/runtime/program/program.cpp b/runtime/program/program.cpp index 394ca9f091..c1706d585a 100644 --- a/runtime/program/program.cpp +++ b/runtime/program/program.cpp @@ -188,12 +188,19 @@ cl_int Program::rebuildProgramFromIr() { inputArgs.apiOptions = ArrayRef(options); inputArgs.internalOptions = ArrayRef(internalOptions); - TranslationOutput output = {}; - auto err = pCompilerInterface->link(*this->pDevice, inputArgs, output); + TranslationOutput compilerOuput = {}; + auto err = pCompilerInterface->link(*this->pDevice, inputArgs, compilerOuput); + this->updateBuildLog(this->pDevice, compilerOuput.frontendCompilerLog.c_str(), compilerOuput.frontendCompilerLog.size()); + this->updateBuildLog(this->pDevice, compilerOuput.backendCompilerLog.c_str(), compilerOuput.backendCompilerLog.size()); if (TranslationOutput::ErrorCode::Success != err) { return asClError(err); } + this->genBinary = std::move(compilerOuput.deviceBinary.mem); + this->genBinarySize = compilerOuput.deviceBinary.size; + this->debugData = std::move(compilerOuput.debugData.mem); + this->debugDataSize = compilerOuput.debugData.size; + auto retVal = processGenBinary(); if (retVal != CL_SUCCESS) { return retVal; diff --git a/unit_tests/fixtures/program_fixture.cpp b/unit_tests/fixtures/program_fixture.cpp index 555726cd26..10c150820b 100644 --- a/unit_tests/fixtures/program_fixture.cpp +++ b/unit_tests/fixtures/program_fixture.cpp @@ -11,15 +11,15 @@ #include "unit_tests/mocks/mock_program.h" namespace NEO { -void ProgramFixture::CreateProgramWithSource(cl_context pContext, - cl_device_id *pDeviceList, - const std::string &SourceFileName) { +void ProgramFixture::CreateProgramWithSource(cl_context context, + cl_device_id *deviceList, + const std::string &sourceFileName) { Cleanup(); cl_int retVal = CL_SUCCESS; std::string testFile; testFile.append(clFiles); - testFile.append(SourceFileName); + testFile.append(sourceFileName); ASSERT_EQ(true, fileExists(testFile)); knownSource = loadDataFromFile( @@ -31,7 +31,7 @@ void ProgramFixture::CreateProgramWithSource(cl_context pContext, const char *sources[1] = {knownSource.get()}; pProgram = Program::create( - pContext, + context, 1, sources, &knownSourceSize, diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index 94b8dcd904..3fda2987ff 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -2975,6 +2975,35 @@ TEST_F(ProgramTests, givenProgramWithSpirvWhenRebuildProgramIsCalledThenSpirvPat EXPECT_EQ(0, memcmp(spirv, spvSectionData, spvSectionDataSize)); } +TEST_F(ProgramTests, whenRebuildingProgramThenStoreDeviceBinaryProperly) { + auto device = castToObject(pContext->getDevice(0)); + + auto compilerInterface = new MockCompilerInterface(); + pDevice->getExecutionEnvironment()->compilerInterface.reset(compilerInterface); + auto compilerMain = new MockCIFMain(); + compilerInterface->SetIgcMain(compilerMain); + compilerMain->setDefaultCreatorFunc(NEO::MockIgcOclDeviceCtx::Create); + + MockCompilerDebugVars debugVars = {}; + char binaryToReturn[] = "abcdfghijklmnop"; + debugVars.binaryToReturn = binaryToReturn; + debugVars.binaryToReturnSize = sizeof(binaryToReturn); + gEnvironment->igcPushDebugVars(debugVars); + std::unique_ptr igcDebugVarsAutoPop{&gEnvironment, [](void *) { gEnvironment->igcPopDebugVars(); }}; + + auto program = clUniquePtr(new MockProgram(*pDevice->getExecutionEnvironment())); + program->setDevice(device); + uint32_t ir[16] = {0x03022307, 0x23471113, 0x17192329}; + program->irBinary = makeCopy(ir, sizeof(ir)); + program->irBinarySize = sizeof(ir); + EXPECT_EQ(nullptr, program->genBinary); + EXPECT_EQ(0U, program->genBinarySize); + program->rebuildProgramFromIr(); + ASSERT_NE(nullptr, program->genBinary); + ASSERT_EQ(sizeof(binaryToReturn), program->genBinarySize); + EXPECT_EQ(0, memcmp(binaryToReturn, program->genBinary.get(), program->genBinarySize)); +} + TEST_F(ProgramTests, givenProgramWhenInternalOptionsArePassedThenTheyAreRemovedFromBuildOptions) { ExecutionEnvironment executionEnvironment; MockProgram pProgram(executionEnvironment);