refactor: use single vector to store used heap allocations

Related-To: NEO-10483

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz 2024-03-15 12:48:01 +00:00 committed by Compute-Runtime-Automation
parent dab5469f81
commit f496233462
5 changed files with 86 additions and 18 deletions

View File

@ -130,8 +130,11 @@ void CommandList::removeDeallocationContainerData() {
if (allocData) {
device->getDriverHandle()->getSvmAllocsManager()->removeSVMAlloc(*allocData);
}
memoryManager->freeGraphicsMemory(deallocation);
eraseDeallocationContainerEntry(deallocation);
if (!((deallocation->getAllocationType() == NEO::AllocationType::internalHeap) ||
(deallocation->getAllocationType() == NEO::AllocationType::linearStream))) {
memoryManager->freeGraphicsMemory(deallocation);
eraseDeallocationContainerEntry(deallocation);
}
}
}

View File

@ -1923,6 +1923,23 @@ HWTEST2_F(CommandListCreate, givenImmediateCommandListWhenThereIsNoEnoughSpaceFo
EXPECT_EQ(latestFlushedTaskCount + 1, whiteBoxCmdList->csr->peekLatestFlushedTaskCount());
}
HWTEST_F(CommandListCreate, givenCommandListWhenRemoveDeallocationContainerDataThenHeapNotErased) {
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily,
device,
NEO::EngineGroupType::compute,
0u,
returnValue, false));
auto &cmdContainer = commandList->getCmdContainer();
auto heapAlloc = cmdContainer.getIndirectHeapAllocation(HeapType::indirectObject);
cmdContainer.getDeallocationContainer().push_back(heapAlloc);
EXPECT_EQ(cmdContainer.getDeallocationContainer().size(), 1u);
commandList->removeDeallocationContainerData();
EXPECT_EQ(cmdContainer.getDeallocationContainer().size(), 1u);
cmdContainer.getDeallocationContainer().clear();
}
TEST(CommandList, givenContextGroupEnabledWhenCreatingImmediateCommandListThenEachCmdListHasDifferentCsr) {
HardwareInfo hwInfo = *defaultHwInfo;

View File

@ -39,8 +39,10 @@ CommandContainer::~CommandContainer() {
for (auto allocationIndirectHeap : allocationIndirectHeaps) {
heapHelper->storeHeapAllocation(allocationIndirectHeap);
}
for (auto heapAllocation : storedHeapsContainer) {
heapHelper->storeHeapAllocation(heapAllocation);
for (auto deallocation : deallocationContainer) {
if ((deallocation->getAllocationType() == AllocationType::internalHeap) || (deallocation->getAllocationType() == AllocationType::linearStream)) {
getHeapHelper()->storeHeapAllocation(deallocation);
}
}
}
}
@ -184,11 +186,12 @@ void CommandContainer::reset() {
slmSize = std::numeric_limits<uint32_t>::max();
getResidencyContainer().clear();
if (getHeapHelper()) {
for (auto heapAllocation : storedHeapsContainer) {
getHeapHelper()->storeHeapAllocation(heapAllocation);
for (auto deallocation : deallocationContainer) {
if ((deallocation->getAllocationType() == AllocationType::internalHeap) || (deallocation->getAllocationType() == AllocationType::linearStream)) {
getHeapHelper()->storeHeapAllocation(deallocation);
}
}
}
storedHeapsContainer.clear();
getDeallocationContainer().clear();
sshAllocations.clear();
@ -285,7 +288,7 @@ void CommandContainer::createAndAssignNewHeap(HeapType heapType, size_t size) {
if (this->immediateCmdListCsr) {
this->storeAllocationAndFlushTagUpdate(oldAlloc);
} else {
storedHeapsContainer.push_back(oldAlloc);
getDeallocationContainer().push_back(oldAlloc);
}
setIndirectHeapAllocation(heapType, newAlloc);
if (oldBase != newBase) {

View File

@ -219,7 +219,6 @@ class CommandContainer : public NonCopyableOrMovableClass {
CmdBufferContainer cmdBufferAllocations;
ResidencyContainer residencyContainer;
std::vector<GraphicsAllocation *> deallocationContainer;
std::vector<GraphicsAllocation *> storedHeapsContainer;
HeapContainer sshAllocations;
HeapReserveData dynamicStateHeapReserveData;

View File

@ -38,7 +38,6 @@ class MyMockCommandContainer : public CommandContainer {
using CommandContainer::getAlignedCmdBufferSize;
using CommandContainer::immediateReusableAllocationList;
using CommandContainer::secondaryCommandStreamForImmediateCmdList;
using CommandContainer::storedHeapsContainer;
GraphicsAllocation *allocateCommandBuffer(bool forceHostMemory) override {
allocateCommandBufferCalled[!!forceHostMemory]++;
@ -1906,20 +1905,22 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenOldHeapIsStoredAndResetContain
auto status = cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, true, false);
EXPECT_EQ(CommandContainer::ErrorCode::success, status);
EXPECT_EQ(0u, cmdContainer.storedHeapsContainer.size());
auto &deallocationList = cmdContainer.getDeallocationContainer();
EXPECT_EQ(0u, deallocationList.size());
auto ioh = cmdContainer.getIndirectHeap(NEO::HeapType::indirectObject);
auto iohOldAllocation = ioh->getGraphicsAllocation();
ioh->getSpace(ioh->getAvailableSpace());
cmdContainer.getHeapWithRequiredSizeAndAlignment(NEO::HeapType::indirectObject, 64, 1);
EXPECT_EQ(1u, cmdContainer.storedHeapsContainer.size());
auto iohAllocIt = std::find(cmdContainer.storedHeapsContainer.begin(),
cmdContainer.storedHeapsContainer.end(),
EXPECT_EQ(1u, deallocationList.size());
auto iohAllocIt = std::find(deallocationList.begin(),
deallocationList.end(),
iohOldAllocation);
EXPECT_NE(cmdContainer.storedHeapsContainer.end(), iohAllocIt);
EXPECT_NE(deallocationList.end(), iohAllocIt);
cmdContainer.reset();
EXPECT_EQ(0u, cmdContainer.storedHeapsContainer.size());
EXPECT_EQ(0u, deallocationList.size());
auto internalStorage = pDevice->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage();
@ -1928,6 +1929,49 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenOldHeapIsStoredAndResetContain
.release();
EXPECT_EQ(iohOldAllocation, iohReusedAllocation);
pDevice->getMemoryManager()->freeGraphicsMemory(iohReusedAllocation);
auto ssh = cmdContainer.getIndirectHeap(NEO::HeapType::surfaceState);
auto sshOldAllocation = ssh->getGraphicsAllocation();
ssh->getSpace(ssh->getAvailableSpace());
cmdContainer.getHeapWithRequiredSizeAndAlignment(NEO::HeapType::surfaceState, 64, 1);
EXPECT_EQ(1u, deallocationList.size());
auto sshAllocIt = std::find(deallocationList.begin(),
deallocationList.end(),
sshOldAllocation);
EXPECT_NE(deallocationList.end(), sshAllocIt);
cmdContainer.reset();
EXPECT_EQ(0u, deallocationList.size());
auto sshReusedAllocation = internalStorage->obtainReusableAllocation(sshOldAllocation->getUnderlyingBufferSize(),
sshOldAllocation->getAllocationType())
.release();
EXPECT_EQ(sshOldAllocation, sshReusedAllocation);
pDevice->getMemoryManager()->freeGraphicsMemory(sshReusedAllocation);
}
TEST_F(CommandContainerTest, givenCmdContainerWhenNonHeapIsStoredAndResetContainerThenNonHeapAllocationIsNotStoredForReuse) {
MyMockCommandContainer cmdContainer;
auto status = cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, true, false);
EXPECT_EQ(CommandContainer::ErrorCode::success, status);
auto &deallocationList = cmdContainer.getDeallocationContainer();
EXPECT_EQ(0u, deallocationList.size());
constexpr size_t mockBufferSize = 64;
uint8_t mockBuffer[mockBufferSize];
MockGraphicsAllocation otherAllocation(mockBuffer, mockBufferSize);
GraphicsAllocation *nonHeapAllocation = &otherAllocation;
deallocationList.push_back(nonHeapAllocation);
cmdContainer.reset();
auto internalStorage = pDevice->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage();
auto reusedAllocation = internalStorage->obtainReusableAllocation(nonHeapAllocation->getUnderlyingBufferSize(),
nonHeapAllocation->getAllocationType())
.release();
EXPECT_EQ(nullptr, reusedAllocation);
}
TEST_F(CommandContainerTest, givenHeaplessCmdContainerWhenResetContainerThenNoHeapInStorageForReuse) {
@ -1935,8 +1979,10 @@ TEST_F(CommandContainerTest, givenHeaplessCmdContainerWhenResetContainerThenNoHe
auto status = cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, false, false);
EXPECT_EQ(CommandContainer::ErrorCode::success, status);
EXPECT_EQ(0u, cmdContainer.storedHeapsContainer.size());
auto &deallocationList = cmdContainer.getDeallocationContainer();
EXPECT_EQ(0u, deallocationList.size());
cmdContainer.reset();
EXPECT_EQ(0u, cmdContainer.storedHeapsContainer.size());
EXPECT_EQ(0u, deallocationList.size());
}