2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-03-21 19:58:30 +08:00
|
|
|
* Copyright (c) 2017 - 2018, Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
* 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"
|
2018-03-21 19:58:30 +08:00
|
|
|
#include "unit_tests/fixtures/enqueue_handler_fixture.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#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"
|
2018-03-14 18:07:51 +08:00
|
|
|
#include "unit_tests/helpers/debug_manager_state_restore.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
using namespace OCLRT;
|
|
|
|
|
|
|
|
HWTEST_F(EnqueueHandlerTest, enqueueHandlerWithKernelCallsProcessEvictionOnCSR) {
|
|
|
|
int32_t tag;
|
|
|
|
auto csr = new MockCsrBase<FamilyType>(tag);
|
|
|
|
pDevice->resetCommandStreamReceiver(csr);
|
|
|
|
|
|
|
|
MockKernelWithInternals mockKernel(*pDevice);
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(context, pDevice, 0));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
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<FamilyType>(tag);
|
|
|
|
pDevice->resetCommandStreamReceiver(csr);
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(context, pDevice, 0));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
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<FamilyType>(tag);
|
|
|
|
pDevice->resetCommandStreamReceiver(csr);
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(context, pDevice, 0));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// 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<FamilyType>(tag);
|
|
|
|
pDevice->resetCommandStreamReceiver(csr);
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(context, pDevice, 0));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// 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) {
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
MockKernelWithInternals kernelInternals(*pDevice, context);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
Kernel *kernel = kernelInternals.mockKernel;
|
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(kernel);
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = new MockCommandQueueHw<FamilyType>(context, pDevice, 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// put queue into initial blocked state
|
|
|
|
mockCmdQ->taskLevel = Event::eventNotReady;
|
|
|
|
|
|
|
|
auto initialRefCountInternal = mockCmdQ->getRefInternalCount();
|
|
|
|
|
|
|
|
bool blocking = false;
|
|
|
|
mockCmdQ->template enqueueHandler<CL_COMMAND_NDRANGE_KERNEL>(nullptr,
|
|
|
|
0,
|
|
|
|
blocking,
|
|
|
|
multiDispatchInfo,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_NE(nullptr, mockCmdQ->virtualEvent);
|
|
|
|
|
|
|
|
auto refCountInternal = mockCmdQ->getRefInternalCount();
|
|
|
|
EXPECT_EQ(initialRefCountInternal + 1, refCountInternal);
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
mockCmdQ->virtualEvent->setStatus(CL_COMPLETE);
|
|
|
|
mockCmdQ->isQueueBlocked();
|
2017-12-21 07:45:38 +08:00
|
|
|
mockCmdQ->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(EnqueueHandlerTest, enqueueBlockedSetsVirtualEventAsCurrentCmdQVirtualEvent) {
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
MockKernelWithInternals kernelInternals(*pDevice, context);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
Kernel *kernel = kernelInternals.mockKernel;
|
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(kernel);
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = new MockCommandQueueHw<FamilyType>(context, pDevice, 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// put queue into initial blocked state
|
|
|
|
mockCmdQ->taskLevel = Event::eventNotReady;
|
|
|
|
|
|
|
|
bool blocking = false;
|
|
|
|
mockCmdQ->template enqueueHandler<CL_COMMAND_NDRANGE_KERNEL>(nullptr,
|
|
|
|
0,
|
|
|
|
blocking,
|
|
|
|
multiDispatchInfo,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, mockCmdQ->virtualEvent);
|
|
|
|
|
|
|
|
EXPECT_TRUE(mockCmdQ->virtualEvent->isCurrentCmdQVirtualEvent());
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
mockCmdQ->virtualEvent->setStatus(CL_COMPLETE);
|
|
|
|
mockCmdQ->isQueueBlocked();
|
2017-12-21 07:45:38 +08:00
|
|
|
mockCmdQ->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(EnqueueHandlerTest, enqueueBlockedUnsetsCurrentCmdQVirtualEventForPreviousVirtualEvent) {
|
|
|
|
|
|
|
|
UserEvent userEvent;
|
|
|
|
cl_event clUserEvent = &userEvent;
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
MockKernelWithInternals kernelInternals(*pDevice, context);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
Kernel *kernel = kernelInternals.mockKernel;
|
|
|
|
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(kernel);
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = new MockCommandQueueHw<FamilyType>(context, pDevice, 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// put queue into initial blocked state with userEvent
|
|
|
|
|
|
|
|
bool blocking = false;
|
|
|
|
mockCmdQ->template enqueueHandler<CL_COMMAND_NDRANGE_KERNEL>(nullptr,
|
|
|
|
0,
|
|
|
|
blocking,
|
|
|
|
multiDispatchInfo,
|
|
|
|
1,
|
|
|
|
&clUserEvent,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, mockCmdQ->virtualEvent);
|
|
|
|
Event *previousVirtualEvent = mockCmdQ->virtualEvent;
|
|
|
|
|
|
|
|
mockCmdQ->template enqueueHandler<CL_COMMAND_NDRANGE_KERNEL>(nullptr,
|
|
|
|
0,
|
|
|
|
blocking,
|
|
|
|
multiDispatchInfo,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
|
|
|
|
|
|
|
EXPECT_FALSE(previousVirtualEvent->isCurrentCmdQVirtualEvent());
|
|
|
|
EXPECT_TRUE(mockCmdQ->virtualEvent->isCurrentCmdQVirtualEvent());
|
|
|
|
|
|
|
|
mockCmdQ->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(EnqueueHandlerTest, enqueueWithOutputEventRegistersEvent) {
|
2018-01-05 18:33:30 +08:00
|
|
|
MockKernelWithInternals kernelInternals(*pDevice, context);
|
2017-12-21 07:45:38 +08:00
|
|
|
Kernel *kernel = kernelInternals.mockKernel;
|
|
|
|
MockMultiDispatchInfo multiDispatchInfo(kernel);
|
|
|
|
cl_event outputEvent = nullptr;
|
|
|
|
|
2018-01-05 18:33:30 +08:00
|
|
|
auto mockCmdQ = new MockCommandQueueHw<FamilyType>(context, pDevice, 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
bool blocking = false;
|
|
|
|
mockCmdQ->template enqueueHandler<CL_COMMAND_NDRANGE_KERNEL>(nullptr,
|
|
|
|
0,
|
|
|
|
blocking,
|
|
|
|
multiDispatchInfo,
|
|
|
|
0,
|
|
|
|
nullptr,
|
|
|
|
&outputEvent);
|
|
|
|
ASSERT_NE(nullptr, outputEvent);
|
|
|
|
Event *event = castToObjectOrAbort<Event>(outputEvent);
|
|
|
|
ASSERT_NE(nullptr, event);
|
|
|
|
|
|
|
|
event->release();
|
|
|
|
mockCmdQ->release();
|
|
|
|
}
|
2018-03-14 18:07:51 +08:00
|
|
|
|
|
|
|
HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDumpIsNotSetThenPatchInfoDataIsNotTransferredToCSR) {
|
|
|
|
int32_t tag;
|
|
|
|
auto csr = new MockCsrBase<FamilyType>(tag);
|
|
|
|
pDevice->resetCommandStreamReceiver(csr);
|
|
|
|
|
|
|
|
MockKernelWithInternals mockKernel(*pDevice);
|
|
|
|
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(context, pDevice, 0));
|
|
|
|
|
|
|
|
size_t gws[] = {1, 1, 1};
|
|
|
|
|
|
|
|
PatchInfoData patchInfoData = {0xaaaaaaaa, 0, PatchInfoAllocationType::KernelArg, 0xbbbbbbbb, 0, PatchInfoAllocationType::IndirectObjectHeap};
|
|
|
|
mockKernel.mockKernel->getPatchInfoDataList().push_back(patchInfoData);
|
|
|
|
|
|
|
|
EXPECT_CALL(*csr, setPatchInfoData(::testing::_)).Times(0);
|
|
|
|
mockCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDumpIsSetThenPatchInfoDataIsTransferredToCSR) {
|
|
|
|
DebugManagerStateRestore dbgRestore;
|
|
|
|
DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true);
|
|
|
|
|
|
|
|
int32_t tag;
|
|
|
|
auto csr = new MockCsrBase<FamilyType>(tag);
|
|
|
|
pDevice->resetCommandStreamReceiver(csr);
|
|
|
|
|
|
|
|
MockKernelWithInternals mockKernel(*pDevice);
|
|
|
|
auto mockCmdQ = std::unique_ptr<MockCommandQueueHw<FamilyType>>(new MockCommandQueueHw<FamilyType>(context, pDevice, 0));
|
|
|
|
|
|
|
|
size_t gws[] = {1, 1, 1};
|
|
|
|
|
|
|
|
PatchInfoData patchInfoData = {0xaaaaaaaa, 0, PatchInfoAllocationType::KernelArg, 0xbbbbbbbb, 0, PatchInfoAllocationType::IndirectObjectHeap};
|
|
|
|
mockKernel.mockKernel->getPatchInfoDataList().push_back(patchInfoData);
|
|
|
|
|
|
|
|
EXPECT_CALL(*csr, setPatchInfoData(::testing::_)).Times(6);
|
|
|
|
mockCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
}
|