fix_l0:Unbind immediately during unmap

- Explicitly force unbind of Buffer Objects during unmap to ensure that
Buffer Objects can be reused in the same application.

Related-To: LOCI-4162

Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
This commit is contained in:
Spruit, Neil R
2023-03-22 01:20:56 +00:00
committed by Compute-Runtime-Automation
parent 3ec0a637ba
commit 9a056318a4
2 changed files with 48 additions and 0 deletions

View File

@@ -560,6 +560,9 @@ void DrmMemoryManager::unMapPhysicalToVirtualMemory(GraphicsAllocation *physical
auto bufferObjects = drmAllocation->getBOs();
for (auto bufferObject : bufferObjects) {
if (bufferObject) {
for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) {
bufferObject->unbind(osContext, drmIterator);
}
auto address = bufferObject->peekAddress();
uint64_t offset = address - gpuRange;
bufferObject->setAddress(offset);

View File

@@ -5159,6 +5159,51 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocati
memoryManager->freeGraphicsMemory(kernelIsaAllocation);
}
TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocationWithLargeBufferThenAfterUnMapBindInfoisReset) {
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
AllocationData allocData;
uint64_t gpuAddress = 0x1234;
allocData.allFlags = 0;
allocData.size = 18 * MemoryConstants::pageSize64k;
allocData.flags.allocateMemory = true;
allocData.type = AllocationType::BUFFER;
allocData.storageInfo.memoryBanks = maxNBitValue(MemoryBanks::getBankForLocalMemory(3));
allocData.storageInfo.multiStorage = true;
allocData.rootDeviceIndex = rootDeviceIndex;
auto allocation = memoryManager->allocatePhysicalLocalDeviceMemory(allocData, status);
ASSERT_NE(nullptr, allocation);
EXPECT_EQ(MemoryManager::AllocationStatus::Success, status);
EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool());
EXPECT_EQ(0u, allocation->getGpuAddress());
EXPECT_EQ(EngineLimits::maxHandleCount, allocation->getNumGmms());
memoryManager->mapPhysicalToVirtualMemory(allocation, gpuAddress, allocData.size);
EXPECT_EQ(gpuAddress, allocation->getGpuAddress());
auto drmAllocation = static_cast<DrmAllocation *>(allocation);
auto &bos = drmAllocation->getBOs();
auto boAddress = drmAllocation->getGpuAddress();
for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
auto bo = bos[handleId];
ASSERT_NE(nullptr, bo);
auto boSize = allocation->getGmm(handleId)->gmmResourceInfo->getSizeAllocation();
EXPECT_EQ(boAddress, bo->peekAddress());
EXPECT_EQ(boSize, bo->peekSize());
EXPECT_EQ(boSize, handleId == 0 || handleId == 1 ? 5 * MemoryConstants::pageSize64k : 4 * MemoryConstants::pageSize64k);
boAddress += boSize;
}
auto osContext = device->getDefaultEngine().osContext;
memoryManager->unMapPhysicalToVirtualMemory(allocation, gpuAddress, allocData.size, osContext, 0u);
for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
auto bo = bos[handleId];
auto contextId = bo->getOsContextId(osContext);
ASSERT_NE(nullptr, bo);
EXPECT_FALSE(bo->bindInfo[contextId][handleId]);
}
EXPECT_EQ(0u, allocation->getGpuAddress());
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocationWithLargeBufferWhenAllocatingInDevicePoolOnAllMemoryBanksThenCreateFourBufferObjectsWithDifferentGpuVirtualAddressesAndPartialSizes) {
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
AllocationData allocData;