Move stamps allocators from memory manager to CSR.

Change-Id: Ib399e462cdddad89fcc470df4c4f0f5e4591a6b2
This commit is contained in:
Piotr Fusik
2018-11-27 13:07:41 +01:00
committed by sys_ocldev
parent 2d77b86e70
commit 87bb6afa56
20 changed files with 159 additions and 228 deletions

View File

@@ -59,9 +59,9 @@ struct TimestampPacketSimpleTests : public ::testing::Test {
public:
using TimestampPacketContainer::timestampPacketNodes;
MockTimestampPacketContainer(MemoryManager *memoryManager, size_t numberOfPreallocatedTags) : TimestampPacketContainer(memoryManager) {
MockTimestampPacketContainer(TagAllocator<TimestampPacket> &tagAllocator, size_t numberOfPreallocatedTags) {
for (size_t i = 0; i < numberOfPreallocatedTags; i++) {
add(memoryManager->obtainTimestampPacketAllocator(3)->getTag());
add(tagAllocator.getTag());
}
}
@@ -205,27 +205,9 @@ TEST_F(TimestampPacketSimpleTests, whenAskedForStampAddressThenReturnWithValidOf
}
}
HWTEST_F(TimestampPacketTests, asd) {
class MyMockMemoryManager : public OsAgnosticMemoryManager {
public:
MyMockMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){};
TagAllocator<TimestampPacket> *obtainTimestampPacketAllocator(size_t poolSize) override {
requestedPoolSize = poolSize;
return OsAgnosticMemoryManager::obtainTimestampPacketAllocator(poolSize);
}
size_t requestedPoolSize = 0;
};
auto myMockMemoryManager = new MyMockMemoryManager(executionEnvironment);
device->injectMemoryManager(myMockMemoryManager);
context->setMemoryManager(myMockMemoryManager);
TimestampPacketContainer previousNodes(device->getMemoryManager());
mockCmdQ->timestampPacketContainer = std::make_unique<MockTimestampPacketContainer>(myMockMemoryManager, 0);
mockCmdQ->obtainNewTimestampPacketNodes(1, previousNodes);
EXPECT_EQ(device->getUltCommandStreamReceiver<FamilyType>().getPreferredTagPoolSize(), myMockMemoryManager->requestedPoolSize);
HWTEST_F(TimestampPacketTests, givenCommandStreamReceiverHwWhenObtainingPreferredTagPoolSizeThenReturnCorrectValue) {
CommandStreamReceiverHw<FamilyType> csr(*platformDevices[0], executionEnvironment);
EXPECT_EQ(512u, csr.getPreferredTagPoolSize());
}
HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEstimatingStreamSizeThenAddPipeControl) {
@@ -289,7 +271,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEstimatingStr
HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWhenDispatchingGpuWalkerThenAddTwoPcForLastWalker) {
using GPGPU_WALKER = typename FamilyType::GPGPU_WALKER;
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
MockTimestampPacketContainer timestampPacket(device->getMemoryManager(), 2);
MockTimestampPacketContainer timestampPacket(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 2);
MockKernelWithInternals kernel2(*device);
@@ -335,7 +317,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWhenDispat
}
HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketDisabledWhenDispatchingGpuWalkerThenDontAddPipeControls) {
MockTimestampPacketContainer timestampPacket(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestampPacket(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockMultiDispatchInfo multiDispatchInfo(kernel->mockKernel);
auto &cmdStream = mockCmdQ->getCS(0);
@@ -362,12 +344,13 @@ HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketDisabledWh
}
HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThenObtainNewStampAndPassToEvent) {
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketWriteEnabled = true;
auto mockMemoryManager = new MockMemoryManager(*device->getExecutionEnvironment());
device->injectMemoryManager(mockMemoryManager);
context->setMemoryManager(mockMemoryManager);
auto mockTagAllocator = new MockTagAllocator<>(mockMemoryManager);
mockMemoryManager->timestampPacketAllocator.reset(mockTagAllocator);
csr.timestampPacketAllocator.reset(mockTagAllocator);
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
cl_event event1, event2;
@@ -464,10 +447,10 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThe
auto cmdQ2 = std::make_unique<MockCommandQueueHw<FamilyType>>(&context2, device2.get(), nullptr);
const cl_uint eventsOnWaitlist = 6;
MockTimestampPacketContainer timestamp3(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp4(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp5(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp6(device->getMemoryManager(), 2);
MockTimestampPacketContainer timestamp3(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockTimestampPacketContainer timestamp4(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockTimestampPacketContainer timestamp5(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockTimestampPacketContainer timestamp6(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 2);
UserEvent event1;
event1.setStatus(CL_COMPLETE);
@@ -517,8 +500,8 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingBlo
auto cmdQ1 = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
auto cmdQ2 = std::make_unique<MockCommandQueueHw<FamilyType>>(&context2, device2.get(), nullptr);
MockTimestampPacketContainer timestamp0(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp1(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp0(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockTimestampPacketContainer timestamp1(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
UserEvent userEvent;
Event event0(cmdQ1.get(), 0, 0, 0);
@@ -561,10 +544,10 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenDispatchingTh
auto &cmdStream = mockCmdQ->getCS(0);
const cl_uint eventsOnWaitlist = 6;
MockTimestampPacketContainer timestamp3(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp4(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp5(device->getMemoryManager(), 2);
MockTimestampPacketContainer timestamp6(device->getMemoryManager(), 1);
MockTimestampPacketContainer timestamp3(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockTimestampPacketContainer timestamp4(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockTimestampPacketContainer timestamp5(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 2);
MockTimestampPacketContainer timestamp6(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
UserEvent event1;
UserEvent event2;
@@ -630,16 +613,16 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingNonBlockedT
device->injectMemoryManager(mockMemoryManager);
context->setMemoryManager(mockMemoryManager);
auto mockTagAllocator = new MockTagAllocator<>(mockMemoryManager, 1);
mockMemoryManager->timestampPacketAllocator.reset(mockTagAllocator);
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketAllocator.reset(mockTagAllocator);
csr.timestampPacketWriteEnabled = true;
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
TimestampPacketContainer previousNodes(device->getMemoryManager());
TimestampPacketContainer previousNodes;
cmdQ->obtainNewTimestampPacketNodes(1, previousNodes);
auto firstNode = cmdQ->timestampPacketContainer->peekNodes().at(0);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.storeMakeResidentAllocations = true;
csr.timestampPacketWriteEnabled = true;
@@ -655,16 +638,16 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingBlockedThen
device->injectMemoryManager(mockMemoryManager);
context->setMemoryManager(mockMemoryManager);
auto mockTagAllocator = new MockTagAllocator<>(mockMemoryManager, 1);
mockMemoryManager->timestampPacketAllocator.reset(mockTagAllocator);
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.timestampPacketAllocator.reset(mockTagAllocator);
csr.timestampPacketWriteEnabled = true;
auto cmdQ = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
TimestampPacketContainer previousNodes(device->getMemoryManager());
TimestampPacketContainer previousNodes;
cmdQ->obtainNewTimestampPacketNodes(1, previousNodes);
auto firstNode = cmdQ->timestampPacketContainer->peekNodes().at(0);
auto &csr = device->getUltCommandStreamReceiver<FamilyType>();
csr.storeMakeResidentAllocations = true;
csr.timestampPacketWriteEnabled = true;
@@ -683,7 +666,7 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingThenDontKee
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
MockCommandQueueHw<FamilyType> cmdQ(context.get(), device.get(), nullptr);
TimestampPacketContainer previousNodes(device->getMemoryManager());
TimestampPacketContainer previousNodes;
cmdQ.obtainNewTimestampPacketNodes(1, previousNodes);
auto firstNode = cmdQ.timestampPacketContainer->peekNodes().at(0);
setTagToReadyState(firstNode->tag);
@@ -711,10 +694,10 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingThenKeepDep
using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
using MI_ATOMIC = typename FamilyType::MI_ATOMIC;
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
MockTimestampPacketContainer firstNode(device->getMemoryManager(), 0);
MockTimestampPacketContainer firstNode(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 0);
MockCommandQueueHw<FamilyType> cmdQ(context.get(), device.get(), nullptr);
TimestampPacketContainer previousNodes(device->getMemoryManager());
TimestampPacketContainer previousNodes;
cmdQ.obtainNewTimestampPacketNodes(2, previousNodes);
firstNode.add(cmdQ.timestampPacketContainer->peekNodes().at(0));
firstNode.add(cmdQ.timestampPacketContainer->peekNodes().at(1));
@@ -747,7 +730,7 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingToOoqThenDo
cl_queue_properties properties[] = {CL_QUEUE_PROPERTIES, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, 0};
MockCommandQueueHw<FamilyType> cmdQ(context.get(), device.get(), properties);
TimestampPacketContainer previousNodes(device->getMemoryManager());
TimestampPacketContainer previousNodes;
cmdQ.obtainNewTimestampPacketNodes(1, previousNodes);
cmdQ.enqueueKernel(kernel->mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
@@ -773,19 +756,17 @@ HWTEST_F(TimestampPacketTests, givenEventsWaitlistFromDifferentDevicesWhenEnqueu
TagAllocator<TimestampPacket> tagAllocator(executionEnvironment.memoryManager.get(), 1, 1);
auto device2 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(nullptr, &executionEnvironment, 1u));
device->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
device2->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
auto &ultCsr = device->getUltCommandStreamReceiver<FamilyType>();
ultCsr.timestampPacketWriteEnabled = true;
ultCsr.storeMakeResidentAllocations = true;
device2->getUltCommandStreamReceiver<FamilyType>().timestampPacketWriteEnabled = true;
MockContext context2(device2.get());
auto cmdQ1 = std::make_unique<MockCommandQueueHw<FamilyType>>(context.get(), device.get(), nullptr);
auto cmdQ2 = std::make_unique<MockCommandQueueHw<FamilyType>>(&context2, device2.get(), nullptr);
MockTimestampPacketContainer node1(device->getMemoryManager(), 0);
MockTimestampPacketContainer node2(device->getMemoryManager(), 0);
MockTimestampPacketContainer node1(*ultCsr.getTimestampPacketAllocator(), 0);
MockTimestampPacketContainer node2(*ultCsr.getTimestampPacketAllocator(), 0);
auto tagNode1 = tagAllocator.getTag();
node1.add(tagNode1);
@@ -842,10 +823,10 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWhenEnqueueingBlockedThenMake
TEST_F(TimestampPacketTests, givenDispatchSizeWhenAskingForNewTimestampsThenObtainEnoughTags) {
size_t dispatchSize = 3;
mockCmdQ->timestampPacketContainer = std::make_unique<MockTimestampPacketContainer>(device->getMemoryManager(), 0);
mockCmdQ->timestampPacketContainer = std::make_unique<MockTimestampPacketContainer>(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 0);
EXPECT_EQ(0u, mockCmdQ->timestampPacketContainer->peekNodes().size());
TimestampPacketContainer previousNodes(device->getMemoryManager());
TimestampPacketContainer previousNodes;
mockCmdQ->obtainNewTimestampPacketNodes(dispatchSize, previousNodes);
EXPECT_EQ(dispatchSize, mockCmdQ->timestampPacketContainer->peekNodes().size());
}
@@ -858,11 +839,11 @@ HWTEST_F(TimestampPacketTests, givenWaitlistAndOutputEventWhenEnqueueingWithoutK
MockKernelWithInternals mockKernel(*device, context.get());
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); // obtain first TimestampPacket
TimestampPacketContainer cmdQNodes(device->getMemoryManager());
TimestampPacketContainer cmdQNodes;
cmdQNodes.assignAndIncrementNodesRefCounts(*cmdQ.timestampPacketContainer);
MockTimestampPacketContainer node1(device->getMemoryManager(), 1);
MockTimestampPacketContainer node2(device->getMemoryManager(), 1);
MockTimestampPacketContainer node1(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
MockTimestampPacketContainer node2(*device->getCommandStreamReceiver().getTimestampPacketAllocator(), 1);
Event event0(&cmdQ, 0, 0, 0);
event0.addTimestampPacketNodes(node1);
@@ -911,7 +892,7 @@ HWTEST_F(TimestampPacketTests, whenEnqueueingBarrierThenRequestPipeControlOnCsrF
MockKernelWithInternals mockKernel(*device, context.get());
cmdQ.enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr); // obtain first TimestampPacket
TimestampPacketContainer cmdQNodes(device->getMemoryManager());
TimestampPacketContainer cmdQNodes;
cmdQNodes.assignAndIncrementNodesRefCounts(*cmdQ.timestampPacketContainer);
cmdQ.enqueueBarrierWithWaitList(0, nullptr, nullptr);