diff --git a/Jenkinsfile b/Jenkinsfile index f75c8a2b6b..e515184550 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,4 +2,4 @@ neoDependenciesRev='726029-739' strategy='EQUAL' allowedF=49 -allowedCD=375 +allowedCD=374 diff --git a/runtime/helpers/task_information.cpp b/runtime/helpers/task_information.cpp index 83ea44d970..e372c21a8f 100644 --- a/runtime/helpers/task_information.cpp +++ b/runtime/helpers/task_information.cpp @@ -105,6 +105,9 @@ CommandComputeKernel::CommandComputeKernel(CommandQueue &commandQueue, CommandSt this->surfaces.push_back(surface); } this->kernel = kernel; + if (kernel) { + kernel->incRefInternal(); + } this->kernelCount = kernelCount; } @@ -116,6 +119,9 @@ CommandComputeKernel::~CommandComputeKernel() { if (kernelOperation->ioh.get() == kernelOperation->dsh.get()) { kernelOperation->doNotFreeISH = true; } + if (kernel) { + kernel->decRefInternal(); + } } CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminated) { diff --git a/runtime/utilities/reference_tracked_object.h b/runtime/utilities/reference_tracked_object.h index 2f04c82d5b..053cb0c901 100644 --- a/runtime/utilities/reference_tracked_object.h +++ b/runtime/utilities/reference_tracked_object.h @@ -145,6 +145,7 @@ class ReferenceTrackedObject { unique_ptr_if_unused decRefInternal() { auto customDeleter = tryGetCustomDeleter(); bool unused = refInternal.dec(); + UNRECOVERABLE_IF(refInternal.peek() < 0); return unique_ptr_if_unused(static_cast(this), unused, customDeleter); } diff --git a/unit_tests/command_queue/command_queue_hw_tests.cpp b/unit_tests/command_queue/command_queue_hw_tests.cpp index 91991c2d74..2509a299a0 100644 --- a/unit_tests/command_queue/command_queue_hw_tests.cpp +++ b/unit_tests/command_queue/command_queue_hw_tests.cpp @@ -412,6 +412,23 @@ HWTEST_F(BlockedCommandQueueTest, givenCommandQueueWhichHasSomeUnusedHeapsWhenBl 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; HWTEST_F(CommandQueueHwRefCountTest, givenBlockedCmdQWhenNewBlockedEnqueueReplacesVirtualEventThenPreviousVirtualEventDecrementsCmdQRefCount) { diff --git a/unit_tests/event/event_tests.cpp b/unit_tests/event/event_tests.cpp index 8fea2f187e..a9215c5574 100644 --- a/unit_tests/event/event_tests.cpp +++ b/unit_tests/event/event_tests.cpp @@ -620,8 +620,8 @@ TEST_F(InternalsEventTest, givenBlockedKernelWithPrintfWhenSubmittedThenPrintOut delete pPrintfSurface; delete pKernelInfo; - delete pKernel; - delete pProgram; + pKernel->decRefInternal(); + pProgram->decRefInternal(); delete pCmdQ; } diff --git a/unit_tests/mocks/mock_kernel.h b/unit_tests/mocks/mock_kernel.h index 162415c82f..97cdd437a3 100644 --- a/unit_tests/mocks/mock_kernel.h +++ b/unit_tests/mocks/mock_kernel.h @@ -212,8 +212,8 @@ class MockKernelWithInternals { mockKernel->setSshLocal(&sshLocal, sizeof(sshLocal)); } ~MockKernelWithInternals() { - delete mockKernel; - delete mockProgram; + mockKernel->decRefInternal(); + mockProgram->decRefInternal(); } operator MockKernel *() {