/* * Copyright (c) 2017, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ #include "runtime/event/event.h" #include "runtime/memory_manager/surface.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/mocks/mock_command_queue.h" #include "unit_tests/mocks/mock_csr.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_kernel.h" #include "unit_tests/mocks/mock_mdi.h" #include "test.h" using namespace OCLRT; class EnqueueHandlerTest : public DeviceFixture, public testing::Test { public: void SetUp() override { DeviceFixture::SetUp(); } void TearDown() override { DeviceFixture::TearDown(); } MockContext context; }; HWTEST_F(EnqueueHandlerTest, enqueueHandlerWithKernelCallsProcessEvictionOnCSR) { int32_t tag; auto csr = new MockCsrBase(tag); pDevice->resetCommandStreamReceiver(csr); MockKernelWithInternals mockKernel(*pDevice); auto mockCmdQ = std::unique_ptr>(new MockCommandQueueHw(&context, pDevice, 0)); size_t gws[] = {1, 1, 1}; mockCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); EXPECT_TRUE(csr->processEvictionCalled); } HWTEST_F(EnqueueHandlerTest, enqueueHandlerCallOnEnqueueMarkerDoesntCallProcessEvictionOnCSR) { int32_t tag; auto csr = new MockCsrBase(tag); pDevice->resetCommandStreamReceiver(csr); auto mockCmdQ = std::unique_ptr>(new MockCommandQueueHw(&context, pDevice, 0)); mockCmdQ->enqueueMarkerWithWaitList( 0, nullptr, nullptr); EXPECT_FALSE(csr->processEvictionCalled); EXPECT_EQ(0u, csr->madeResidentGfxAllocations.size()); EXPECT_EQ(0u, csr->madeNonResidentGfxAllocations.size()); } HWTEST_F(EnqueueHandlerTest, enqueueHandlerForMarkerOnUnblockedQueueDoesntIncrementTaskLevel) { int32_t tag; auto csr = new MockCsrBase(tag); pDevice->resetCommandStreamReceiver(csr); auto mockCmdQ = std::unique_ptr>(new MockCommandQueueHw(&context, pDevice, 0)); // put queue into initial unblocked state mockCmdQ->taskLevel = 0; mockCmdQ->enqueueMarkerWithWaitList( 0, nullptr, nullptr); EXPECT_EQ(0u, mockCmdQ->taskLevel); } HWTEST_F(EnqueueHandlerTest, enqueueHandlerForMarkerOnBlockedQueueShouldNotIncrementTaskLevel) { int32_t tag; auto csr = new MockCsrBase(tag); pDevice->resetCommandStreamReceiver(csr); auto mockCmdQ = std::unique_ptr>(new MockCommandQueueHw(&context, pDevice, 0)); // put queue into initial blocked state mockCmdQ->taskLevel = Event::eventNotReady; mockCmdQ->enqueueMarkerWithWaitList( 0, nullptr, nullptr); EXPECT_EQ(Event::eventNotReady, mockCmdQ->taskLevel); } HWTEST_F(EnqueueHandlerTest, enqueueBlockedWithoutReturnEventCreatesVirtualEventAndIncremetsCommandQueueInternalRefCount) { MockKernelWithInternals kernelInternals(*pDevice, &context); Kernel *kernel = kernelInternals.mockKernel; MockMultiDispatchInfo multiDispatchInfo(kernel); auto mockCmdQ = new MockCommandQueueHw(&context, pDevice, 0); // put queue into initial blocked state mockCmdQ->taskLevel = Event::eventNotReady; auto initialRefCountInternal = mockCmdQ->getRefInternalCount(); bool blocking = false; mockCmdQ->template enqueueHandler(nullptr, 0, blocking, multiDispatchInfo, 0, nullptr, nullptr); EXPECT_NE(nullptr, mockCmdQ->virtualEvent); auto refCountInternal = mockCmdQ->getRefInternalCount(); EXPECT_EQ(initialRefCountInternal + 1, refCountInternal); mockCmdQ->decRefInternal(); mockCmdQ->release(); } HWTEST_F(EnqueueHandlerTest, enqueueBlockedSetsVirtualEventAsCurrentCmdQVirtualEvent) { MockKernelWithInternals kernelInternals(*pDevice, &context); Kernel *kernel = kernelInternals.mockKernel; MockMultiDispatchInfo multiDispatchInfo(kernel); auto mockCmdQ = new MockCommandQueueHw(&context, pDevice, 0); // put queue into initial blocked state mockCmdQ->taskLevel = Event::eventNotReady; bool blocking = false; mockCmdQ->template enqueueHandler(nullptr, 0, blocking, multiDispatchInfo, 0, nullptr, nullptr); ASSERT_NE(nullptr, mockCmdQ->virtualEvent); EXPECT_TRUE(mockCmdQ->virtualEvent->isCurrentCmdQVirtualEvent()); mockCmdQ->decRefInternal(); mockCmdQ->release(); } HWTEST_F(EnqueueHandlerTest, enqueueBlockedUnsetsCurrentCmdQVirtualEventForPreviousVirtualEvent) { UserEvent userEvent; cl_event clUserEvent = &userEvent; MockKernelWithInternals kernelInternals(*pDevice, &context); Kernel *kernel = kernelInternals.mockKernel; MockMultiDispatchInfo multiDispatchInfo(kernel); auto mockCmdQ = new MockCommandQueueHw(&context, pDevice, 0); // put queue into initial blocked state with userEvent bool blocking = false; mockCmdQ->template enqueueHandler(nullptr, 0, blocking, multiDispatchInfo, 1, &clUserEvent, nullptr); ASSERT_NE(nullptr, mockCmdQ->virtualEvent); Event *previousVirtualEvent = mockCmdQ->virtualEvent; mockCmdQ->template enqueueHandler(nullptr, 0, blocking, multiDispatchInfo, 0, nullptr, nullptr); EXPECT_FALSE(previousVirtualEvent->isCurrentCmdQVirtualEvent()); EXPECT_TRUE(mockCmdQ->virtualEvent->isCurrentCmdQVirtualEvent()); mockCmdQ->release(); } HWTEST_F(EnqueueHandlerTest, blockedEnqueueRegistersEvent) { UserEvent userEvent; cl_event clUserEvent = &userEvent; MockKernelWithInternals kernelInternals(*pDevice, &context); Kernel *kernel = kernelInternals.mockKernel; MockMultiDispatchInfo multiDispatchInfo(kernel); cl_event outputEvent = nullptr; auto mockCmdQ = new MockCommandQueueHw(&context, pDevice, 0); bool blocking = false; mockCmdQ->template enqueueHandler(nullptr, 0, blocking, multiDispatchInfo, 1, &clUserEvent, &outputEvent); ASSERT_NE(nullptr, outputEvent); Event *event = castToObjectOrAbort(outputEvent); ASSERT_NE(nullptr, event); ASSERT_NE(nullptr, mockCmdQ->virtualEvent); EXPECT_EQ(event, mockCmdQ->virtualEvent); Event *head = context.getEventsRegistry().peekHead(); EXPECT_EQ(head, mockCmdQ->virtualEvent); event->release(); mockCmdQ->release(); } HWTEST_F(EnqueueHandlerTest, enqueueWithOutputEventRegistersEvent) { MockKernelWithInternals kernelInternals(*pDevice, &context); Kernel *kernel = kernelInternals.mockKernel; MockMultiDispatchInfo multiDispatchInfo(kernel); cl_event outputEvent = nullptr; auto mockCmdQ = new MockCommandQueueHw(&context, pDevice, 0); bool blocking = false; mockCmdQ->template enqueueHandler(nullptr, 0, blocking, multiDispatchInfo, 0, nullptr, &outputEvent); ASSERT_NE(nullptr, outputEvent); Event *event = castToObjectOrAbort(outputEvent); ASSERT_NE(nullptr, event); Event *head = context.getEventsRegistry().peekHead(); EXPECT_EQ(head, event); event->release(); mockCmdQ->release(); }