Skip to content

Commit a3ad3b9

Browse files
Clean temporary allocations after Blit operation
Change-Id: I5c9b6778c93c7422bb84ee367dbf298df5e06cab Related-To: NEO-3020 Signed-off-by: Dunajski, Bartosz <[email protected]>
1 parent cc6a94b commit a3ad3b9

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

runtime/command_stream/command_stream_receiver_hw.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ void CommandStreamReceiverHw<GfxFamily>::blitFromHostPtr(MemObj &destinationMemO
829829

830830
lock.unlock();
831831
waitForTaskCountWithKmdNotifyFallback(newTaskCount, flushStampToWait, false, false);
832+
internalAllocationStorage->cleanAllocationList(newTaskCount, TEMPORARY_ALLOCATION);
832833
}
833834

834835
} // namespace NEO

unit_tests/command_stream/command_stream_receiver_hw_tests.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "unit_tests/mocks/mock_context.h"
3939
#include "unit_tests/mocks/mock_csr.h"
4040
#include "unit_tests/mocks/mock_event.h"
41+
#include "unit_tests/mocks/mock_internal_allocation_storage.h"
4142
#include "unit_tests/mocks/mock_kernel.h"
4243
#include "unit_tests/mocks/mock_submissions_aggregator.h"
4344
#include "unit_tests/utilities/base_object_utils.h"
@@ -379,14 +380,7 @@ HWTEST_F(BcsTests, givenInputAllocationsWhenBlitDispatchedThenMakeAllAllocations
379380
EXPECT_TRUE(csr.isMadeResident(csr.getTagAllocation()));
380381
EXPECT_EQ(1u, csr.makeSurfacePackNonResidentCalled);
381382

382-
bool hostPtrAllocationFound = false;
383-
for (auto &allocation : csr.makeResidentAllocations) {
384-
if (allocation.first->getUnderlyingBuffer() == hostPtr) {
385-
hostPtrAllocationFound = true;
386-
break;
387-
}
388-
}
389-
EXPECT_TRUE(hostPtrAllocationFound);
383+
EXPECT_EQ(4u, csr.makeResidentAllocations.size());
390384
}
391385

392386
HWTEST_F(BcsTests, givenBufferWhenBlitCalledThenFlushCommandBuffer) {
@@ -456,3 +450,22 @@ HWTEST_F(BcsTests, whenBlitFromHostPtrCalledThenCallWaitWithKmdFallback) {
456450
EXPECT_FALSE(myMockCsr->useQuickKmdSleepPassed);
457451
EXPECT_FALSE(myMockCsr->forcePowerSavingModePassed);
458452
}
453+
454+
HWTEST_F(BcsTests, whenBlitFromHostPtrCalledThenCleanTemporaryAllocations) {
455+
auto &bcsCsr = pDevice->getUltCommandStreamReceiver<FamilyType>();
456+
auto mockInternalAllocationsStorage = new MockInternalAllocationStorage(bcsCsr);
457+
bcsCsr.internalAllocationStorage.reset(mockInternalAllocationsStorage);
458+
459+
cl_int retVal = CL_SUCCESS;
460+
auto buffer = clUniquePtr<Buffer>(Buffer::create(context.get(), CL_MEM_READ_WRITE, 1, nullptr, retVal));
461+
void *hostPtr = reinterpret_cast<void *>(0x12340000);
462+
463+
uint32_t newTaskCount = 17;
464+
bcsCsr.taskCount = newTaskCount - 1;
465+
466+
EXPECT_EQ(0u, mockInternalAllocationsStorage->cleanAllocationsCalled);
467+
bcsCsr.blitFromHostPtr(*buffer, hostPtr, 1);
468+
EXPECT_EQ(1u, mockInternalAllocationsStorage->cleanAllocationsCalled);
469+
EXPECT_EQ(newTaskCount, mockInternalAllocationsStorage->lastCleanAllocationsTaskCount);
470+
EXPECT_TRUE(TEMPORARY_ALLOCATION == mockInternalAllocationsStorage->lastCleanAllocationUsage);
471+
}

unit_tests/libult/ult_command_stream_receiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
4040
using BaseClass::CommandStreamReceiver::experimentalCmdBuffer;
4141
using BaseClass::CommandStreamReceiver::flushStamp;
4242
using BaseClass::CommandStreamReceiver::GSBAFor32BitProgrammed;
43+
using BaseClass::CommandStreamReceiver::internalAllocationStorage;
4344
using BaseClass::CommandStreamReceiver::isPreambleSent;
4445
using BaseClass::CommandStreamReceiver::isStateSipSent;
4546
using BaseClass::CommandStreamReceiver::lastMediaSamplerConfig;

unit_tests/mocks/mock_internal_allocation_storage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class MockInternalAllocationStorage : public InternalAllocationStorage {
1616
void cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage) override {
1717
cleanAllocationsCalled++;
1818
lastCleanAllocationsTaskCount = waitTaskCount;
19+
lastCleanAllocationUsage = allocationUsage;
1920
InternalAllocationStorage::cleanAllocationList(waitTaskCount, allocationUsage);
2021
if (doUpdateCompletion) {
2122
*commandStreamReceiver.getTagAddress() = valueToUpdateCompletion;
@@ -28,6 +29,7 @@ class MockInternalAllocationStorage : public InternalAllocationStorage {
2829
}
2930
bool doUpdateCompletion = false;
3031
uint32_t valueToUpdateCompletion;
32+
uint32_t lastCleanAllocationUsage = 0;
3133
uint32_t lastCleanAllocationsTaskCount = 0;
3234
uint32_t cleanAllocationsCalled = 0;
3335
};

0 commit comments

Comments
 (0)