diff --git a/opencl/source/command_queue/command_queue.cpp b/opencl/source/command_queue/command_queue.cpp index fe5301cac8..7438dccc0f 100644 --- a/opencl/source/command_queue/command_queue.cpp +++ b/opencl/source/command_queue/command_queue.cpp @@ -125,6 +125,7 @@ CommandQueue::~CommandQueue() { if (context && !isSpecialCommandQueue) { context->decRefInternal(); } + gtpinRemoveCommandQueue(this); } CommandStreamReceiver &CommandQueue::getGpgpuCommandStreamReceiver() const { diff --git a/opencl/source/gtpin/gtpin_callbacks.cpp b/opencl/source/gtpin/gtpin_callbacks.cpp index d7ceec4d02..c31e185fab 100644 --- a/opencl/source/gtpin/gtpin_callbacks.cpp +++ b/opencl/source/gtpin/gtpin_callbacks.cpp @@ -265,4 +265,18 @@ void gtpinSetIgcInit(void *pIgcInitPtr) { pIgcInit = static_cast(pIgcInitPtr); } +void gtpinRemoveCommandQueue(void *pCmdQueue) { + if (isGTPinInitialized) { + std::unique_lock lock{kernelExecQueueLock}; + size_t n = 0; + while (n < kernelExecQueue.size()) { + if (kernelExecQueue[n].pCommandQueue == pCmdQueue) { + kernelExecQueue.erase(kernelExecQueue.begin() + n); + } else { + n++; + } + } + } +} + } // namespace NEO diff --git a/opencl/source/gtpin/gtpin_notify.h b/opencl/source/gtpin/gtpin_notify.h index 400a854e6b..5bcba6a907 100644 --- a/opencl/source/gtpin/gtpin_notify.h +++ b/opencl/source/gtpin/gtpin_notify.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2020 Intel Corporation + * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -27,4 +27,5 @@ void gtpinNotifyPlatformShutdown(); inline bool gtpinIsGTPinInitialized() { return isGTPinInitialized; } void *gtpinGetIgcInit(); void gtpinSetIgcInit(void *pIgcInitPtr); +void gtpinRemoveCommandQueue(void *pCmdQueue); } // namespace NEO diff --git a/opencl/test/unit_test/gtpin/gtpin_tests.cpp b/opencl/test/unit_test/gtpin/gtpin_tests.cpp index 52b6646d0d..a48a9a92fb 100644 --- a/opencl/test/unit_test/gtpin/gtpin_tests.cpp +++ b/opencl/test/unit_test/gtpin/gtpin_tests.cpp @@ -2830,4 +2830,49 @@ HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtpinNot mockGAHandle.reset(); allocDataHandle.reset(); } + +TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenGtpinRemoveCommandQueueIsCalledThenAllKernelsFromCmdQueueAreRemoved) { + gtpinCallbacks.onContextCreate = OnContextCreate; + gtpinCallbacks.onContextDestroy = OnContextDestroy; + gtpinCallbacks.onKernelCreate = OnKernelCreate; + gtpinCallbacks.onKernelSubmit = OnKernelSubmit; + gtpinCallbacks.onCommandBufferCreate = OnCommandBufferCreate; + gtpinCallbacks.onCommandBufferComplete = OnCommandBufferComplete; + retFromGtPin = GTPin_Init(>pinCallbacks, &driverServices, nullptr); + EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin); + + kernelExecQueue.clear(); + + CommandQueue *cmdQ1 = reinterpret_cast(1); + CommandQueue *cmdQ2 = reinterpret_cast(2); + Kernel *kernel1 = reinterpret_cast(1); + Kernel *kernel2 = reinterpret_cast(2); + Kernel *kernel3 = reinterpret_cast(3); + Kernel *kernel4 = reinterpret_cast(4); + + gtpinkexec_t kExec; + kExec.pKernel = kernel1; + kExec.pCommandQueue = cmdQ1; + kernelExecQueue.push_back(kExec); + + kExec.pKernel = kernel2; + kExec.pCommandQueue = cmdQ1; + kernelExecQueue.push_back(kExec); + + kExec.pKernel = kernel3; + kExec.pCommandQueue = cmdQ2; + kernelExecQueue.push_back(kExec); + + kExec.pKernel = kernel4; + kExec.pCommandQueue = cmdQ2; + kernelExecQueue.push_back(kExec); + EXPECT_EQ(4u, kernelExecQueue.size()); + + gtpinRemoveCommandQueue(cmdQ1); + EXPECT_EQ(2u, kernelExecQueue.size()); + + gtpinRemoveCommandQueue(cmdQ2); + EXPECT_EQ(0u, kernelExecQueue.size()); +} + } // namespace ULT