diff --git a/opencl/source/command_queue/command_queue_hw.h b/opencl/source/command_queue/command_queue_hw.h index 064111f88a..0ea1190350 100644 --- a/opencl/source/command_queue/command_queue_hw.h +++ b/opencl/source/command_queue/command_queue_hw.h @@ -367,21 +367,21 @@ class CommandQueueHw : public CommandQueue { template cl_int enqueueBlitSplit(MultiDispatchInfo &dispatchInfo, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *event, bool blocking, CommandStreamReceiver &csr); - CompletionStamp enqueueNonBlocked(Surface **surfacesForResidency, - size_t surfaceCount, - LinearStream &commandStream, - size_t commandStreamStart, - bool &blocking, - bool clearDependenciesForSubCapture, - const MultiDispatchInfo &multiDispatchInfo, - const EnqueueProperties &enqueueProperties, - TimestampPacketDependencies ×tampPacketDependencies, - EventsRequest &eventsRequest, - EventBuilder &eventBuilder, - TaskCountType taskLevel, - PrintfHandler *printfHandler, - bool relaxedOrderingEnabled, - uint32_t commandType); + MOCKABLE_VIRTUAL CompletionStamp enqueueNonBlocked(Surface **surfacesForResidency, + size_t surfaceCount, + LinearStream &commandStream, + size_t commandStreamStart, + bool &blocking, + bool clearDependenciesForSubCapture, + const MultiDispatchInfo &multiDispatchInfo, + const EnqueueProperties &enqueueProperties, + TimestampPacketDependencies ×tampPacketDependencies, + EventsRequest &eventsRequest, + EventBuilder &eventBuilder, + TaskCountType taskLevel, + PrintfHandler *printfHandler, + bool relaxedOrderingEnabled, + uint32_t commandType); void enqueueBlocked(uint32_t commandType, Surface **surfacesForResidency, diff --git a/opencl/source/command_queue/enqueue_common.h b/opencl/source/command_queue/enqueue_common.h index d3870cc736..b42107baf9 100644 --- a/opencl/source/command_queue/enqueue_common.h +++ b/opencl/source/command_queue/enqueue_common.h @@ -410,6 +410,9 @@ cl_int CommandQueueHw::enqueueHandler(Surface **surfacesForResidency, } if (completionStamp.taskCount > CompletionStamp::notReady) { + if (deferredTimestampPackets.get()) { + timestampPacketContainer->moveNodesToNewContainer(*deferredTimestampPackets); + } return CommandQueue::getErrorCodeFromTaskCount(completionStamp.taskCount); } diff --git a/opencl/test/unit_test/command_queue/enqueue_handler_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_handler_tests.cpp index 73cb92e6f0..9413b055a8 100644 --- a/opencl/test/unit_test/command_queue/enqueue_handler_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_handler_tests.cpp @@ -716,14 +716,14 @@ HWTEST_F(EnqueueHandlerTest, givenKernelUsingSyncBufferWhenEnqueuingKernelThenSs } struct EnqueueHandlerTestBasic : public ::testing::Test { - template - std::unique_ptr> setupFixtureAndCreateMockCommandQueue() { + template + std::unique_ptr setupFixtureAndCreateMockCommandQueue() { auto executionEnvironment = platform()->peekExecutionEnvironment(); device = std::make_unique(MockDevice::createWithExecutionEnvironment(nullptr, executionEnvironment, 0u)); context = std::make_unique(device.get()); - auto mockCmdQ = std::make_unique>(context.get(), device.get(), nullptr); + auto mockCmdQ = std::make_unique(context.get(), device.get(), nullptr); auto &ultCsr = static_cast &>(mockCmdQ->getGpgpuCommandStreamReceiver()); ultCsr.taskCount = initialTaskCount; @@ -741,7 +741,7 @@ struct EnqueueHandlerTestBasic : public ::testing::Test { }; HWTEST_F(EnqueueHandlerTestBasic, givenEnqueueHandlerWhenCommandIsBlokingThenCompletionStampTaskCountIsPassedToWaitForTaskCountAndCleanAllocationListAsRequiredTaskCount) { - auto mockCmdQ = setupFixtureAndCreateMockCommandQueue(); + auto mockCmdQ = setupFixtureAndCreateMockCommandQueue, FamilyType>(); MockKernelWithInternals kernelInternals(*device, context.get()); Kernel *kernel = kernelInternals.mockKernel; MockMultiDispatchInfo multiDispatchInfo(device.get(), kernel); @@ -757,7 +757,7 @@ HWTEST_F(EnqueueHandlerTestBasic, givenEnqueueHandlerWhenCommandIsBlokingThenCom } HWTEST_F(EnqueueHandlerTestBasic, givenBlockedEnqueueHandlerWhenCommandIsBlokingThenCompletionStampTaskCountIsPassedToWaitForTaskCountAndCleanAllocationListAsRequiredTaskCount) { - auto mockCmdQ = setupFixtureAndCreateMockCommandQueue(); + auto mockCmdQ = setupFixtureAndCreateMockCommandQueue, FamilyType>(); MockKernelWithInternals kernelInternals(*device, context.get()); Kernel *kernel = kernelInternals.mockKernel; @@ -783,3 +783,93 @@ HWTEST_F(EnqueueHandlerTestBasic, givenBlockedEnqueueHandlerWhenCommandIsBloking t0.join(); } +template +class MockCommandQueueFailEnqueue : public MockCommandQueueHw { + public: + MockCommandQueueFailEnqueue(Context *context, + ClDevice *device, + cl_queue_properties *properties) : MockCommandQueueHw(context, device, properties) { + mockTagAllocator = std::make_unique>(0, device->getDevice().getMemoryManager()); + this->timestampPacketContainer = std::make_unique(); + this->deferredTimestampPackets = std::make_unique(); + } + CompletionStamp enqueueNonBlocked(Surface **surfacesForResidency, + size_t surfaceCount, + LinearStream &commandStream, + size_t commandStreamStart, + bool &blocking, + bool clearDependenciesForSubCapture, + const MultiDispatchInfo &multiDispatchInfo, + const EnqueueProperties &enqueueProperties, + TimestampPacketDependencies ×tampPacketDependencies, + EventsRequest &eventsRequest, + EventBuilder &eventBuilder, + TaskCountType taskLevel, + PrintfHandler *printfHandler, + bool relaxedOrderingEnabled, + uint32_t commandType) override { + this->timestampPacketContainer->add(mockTagAllocator->getTag()); + CompletionStamp stamp{}; + stamp.taskCount = taskCountToReturn; + return stamp; + } + TaskCountType taskCountToReturn = 0; + std::unique_ptr> mockTagAllocator; +}; +HWTEST_F(EnqueueHandlerTestBasic, givenEnqueueHandlerWhenEnqueueFailedThenTimestampPacketContainerIsEmpty) { + auto mockCmdQ = setupFixtureAndCreateMockCommandQueue, FamilyType>(); + + MockKernelWithInternals kernelInternals(*device, context.get()); + Kernel *kernel = kernelInternals.mockKernel; + MockMultiDispatchInfo multiDispatchInfo(device.get(), kernel); + mockCmdQ->taskCountToReturn = CompletionStamp::gpuHang; + mockCmdQ->template enqueueHandler(nullptr, + 0, + true, + multiDispatchInfo, + 0, + nullptr, + nullptr); + EXPECT_TRUE(mockCmdQ->timestampPacketContainer->peekNodes().empty()); + TimestampPacketContainer release; + mockCmdQ->deferredTimestampPackets->swapNodes(release); +} + +HWTEST_F(EnqueueHandlerTestBasic, givenEnqueueHandlerWhenEnqueueSucceedsThenTimestampPacketContainerIsNotEmpty) { + auto mockCmdQ = setupFixtureAndCreateMockCommandQueue, FamilyType>(); + + MockKernelWithInternals kernelInternals(*device, context.get()); + Kernel *kernel = kernelInternals.mockKernel; + MockMultiDispatchInfo multiDispatchInfo(device.get(), kernel); + mockCmdQ->taskCountToReturn = 100; + mockCmdQ->template enqueueHandler(nullptr, + 0, + true, + multiDispatchInfo, + 0, + nullptr, + nullptr); + EXPECT_FALSE(mockCmdQ->timestampPacketContainer->peekNodes().empty()); + TimestampPacketContainer release; + mockCmdQ->timestampPacketContainer->swapNodes(release); +} + +HWTEST_F(EnqueueHandlerTestBasic, givenEnqueueHandlerWhenEnqueueFailedButThereIsNoDeferredContainerThenTimestampPacketContainerIsNotEmpty) { + auto mockCmdQ = setupFixtureAndCreateMockCommandQueue, FamilyType>(); + + MockKernelWithInternals kernelInternals(*device, context.get()); + Kernel *kernel = kernelInternals.mockKernel; + MockMultiDispatchInfo multiDispatchInfo(device.get(), kernel); + mockCmdQ->taskCountToReturn = CompletionStamp::gpuHang; + mockCmdQ->deferredTimestampPackets.reset(); + mockCmdQ->template enqueueHandler(nullptr, + 0, + true, + multiDispatchInfo, + 0, + nullptr, + nullptr); + EXPECT_FALSE(mockCmdQ->timestampPacketContainer->peekNodes().empty()); + TimestampPacketContainer release; + mockCmdQ->timestampPacketContainer->swapNodes(release); +} \ No newline at end of file diff --git a/opencl/test/unit_test/mocks/mock_command_queue.h b/opencl/test/unit_test/mocks/mock_command_queue.h index a00a3b71a9..043ae220d6 100644 --- a/opencl/test/unit_test/mocks/mock_command_queue.h +++ b/opencl/test/unit_test/mocks/mock_command_queue.h @@ -30,6 +30,7 @@ class MockCommandQueue : public CommandQueue { using CommandQueue::blitEnqueueAllowed; using CommandQueue::blitEnqueueImageAllowed; using CommandQueue::bufferCpuCopyAllowed; + using CommandQueue::deferredTimestampPackets; using CommandQueue::device; using CommandQueue::gpgpuEngine; using CommandQueue::isCopyOnly;