Add reference on kernel in blocked scenarios.

- Prevents kernel destruction while it may still be in use.

Change-Id: I1f87d09c5cabf29644a1b06b63f1789dbb15985a
This commit is contained in:
Mrozek, Michal
2018-01-04 16:34:25 +01:00
parent 57137fea84
commit 3eb856b192
6 changed files with 29 additions and 5 deletions

2
Jenkinsfile vendored
View File

@@ -2,4 +2,4 @@
neoDependenciesRev='726029-739' neoDependenciesRev='726029-739'
strategy='EQUAL' strategy='EQUAL'
allowedF=49 allowedF=49
allowedCD=375 allowedCD=374

View File

@@ -105,6 +105,9 @@ CommandComputeKernel::CommandComputeKernel(CommandQueue &commandQueue, CommandSt
this->surfaces.push_back(surface); this->surfaces.push_back(surface);
} }
this->kernel = kernel; this->kernel = kernel;
if (kernel) {
kernel->incRefInternal();
}
this->kernelCount = kernelCount; this->kernelCount = kernelCount;
} }
@@ -116,6 +119,9 @@ CommandComputeKernel::~CommandComputeKernel() {
if (kernelOperation->ioh.get() == kernelOperation->dsh.get()) { if (kernelOperation->ioh.get() == kernelOperation->dsh.get()) {
kernelOperation->doNotFreeISH = true; kernelOperation->doNotFreeISH = true;
} }
if (kernel) {
kernel->decRefInternal();
}
} }
CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminated) { CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminated) {

View File

@@ -145,6 +145,7 @@ class ReferenceTrackedObject {
unique_ptr_if_unused<DerivedClass> decRefInternal() { unique_ptr_if_unused<DerivedClass> decRefInternal() {
auto customDeleter = tryGetCustomDeleter(); auto customDeleter = tryGetCustomDeleter();
bool unused = refInternal.dec(); bool unused = refInternal.dec();
UNRECOVERABLE_IF(refInternal.peek() < 0);
return unique_ptr_if_unused<DerivedClass>(static_cast<DerivedClass *>(this), unused, customDeleter); return unique_ptr_if_unused<DerivedClass>(static_cast<DerivedClass *>(this), unused, customDeleter);
} }

View File

@@ -412,6 +412,23 @@ HWTEST_F(BlockedCommandQueueTest, givenCommandQueueWhichHasSomeUnusedHeapsWhenBl
EXPECT_EQ(sshBase, ssh.getBase()); EXPECT_EQ(sshBase, ssh.getBase());
} }
HWTEST_F(BlockedCommandQueueTest, givenEnqueueBlockedByUserEventWhenItIsEnqueuedThenKernelReferenceCountIsIncreased) {
UserEvent userEvent(context);
MockKernelWithInternals mockKernelWithInternals(*pDevice);
auto mockKernel = mockKernelWithInternals.mockKernel;
size_t offset = 0;
size_t size = 1;
cl_event blockedEvent = &userEvent;
auto currentRefCount = mockKernel->getRefInternalCount();
pCmdQ->enqueueKernel(mockKernel, 1, &offset, &size, &size, 1, &blockedEvent, nullptr);
EXPECT_EQ(currentRefCount + 1, mockKernel->getRefInternalCount());
userEvent.setStatus(CL_COMPLETE);
EXPECT_EQ(currentRefCount, mockKernel->getRefInternalCount());
}
typedef CommandQueueHwTest CommandQueueHwRefCountTest; typedef CommandQueueHwTest CommandQueueHwRefCountTest;
HWTEST_F(CommandQueueHwRefCountTest, givenBlockedCmdQWhenNewBlockedEnqueueReplacesVirtualEventThenPreviousVirtualEventDecrementsCmdQRefCount) { HWTEST_F(CommandQueueHwRefCountTest, givenBlockedCmdQWhenNewBlockedEnqueueReplacesVirtualEventThenPreviousVirtualEventDecrementsCmdQRefCount) {

View File

@@ -620,8 +620,8 @@ TEST_F(InternalsEventTest, givenBlockedKernelWithPrintfWhenSubmittedThenPrintOut
delete pPrintfSurface; delete pPrintfSurface;
delete pKernelInfo; delete pKernelInfo;
delete pKernel; pKernel->decRefInternal();
delete pProgram; pProgram->decRefInternal();
delete pCmdQ; delete pCmdQ;
} }

View File

@@ -212,8 +212,8 @@ class MockKernelWithInternals {
mockKernel->setSshLocal(&sshLocal, sizeof(sshLocal)); mockKernel->setSshLocal(&sshLocal, sizeof(sshLocal));
} }
~MockKernelWithInternals() { ~MockKernelWithInternals() {
delete mockKernel; mockKernel->decRefInternal();
delete mockProgram; mockProgram->decRefInternal();
} }
operator MockKernel *() { operator MockKernel *() {