compute-runtime/opencl/test/unit_test/helpers/timestamp_packet_2_tests.cpp

205 lines
9.2 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/test/common/cmd_parse/hw_parse.h"
#include "shared/test/unit_test/utilities/base_object_utils.h"
#include "opencl/source/event/user_event.h"
#include "opencl/test/unit_test/helpers/timestamp_packet_tests.h"
#include "opencl/test/unit_test/mocks/mock_timestamp_container.h"
using namespace NEO;
HWTEST_F(TimestampPacketTests, givenEmptyWaitlistAndNoOutputEventWhenEnqueueingMarkerThenDoNothing) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(context, device.get(), nullptr));
cmdQ->enqueueMarkerWithWaitList(0, nullptr, nullptr);
EXPECT_EQ(0u, cmdQ->timestampPacketContainer->peekNodes().size());
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenEmptyWaitlistAndEventWhenEnqueueingMarkerWithProfilingEnabledThenObtainNewNode) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto cmdQ = clUniquePtr(new MockCommandQueueHw<FamilyType>(context, device.get(), nullptr));
cmdQ->setProfilingEnabled();
cl_event event;
cmdQ->enqueueMarkerWithWaitList(0, nullptr, &event);
EXPECT_EQ(1u, cmdQ->timestampPacketContainer->peekNodes().size());
clReleaseEvent(event);
}
HWTEST_F(TimestampPacketTests, whenEnqueueingBarrierThenRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
MockKernelWithInternals mockKernel(*device, context);
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); // obtain first TimestampPackets<uint32_t>
TimestampPacketContainer cmdQNodes;
cmdQNodes.assignAndIncrementNodesRefCounts(*cmdQ.timestampPacketContainer);
cmdQ.enqueueBarrierWithWaitList(0, nullptr, nullptr);
EXPECT_EQ(cmdQ.timestampPacketContainer->peekNodes().at(0), cmdQNodes.peekNodes().at(0)); // dont obtain new node
EXPECT_EQ(1u, cmdQ.timestampPacketContainer->peekNodes().size());
EXPECT_TRUE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteDisabledWhenEnqueueingBarrierThenDontRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = false;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
cmdQ.enqueueBarrierWithWaitList(0, nullptr, nullptr);
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
}
HWTEST_F(TimestampPacketTests, givenBlockedQueueWhenEnqueueingBarrierThenRequestPipeControlOnCsrFlush) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
auto userEvent = make_releaseable<UserEvent>();
cl_event waitlist[] = {userEvent.get()};
cmdQ.enqueueBarrierWithWaitList(1, waitlist, nullptr);
EXPECT_TRUE(csr.stallingPipeControlOnNextFlushRequired);
userEvent->setStatus(CL_COMPLETE);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWhenEstimatingCsrStreamSizeThenAddSizeForPipeControl) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
csr.stallingPipeControlOnNextFlushRequired = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.stallingPipeControlOnNextFlushRequired = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + sizeof(typename FamilyType::PIPE_CONTROL);
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWithBarrierWriteWhenEstimatingCsrStreamSizeThenAddSizeForPipeControlForWrite) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
TimestampPacketContainer barrierTimestampPacketNode;
barrierTimestampPacketNode.add(csr.getTimestampPacketAllocator()->getTag());
flags.barrierTimestampPacketNodes = &barrierTimestampPacketNode;
csr.stallingPipeControlOnNextFlushRequired = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.stallingPipeControlOnNextFlushRequired = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + MemorySynchronizationCommands<FamilyType>::getSizeForPipeControlWithPostSyncOperation(device->getHardwareInfo());
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenInstructionCacheRequesWhenSizeIsEstimatedThenPipeControlIsAdded) {
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
csr.requiresInstructionCacheFlush = false;
auto sizeWithoutPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
csr.requiresInstructionCacheFlush = true;
auto sizeWithPcRequest = device->getUltCommandStreamReceiver<FamilyType>().getRequiredCmdStreamSize(flags, device->getDevice());
size_t extendedSize = sizeWithoutPcRequest + sizeof(typename FamilyType::PIPE_CONTROL);
EXPECT_EQ(sizeWithPcRequest, extendedSize);
}
HWTEST_F(TimestampPacketTests, givenPipeControlRequestWhenFlushingThenProgramPipeControlAndResetRequestFlag) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.stallingPipeControlOnNextFlushRequired = true;
csr.timestampPacketWriteEnabled = true;
MockCommandQueueHw<FamilyType> cmdQ(context, device.get(), nullptr);
MockKernelWithInternals mockKernel(*device, context);
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_FALSE(csr.stallingPipeControlOnNextFlushRequired);
HardwareParse hwParser;
hwParser.parseCommands<FamilyType>(csr.commandStream, 0);
auto secondEnqueueOffset = csr.commandStream.getUsed();
auto pipeControl = genCmdCast<typename FamilyType::PIPE_CONTROL *>(*hwParser.cmdList.begin());
EXPECT_NE(nullptr, pipeControl);
EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_NO_WRITE, pipeControl->getPostSyncOperation());
EXPECT_TRUE(pipeControl->getCommandStreamerStallEnable());
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
EXPECT_EQ(secondEnqueueOffset, csr.commandStream.getUsed()); // nothing programmed when flag is not set
}
HWTEST_F(TimestampPacketTests, givenKernelWhichDoesntRequireFlushWhenEnqueueingKernelThenOneNodeIsCreated) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableCacheFlushAfterWalker.set(false);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto mockTagAllocator = new MockTagAllocator<>(device->getRootDeviceIndex(), executionEnvironment->memoryManager.get());
csr.timestampPacketAllocator.reset(mockTagAllocator);
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, device.get(), nullptr);
// obtain first node for cmdQ and event1
cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto size = cmdQ->timestampPacketContainer->peekNodes().size();
EXPECT_EQ(size, 1u);
}
HWTEST_F(TimestampPacketTests, givenKernelWhichRequiresFlushWhenEnqueueingKernelThenTwoNodesAreCreated) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.EnableCacheFlushAfterWalker.set(true);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto mockTagAllocator = new MockTagAllocator<>(device->getRootDeviceIndex(), executionEnvironment->memoryManager.get());
csr.timestampPacketAllocator.reset(mockTagAllocator);
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context, device.get(), nullptr);
kernel->mockKernel->svmAllocationsRequireCacheFlush = true;
// obtain first node for cmdQ and event1
cmdQ->enqueueKernel(kernel->mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
auto node1 = cmdQ->timestampPacketContainer->peekNodes().at(0);
auto node2 = cmdQ->timestampPacketContainer->peekNodes().at(1);
auto size = cmdQ->timestampPacketContainer->peekNodes().size();
EXPECT_EQ(size, 2u);
EXPECT_NE(nullptr, node1);
EXPECT_NE(nullptr, node2);
EXPECT_NE(node1, node2);
}