diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index f7db6d64a7..6021d02b23 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -158,6 +158,21 @@ uint32_t Context::getMaxRootDeviceIndex() const { } CommandQueue *Context::getSpecialQueue(uint32_t rootDeviceIndex) { + if (specialQueues[rootDeviceIndex]) + return specialQueues[rootDeviceIndex]; + + static std::mutex mtx; + std::lock_guard lock(mtx); + + if (!specialQueues[rootDeviceIndex]) { + cl_int errcodeRet = CL_SUCCESS; + auto deviceOrdinal = std::distance(this->getRootDeviceIndices().begin(), std::find(this->getRootDeviceIndices().begin(), this->getRootDeviceIndices().end(), rootDeviceIndex)); + auto commandQueue = CommandQueue::create(this, this->getDevice(deviceOrdinal), nullptr, true, errcodeRet); + DEBUG_BREAK_IF(commandQueue == nullptr); + DEBUG_BREAK_IF(errcodeRet != CL_SUCCESS); + overrideSpecialQueueAndDecrementRefCount(commandQueue, rootDeviceIndex); + } + return specialQueues[rootDeviceIndex]; } @@ -179,6 +194,7 @@ bool Context::createImpl(const cl_context_properties *properties, const ClDeviceVector &inputDevices, void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *), void *data, cl_int &errcodeRet) { + errcodeRet = CL_SUCCESS; auto propertiesCurrent = properties; bool interopUserSync = false; @@ -288,14 +304,6 @@ bool Context::createImpl(const cl_context_properties *properties, } } - for (auto &device : devices) { - if (!specialQueues[device->getRootDeviceIndex()]) { - auto commandQueue = CommandQueue::create(this, device, nullptr, true, errcodeRet); // NOLINT(clang-analyzer-cplusplus.NewDelete) - DEBUG_BREAK_IF(commandQueue == nullptr); - overrideSpecialQueueAndDecrementRefCount(commandQueue, device->getRootDeviceIndex()); - } - } - return true; } diff --git a/opencl/test/unit_test/context/context_tests.cpp b/opencl/test/unit_test/context/context_tests.cpp index 98d4f20e74..4ddda11e6b 100644 --- a/opencl/test/unit_test/context/context_tests.cpp +++ b/opencl/test/unit_test/context/context_tests.cpp @@ -120,7 +120,7 @@ TEST_F(ContextTest, WhenCreatingContextThenSpecialQueueIsAvailable) { TEST_F(ContextTest, WhenSettingSpecialQueueThenQueueIsAvailable) { MockContext context((ClDevice *)devices[0], true); - auto specialQ = context.getSpecialQueue(0u); + auto specialQ = context.specialQueues[0]; EXPECT_EQ(specialQ, nullptr); auto cmdQ = new MockCommandQueue(&context, (ClDevice *)devices[0], 0, false); diff --git a/opencl/test/unit_test/gtpin/gtpin_tests.cpp b/opencl/test/unit_test/gtpin/gtpin_tests.cpp index 8cf0bbc86e..28b00a591e 100644 --- a/opencl/test/unit_test/gtpin/gtpin_tests.cpp +++ b/opencl/test/unit_test/gtpin/gtpin_tests.cpp @@ -435,7 +435,7 @@ TEST_F(GTPinTests, givenInvalidArgumentsThenBufferUnMapFails) { } TEST_F(GTPinTests, givenValidRequestForHugeMemoryAllocationThenBufferAllocateFails) { - + [[maybe_unused]] auto cmdQ = pContext->getSpecialQueue(0); DebugManagerStateRestore restorer; for (auto &allocationInUSMShared : ::testing::Bool()) { debugManager.flags.GTPinAllocateBufferInSharedMemory.set(allocationInUSMShared);