Skip to content

Commit

Permalink
Making DSH and IOH always resident
Browse files Browse the repository at this point in the history
Change-Id: Ib114b92cb5ee153f213c15c935f8f1d1cfeb46eb
  • Loading branch information
andrzejkoska authored and Compute-Runtime-Automation committed Apr 13, 2018
1 parent d516cd6 commit b0a6d91
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
6 changes: 5 additions & 1 deletion runtime/command_stream/command_stream_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ void CommandStreamReceiver::processEviction() {
void CommandStreamReceiver::makeNonResident(GraphicsAllocation &gfxAllocation) {
if (gfxAllocation.residencyTaskCount != ObjectNotResident) {
makeCoherent(gfxAllocation);
getMemoryManager()->pushAllocationForEviction(&gfxAllocation);
if (gfxAllocation.peekEvictable()) {
getMemoryManager()->pushAllocationForEviction(&gfxAllocation);
} else {
gfxAllocation.setEvictable(true);
}
}

gfxAllocation.residencyTaskCount = ObjectNotResident;
Expand Down
2 changes: 2 additions & 0 deletions runtime/command_stream/command_stream_receiver_hw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
auto sshAllocation = ssh.getGraphicsAllocation();

this->makeResident(*dshAllocation);
dshAllocation->setEvictable(false);
this->makeResident(*iohAllocation);
this->makeResident(*sshAllocation);
iohAllocation->setEvictable(false);

this->makeResident(*tagAllocation);

Expand Down
4 changes: 4 additions & 0 deletions runtime/memory_manager/graphics_allocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
osHandle sharedHandle;
bool locked = false;
uint32_t reuseCount = 0; // GraphicsAllocation can be reused by shared resources
bool evictable = true;

public:
enum AllocationType {
Expand Down Expand Up @@ -126,6 +127,9 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {

int residencyTaskCount = ObjectNotResident;

void setEvictable(bool evictable) { this->evictable = evictable; }
bool peekEvictable() const { return evictable; }

bool isResident() const { return residencyTaskCount != ObjectNotResident; }
void setLocked(bool locked) { this->locked = locked; }
bool isLocked() const { return locked; }
Expand Down
23 changes: 23 additions & 0 deletions unit_tests/command_stream/command_stream_receiver_hw_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,29 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTaskIsSu
EXPECT_EQ(expectedUsedSize, commandStream.getUsed());
}

HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrWhenflushTaskThenDshAndIohNotEvictable) {
auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0]);
pDevice->resetCommandStreamReceiver(mockCsr);
DispatchFlags dispatchFlags;

mockCsr->flushTask(commandStream,
0,
dsh,
ioh,
ssh,
taskLevel,
dispatchFlags);

EXPECT_EQ(dsh.getGraphicsAllocation()->peekEvictable(), true);
EXPECT_EQ(ssh.getGraphicsAllocation()->peekEvictable(), true);
EXPECT_EQ(ioh.getGraphicsAllocation()->peekEvictable(), true);

dsh.getGraphicsAllocation()->setEvictable(false);
EXPECT_EQ(dsh.getGraphicsAllocation()->peekEvictable(), false);
dsh.getGraphicsAllocation()->setEvictable(true);
EXPECT_EQ(dsh.getGraphicsAllocation()->peekEvictable(), true);
}

HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndMidThreadPreemptionWhenFlushTaskIsCalledThenSipKernelIsMadeResident) {
auto mockCsr = new MockCsrHw2<FamilyType>(*platformDevices[0]);
pDevice->resetCommandStreamReceiver(mockCsr);
Expand Down
19 changes: 17 additions & 2 deletions unit_tests/os_interface/windows/device_command_stream_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,15 +668,21 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator);

auto commandBuffer = memManager->allocateGraphicsMemory(1024, 4096);
auto dshAlloc = memManager->allocateGraphicsMemory(1024, 4096);
auto iohAlloc = memManager->allocateGraphicsMemory(1024, 4096);
auto sshAlloc = memManager->allocateGraphicsMemory(1024, 4096);

mockCsr->setTagAllocation(tagAllocation);

LinearStream cs(commandBuffer);
LinearStream dsh(dshAlloc);
LinearStream ioh(iohAlloc);
LinearStream ssh(sshAlloc);

DispatchFlags dispatchFlags;
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.requiresCoherency = true;
mockCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags);
mockCsr->flushTask(cs, 0u, dsh, ioh, ssh, 0u, dispatchFlags);

auto &cmdBuffers = mockedSubmissionsAggregator->peekCommandBuffers();
auto storedCommandBuffer = cmdBuffers.peekHead();
Expand All @@ -692,11 +698,14 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
auto csrCommandStream = mockCsr->commandStream.getGraphicsAllocation();
EXPECT_EQ(reinterpret_cast<uint64_t>(csrCommandStream->getUnderlyingBuffer()), mockWddm->submitResult.commandBufferSubmitted);
EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)mockWddm->submitResult.commandHeaderSubmitted)->RequiresCoherency);
EXPECT_EQ(3u, mockWddm->makeResidentResult.handleCount);
EXPECT_EQ(6u, mockWddm->makeResidentResult.handleCount);

std::vector<D3DKMT_HANDLE> expectedHandles;
expectedHandles.push_back(((WddmAllocation *)tagAllocation)->handle);
expectedHandles.push_back(((WddmAllocation *)commandBuffer)->handle);
expectedHandles.push_back(((WddmAllocation *)dshAlloc)->handle);
expectedHandles.push_back(((WddmAllocation *)iohAlloc)->handle);
expectedHandles.push_back(((WddmAllocation *)sshAlloc)->handle);
expectedHandles.push_back(((WddmAllocation *)csrCommandStream)->handle);

for (auto i = 0u; i < mockWddm->makeResidentResult.handleCount; i++) {
Expand All @@ -712,8 +721,14 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt

EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)tagAllocation)->getTrimCandidateListPosition());
EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)commandBuffer)->getTrimCandidateListPosition());
EXPECT_EQ(trimListUnusedPosition, ((WddmAllocation *)dshAlloc)->getTrimCandidateListPosition());
EXPECT_EQ(trimListUnusedPosition, ((WddmAllocation *)iohAlloc)->getTrimCandidateListPosition());
EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)sshAlloc)->getTrimCandidateListPosition());
EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)csrCommandStream)->getTrimCandidateListPosition());

memManager->freeGraphicsMemory(dshAlloc);
memManager->freeGraphicsMemory(iohAlloc);
memManager->freeGraphicsMemory(sshAlloc);
memManager->freeGraphicsMemory(commandBuffer);
}

Expand Down

0 comments on commit b0a6d91

Please sign in to comment.