diff --git a/shared/source/compiler_interface/compiler_interface.cpp b/shared/source/compiler_interface/compiler_interface.cpp index 4153fe6631..c37e095d82 100644 --- a/shared/source/compiler_interface/compiler_interface.cpp +++ b/shared/source/compiler_interface/compiler_interface.cpp @@ -473,7 +473,10 @@ CIF::RAII::UPtr_t CompilerInterface::createFclT } if (fclBaseTranslationCtx == nullptr) { - fclBaseTranslationCtx = deviceCtx->CreateTranslationCtx(inType, outType); + auto ulock = this->lock(); + if (fclBaseTranslationCtx == nullptr) { + fclBaseTranslationCtx = deviceCtx->CreateTranslationCtx(inType, outType); + } } return deviceCtx->CreateTranslationCtx(inType, outType); diff --git a/shared/test/common/mocks/mock_compiler_interface.h b/shared/test/common/mocks/mock_compiler_interface.h index 102f9f7061..c27520322a 100644 --- a/shared/test/common/mocks/mock_compiler_interface.h +++ b/shared/test/common/mocks/mock_compiler_interface.h @@ -21,6 +21,7 @@ namespace NEO { class MockCompilerInterface : public CompilerInterface { public: + using CompilerInterface::fclBaseTranslationCtx; using CompilerInterface::fclDeviceContexts; using CompilerInterface::initialize; using CompilerInterface::isCompilerAvailable; diff --git a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp index 7167141230..bbdb8ea1d3 100644 --- a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp +++ b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp @@ -684,20 +684,25 @@ struct MockCompilerDeviceCtx : DeviceCtxBase { template struct LockListener { - LockListener(NEO::Device *device) - : device(device) { + LockListener(NEO::Device *device, bool createDeviceCtxOnLock = true) + : device(device), createDeviceCtxOnLock(createDeviceCtxOnLock) { } static void listener(MockCompilerInterface &compInt) { auto data = (LockListener *)compInt.lockListenerData; - auto deviceCtx = CIF::RAII::UPtr(new MockDeviceCtx); - EXPECT_TRUE(compInt.getDeviceContexts().empty()); - compInt.setDeviceCtx(*data->device, deviceCtx.get()); - data->createdDeviceCtx = deviceCtx.get(); + data->lockCount += 1; + if (data->createDeviceCtxOnLock && compInt.getDeviceContexts().empty()) { + + auto deviceCtx = CIF::RAII::UPtr(new MockDeviceCtx); + compInt.setDeviceCtx(*data->device, deviceCtx.get()); + data->createdDeviceCtx = deviceCtx.get(); + } } NEO::Device *device = nullptr; MockDeviceCtx *createdDeviceCtx = nullptr; + bool createDeviceCtxOnLock = false; + int lockCount = 0; }; struct WasLockedListener { @@ -768,7 +773,9 @@ TEST_F(CompilerInterfaceTest, GivenSimultaneousRequestForNewFclTranslationContex this->pCompilerInterface->lockListenerData = &listenerData; this->pCompilerInterface->lockListener = ListenerT::listener; + EXPECT_EQ(0, listenerData.lockCount); auto ret = this->pCompilerInterface->createFclTranslationCtx(*device, IGC::CodeType::oclC, IGC::CodeType::spirV); + EXPECT_EQ(2, listenerData.lockCount); EXPECT_NE(nullptr, ret.get()); ASSERT_EQ(1U, this->pCompilerInterface->getFclDeviceContexts().size()); ASSERT_NE(this->pCompilerInterface->getFclDeviceContexts().end(),