Skip to content

Commit bd94572

Browse files
Removing dependent commandQueue kernels
Signed-off-by: Andrzej Koska <[email protected]> Related-To: NEO-6212
1 parent 34ad95a commit bd94572

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

opencl/source/command_queue/command_queue.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ CommandQueue::~CommandQueue() {
125125
if (context && !isSpecialCommandQueue) {
126126
context->decRefInternal();
127127
}
128+
gtpinRemoveCommandQueue(this);
128129
}
129130

130131
CommandStreamReceiver &CommandQueue::getGpgpuCommandStreamReceiver() const {

opencl/source/gtpin/gtpin_callbacks.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,18 @@ void gtpinSetIgcInit(void *pIgcInitPtr) {
265265
pIgcInit = static_cast<igc_init_t *>(pIgcInitPtr);
266266
}
267267

268+
void gtpinRemoveCommandQueue(void *pCmdQueue) {
269+
if (isGTPinInitialized) {
270+
std::unique_lock<GTPinLockType> lock{kernelExecQueueLock};
271+
size_t n = 0;
272+
while (n < kernelExecQueue.size()) {
273+
if (kernelExecQueue[n].pCommandQueue == pCmdQueue) {
274+
kernelExecQueue.erase(kernelExecQueue.begin() + n);
275+
} else {
276+
n++;
277+
}
278+
}
279+
}
280+
}
281+
268282
} // namespace NEO

opencl/source/gtpin/gtpin_notify.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2018-2020 Intel Corporation
2+
* Copyright (C) 2018-2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -27,4 +27,5 @@ void gtpinNotifyPlatformShutdown();
2727
inline bool gtpinIsGTPinInitialized() { return isGTPinInitialized; }
2828
void *gtpinGetIgcInit();
2929
void gtpinSetIgcInit(void *pIgcInitPtr);
30+
void gtpinRemoveCommandQueue(void *pCmdQueue);
3031
} // namespace NEO

opencl/test/unit_test/gtpin/gtpin_tests.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,4 +2830,49 @@ HWTEST_F(GTPinTestsWithLocalMemory, givenGtPinCanUseSharedAllocationWhenGtpinNot
28302830
mockGAHandle.reset();
28312831
allocDataHandle.reset();
28322832
}
2833+
2834+
TEST_F(GTPinTests, givenInitializedGTPinInterfaceWhenGtpinRemoveCommandQueueIsCalledThenAllKernelsFromCmdQueueAreRemoved) {
2835+
gtpinCallbacks.onContextCreate = OnContextCreate;
2836+
gtpinCallbacks.onContextDestroy = OnContextDestroy;
2837+
gtpinCallbacks.onKernelCreate = OnKernelCreate;
2838+
gtpinCallbacks.onKernelSubmit = OnKernelSubmit;
2839+
gtpinCallbacks.onCommandBufferCreate = OnCommandBufferCreate;
2840+
gtpinCallbacks.onCommandBufferComplete = OnCommandBufferComplete;
2841+
retFromGtPin = GTPin_Init(&gtpinCallbacks, &driverServices, nullptr);
2842+
EXPECT_EQ(GTPIN_DI_SUCCESS, retFromGtPin);
2843+
2844+
kernelExecQueue.clear();
2845+
2846+
CommandQueue *cmdQ1 = reinterpret_cast<CommandQueue *>(1);
2847+
CommandQueue *cmdQ2 = reinterpret_cast<CommandQueue *>(2);
2848+
Kernel *kernel1 = reinterpret_cast<Kernel *>(1);
2849+
Kernel *kernel2 = reinterpret_cast<Kernel *>(2);
2850+
Kernel *kernel3 = reinterpret_cast<Kernel *>(3);
2851+
Kernel *kernel4 = reinterpret_cast<Kernel *>(4);
2852+
2853+
gtpinkexec_t kExec;
2854+
kExec.pKernel = kernel1;
2855+
kExec.pCommandQueue = cmdQ1;
2856+
kernelExecQueue.push_back(kExec);
2857+
2858+
kExec.pKernel = kernel2;
2859+
kExec.pCommandQueue = cmdQ1;
2860+
kernelExecQueue.push_back(kExec);
2861+
2862+
kExec.pKernel = kernel3;
2863+
kExec.pCommandQueue = cmdQ2;
2864+
kernelExecQueue.push_back(kExec);
2865+
2866+
kExec.pKernel = kernel4;
2867+
kExec.pCommandQueue = cmdQ2;
2868+
kernelExecQueue.push_back(kExec);
2869+
EXPECT_EQ(4u, kernelExecQueue.size());
2870+
2871+
gtpinRemoveCommandQueue(cmdQ1);
2872+
EXPECT_EQ(2u, kernelExecQueue.size());
2873+
2874+
gtpinRemoveCommandQueue(cmdQ2);
2875+
EXPECT_EQ(0u, kernelExecQueue.size());
2876+
}
2877+
28332878
} // namespace ULT

0 commit comments

Comments
 (0)