fix: add error checks & return to unMapVirtualMem

Related-To: NEO-8566

Signed-off-by: Eric Mortensen <eric.mortensen@intel.com>
This commit is contained in:
Eric Mortensen
2025-07-10 03:05:39 +00:00
committed by Compute-Runtime-Automation
parent 35ecde70df
commit 69f2cda2fa
20 changed files with 258 additions and 73 deletions

View File

@@ -1484,34 +1484,45 @@ ze_result_t ContextImp::mapVirtualMem(const void *ptr,
} }
} }
ze_result_t ContextImp::unMapVirtualMem(const void *ptr, ze_result_t ContextImp::unMapVirtualMem(const void *ptr, size_t size) {
size_t size) { ze_result_t result = ZE_RESULT_SUCCESS;
NEO::VirtualMemoryReservation *virtualMemoryReservation = nullptr; // Test for unsupported page size alignment: not covered in API validation layer.
auto lockVirtual = this->driverHandle->getMemoryManager()->lockVirtualMemoryReservationMap(); if ((getPageAlignedSizeRequired(size, nullptr, nullptr) != size)) {
virtualMemoryReservation = findSupportedVirtualReservation(ptr, size); return ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT;
}
auto memManager = this->driverHandle->getMemoryManager();
auto lockVirtual = memManager->lockVirtualMemoryReservationMap();
auto virtualMemoryReservation = findSupportedVirtualReservation(ptr, size);
if (virtualMemoryReservation) { if (virtualMemoryReservation) {
std::map<void *, NEO::MemoryMappedRange *>::iterator physicalMapIt; std::map<void *, NEO::MemoryMappedRange *>::iterator physicalMapIt;
physicalMapIt = virtualMemoryReservation->mappedAllocations.find(const_cast<void *>(ptr)); physicalMapIt = virtualMemoryReservation->mappedAllocations.find(const_cast<void *>(ptr));
if (physicalMapIt != virtualMemoryReservation->mappedAllocations.end()) { if (physicalMapIt != virtualMemoryReservation->mappedAllocations.end()) {
NEO::SVMAllocsManager *svmAllocsManager = this->driverHandle->getSvmAllocsManager();
NEO::PhysicalMemoryAllocation *physicalAllocation = &physicalMapIt->second->mappedAllocation; NEO::PhysicalMemoryAllocation *physicalAllocation = &physicalMapIt->second->mappedAllocation;
NEO::SvmAllocationData *allocData = this->driverHandle->getSvmAllocsManager()->getSVMAlloc(reinterpret_cast<void *>(physicalAllocation->allocation->getGpuAddress())); NEO::SvmAllocationData *allocData = svmAllocsManager->getSVMAlloc(reinterpret_cast<void *>(physicalAllocation->allocation->getGpuAddress()));
bool retVal = false;
if (physicalAllocation->allocation->getAllocationType() == NEO::AllocationType::buffer) { if (physicalAllocation->allocation->getAllocationType() == NEO::AllocationType::buffer) {
this->driverHandle->getSvmAllocsManager()->removeSVMAlloc(*allocData); svmAllocsManager->removeSVMAlloc(*allocData);
NEO::OsContext *osContext = &physicalAllocation->device->getDefaultEngine().commandStreamReceiver->getOsContext(); NEO::OsContext *osContext = &physicalAllocation->device->getDefaultEngine().commandStreamReceiver->getOsContext();
this->driverHandle->getMemoryManager()->unMapPhysicalDeviceMemoryFromVirtualMemory(physicalAllocation->allocation, castToUint64(ptr), size, osContext, virtualMemoryReservation->rootDeviceIndex); retVal = memManager->unMapPhysicalDeviceMemoryFromVirtualMemory(physicalAllocation->allocation, castToUint64(ptr), size, osContext, virtualMemoryReservation->rootDeviceIndex);
} else { } else {
auto gpuAllocations = allocData->gpuAllocations; auto gpuAllocations = allocData->gpuAllocations;
this->driverHandle->getSvmAllocsManager()->removeSVMAlloc(*allocData); svmAllocsManager->removeSVMAlloc(*allocData);
this->driverHandle->getMemoryManager()->unMapPhysicalHostMemoryFromVirtualMemory(gpuAllocations, physicalAllocation->allocation, castToUint64(ptr), size); retVal = memManager->unMapPhysicalHostMemoryFromVirtualMemory(gpuAllocations, physicalAllocation->allocation, castToUint64(ptr), size);
}
if (!retVal) {
result = ZE_RESULT_ERROR_UNKNOWN;
} }
delete physicalMapIt->second; delete physicalMapIt->second;
virtualMemoryReservation->mappedAllocations.erase(physicalMapIt); virtualMemoryReservation->mappedAllocations.erase(physicalMapIt);
} }
} }
return ZE_RESULT_SUCCESS; return result;
} }
ze_result_t ContextImp::setVirtualMemAccessAttribute(const void *ptr, ze_result_t ContextImp::setVirtualMemAccessAttribute(const void *ptr,

View File

@@ -232,8 +232,8 @@ class MemoryManagerIpcMock : public NEO::MemoryManager {
GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return; }; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return false; };
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return; }; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
@@ -363,8 +363,8 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return; }; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return false; };
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return; }; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };

View File

@@ -1759,8 +1759,8 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager {
GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return; }; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return false; };
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return; }; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override {
if (failMapVirtualMemory) { if (failMapVirtualMemory) {
return false; return false;
@@ -2510,6 +2510,7 @@ TEST_F(ContextTest, whenCallingMapVirtualMemoryWithInvalidValuesThenFailureRetur
res = contextImp->mapVirtualMem(offsetAddr, pagesize * 2, mem, offset, access); res = contextImp->mapVirtualMem(offsetAddr, pagesize * 2, mem, offset, access);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
// Test coverage for case when "if (virtualMemoryReservation)" is false.
res = contextImp->unMapVirtualMem(nullptr, pagesize); res = contextImp->unMapVirtualMem(nullptr, pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -2530,6 +2531,10 @@ TEST_F(ContextTest, whenCallingMapVirtualMemoryWithInvalidValuesThenFailureRetur
res = contextImp->mapVirtualMem(ptr, pagesize, mem, offset, access); res = contextImp->mapVirtualMem(ptr, pagesize, mem, offset, access);
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, res);
// Test unsupported page size alignment: not covered in API validation layer.
res = contextImp->unMapVirtualMem(ptr, pagesize + pagesize / 2);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT, res);
res = contextImp->unMapVirtualMem(ptr, pagesize); res = contextImp->unMapVirtualMem(ptr, pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -2543,6 +2548,69 @@ TEST_F(ContextTest, whenCallingMapVirtualMemoryWithInvalidValuesThenFailureRetur
EXPECT_EQ(ZE_RESULT_SUCCESS, res); EXPECT_EQ(ZE_RESULT_SUCCESS, res);
} }
TEST_F(ContextTest, whenCallingUnmapVirtualMemoryWithFailedUnmapThenUnknownErrorReturned) {
ze_context_handle_t hContext;
std::unique_ptr<MockMemoryManager> mockMemManager;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};
ze_result_t res = driverHandle->createContext(&desc, 0u, nullptr, &hContext);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface =
std::make_unique<NEO::MockMemoryOperations>();
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
// Use a mock memory manager that returns a failure for unmapVirtualMem.
auto memManager = driverHandle->getMemoryManager();
mockMemManager = std::make_unique<MockMemoryManager>();
driverHandle->setMemoryManager(mockMemManager.get());
void *pStart = 0x0;
size_t size = 4096u;
void *ptr = nullptr;
size_t pagesize = 0u;
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->reserveVirtualMem(pStart, pagesize, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
ze_physical_mem_desc_t descMem = {ZE_STRUCTURE_TYPE_PHYSICAL_MEM_DESC, nullptr, ZE_PHYSICAL_MEM_FLAG_ALLOCATE_ON_DEVICE, pagesize};
ze_physical_mem_handle_t mem = {};
res = contextImp->createPhysicalMem(device, &descMem, &mem);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
ze_memory_access_attribute_t access = {ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE};
size_t offset = 0;
res = contextImp->mapVirtualMem(ptr, pagesize, mem, offset, access);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
// Set the mock memory manager to return an error for unmapVirtualMem.
mockMemManager->failUnMapPhysicalToVirtualMemory = true;
res = contextImp->unMapVirtualMem(ptr, pagesize);
EXPECT_EQ(ZE_RESULT_ERROR_UNKNOWN, res);
// Reset the mock memory manager to not fail unmapVirtualMem.
mockMemManager->failUnMapPhysicalToVirtualMemory = false;
res = contextImp->destroyPhysicalMem(mem);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->freeVirtualMem(ptr, pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
// Reset the memory manager to the original one.
driverHandle->setMemoryManager(memManager);
res = contextImp->destroy();
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
using IsAtMostProductDG1 = IsAtMostProduct<IGFX_DG1>; using IsAtMostProductDG1 = IsAtMostProduct<IGFX_DG1>;
HWTEST2_F(ContextTest, WhenCreatingImageThenSuccessIsReturned, IsAtMostProductDG1) { HWTEST2_F(ContextTest, WhenCreatingImageThenSuccessIsReturned, IsAtMostProductDG1) {

View File

@@ -104,8 +104,8 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager {
GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return; }; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return false; };
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return; }; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };

View File

@@ -336,14 +336,15 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation, bool i
return; return;
} }
bool rootEnvAvailable = executionEnvironment.rootDeviceEnvironments.size() > 0; bool rootEnvAvailable = executionEnvironment.rootDeviceEnvironments.size() > 0;
uint32_t rootDevIdx = gfxAllocation->getRootDeviceIndex();
if (rootEnvAvailable) { if (rootEnvAvailable) {
if (executionEnvironment.rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->getBindlessHeapsHelper() != nullptr) { if (executionEnvironment.rootDeviceEnvironments[rootDevIdx]->getBindlessHeapsHelper() != nullptr) {
executionEnvironment.rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->getBindlessHeapsHelper()->releaseSSToReusePool(gfxAllocation->getBindlessInfo()); executionEnvironment.rootDeviceEnvironments[rootDevIdx]->getBindlessHeapsHelper()->releaseSSToReusePool(gfxAllocation->getBindlessInfo());
} }
if (this->peekExecutionEnvironment().rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->memoryOperationsInterface) { if (this->peekExecutionEnvironment().rootDeviceEnvironments[rootDevIdx]->memoryOperationsInterface) {
this->peekExecutionEnvironment().rootDeviceEnvironments[gfxAllocation->getRootDeviceIndex()]->memoryOperationsInterface->free(nullptr, *gfxAllocation); this->peekExecutionEnvironment().rootDeviceEnvironments[rootDevIdx]->memoryOperationsInterface->free(nullptr, *gfxAllocation);
} }
} }
@@ -359,7 +360,7 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation, bool i
} }
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Free allocation, gpu address = ", std::hex, gfxAllocation->getGpuAddress()); DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Free allocation, gpu address = ", std::hex, gfxAllocation->getGpuAddress());
getLocalMemoryUsageBankSelector(gfxAllocation->getAllocationType(), gfxAllocation->getRootDeviceIndex())->freeOnBanks(gfxAllocation->storageInfo.getMemoryBanks(), gfxAllocation->getUnderlyingBufferSize()); getLocalMemoryUsageBankSelector(gfxAllocation->getAllocationType(), rootDevIdx)->freeOnBanks(gfxAllocation->storageInfo.getMemoryBanks(), gfxAllocation->getUnderlyingBufferSize());
freeGraphicsMemoryImpl(gfxAllocation, isImportedAllocation); freeGraphicsMemoryImpl(gfxAllocation, isImportedAllocation);
} }

View File

@@ -322,8 +322,8 @@ class MemoryManager {
[[nodiscard]] std::unique_lock<std::mutex> lockPhysicalMemoryAllocationMap() { return std::unique_lock<std::mutex>(this->physicalMemoryAllocationMapMutex); }; [[nodiscard]] std::unique_lock<std::mutex> lockPhysicalMemoryAllocationMap() { return std::unique_lock<std::mutex>(this->physicalMemoryAllocationMapMutex); };
virtual bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) = 0; virtual bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) = 0;
virtual bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) = 0; virtual bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) = 0;
virtual void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) = 0; virtual bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) = 0;
virtual void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) = 0; virtual bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) = 0;
bool allocateBindlessSlot(GraphicsAllocation *allocation); bool allocateBindlessSlot(GraphicsAllocation *allocation);
static uint64_t adjustToggleBitFlagForGpuVa(AllocationType inputAllocationType, uint64_t gpuAddress); static uint64_t adjustToggleBitFlagForGpuVa(AllocationType inputAllocationType, uint64_t gpuAddress);
virtual bool allocateInterrupt(uint32_t &outHandle, uint32_t rootDeviceIndex) { return false; } virtual bool allocateInterrupt(uint32_t &outHandle, uint32_t rootDeviceIndex) { return false; }

View File

@@ -417,16 +417,18 @@ void OsAgnosticMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uin
} }
} }
void OsAgnosticMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) { bool OsAgnosticMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) {
physicalAllocation->setGpuPtr(0u); physicalAllocation->setGpuPtr(0u);
physicalAllocation->setReservedAddressRange(nullptr, 0u); physicalAllocation->setReservedAddressRange(nullptr, 0u);
return true;
} }
void OsAgnosticMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) { bool OsAgnosticMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) {
for (uint32_t i = 0; i < static_cast<uint32_t>(multiGraphicsAllocation.getGraphicsAllocations().size()); i++) { for (uint32_t i = 0; i < static_cast<uint32_t>(multiGraphicsAllocation.getGraphicsAllocations().size()); i++) {
delete multiGraphicsAllocation.getGraphicsAllocation(i); delete multiGraphicsAllocation.getGraphicsAllocation(i);
multiGraphicsAllocation.removeAllocation(i); multiGraphicsAllocation.removeAllocation(i);
} }
return true;
} }
bool OsAgnosticMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) { bool OsAgnosticMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2024 Intel Corporation * Copyright (C) 2018-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -64,8 +64,8 @@ class OsAgnosticMemoryManager : public MemoryManager {
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override;
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override;
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override; GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override; GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override;

View File

@@ -116,7 +116,7 @@ class BufferObject {
BufferObject *const residency[], size_t residencyCount, ExecObject *execObjectsStorage, uint64_t completionGpuAddress, TaskCountType completionValue); BufferObject *const residency[], size_t residencyCount, ExecObject *execObjectsStorage, uint64_t completionGpuAddress, TaskCountType completionValue);
int bind(OsContext *osContext, uint32_t vmHandleId, const bool forcePagingFence); int bind(OsContext *osContext, uint32_t vmHandleId, const bool forcePagingFence);
int unbind(OsContext *osContext, uint32_t vmHandleId); MOCKABLE_VIRTUAL int unbind(OsContext *osContext, uint32_t vmHandleId);
void printExecutionBuffer(ExecBuffer &execbuf, const size_t &residencyCount, ExecObject *execObjectsStorage, BufferObject *const residency[]); void printExecutionBuffer(ExecBuffer &execbuf, const size_t &residencyCount, ExecObject *execObjectsStorage, BufferObject *const residency[]);

View File

@@ -754,13 +754,17 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemory64kb(const Allocatio
return nullptr; return nullptr;
} }
void DrmMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) { bool DrmMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) {
bool result = true;
DrmAllocation *drmAllocation = reinterpret_cast<DrmAllocation *>(physicalAllocation); DrmAllocation *drmAllocation = reinterpret_cast<DrmAllocation *>(physicalAllocation);
auto bufferObjects = drmAllocation->getBOs(); auto bufferObjects = drmAllocation->getBOs();
for (auto bufferObject : bufferObjects) { for (auto bufferObject : bufferObjects) {
if (bufferObject) { if (bufferObject) {
for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) { for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) {
bufferObject->unbind(osContext, drmIterator); if (bufferObject->unbind(osContext, drmIterator) != 0) {
result = false;
}
} }
auto address = bufferObject->peekAddress(); auto address = bufferObject->peekAddress();
uint64_t offset = address - gpuRange; uint64_t offset = address - gpuRange;
@@ -769,9 +773,10 @@ void DrmMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAlloca
} }
physicalAllocation->setCpuPtrAndGpuAddress(nullptr, 0u); physicalAllocation->setCpuPtrAndGpuAddress(nullptr, 0u);
physicalAllocation->setReservedAddressRange(nullptr, 0u); physicalAllocation->setReservedAddressRange(nullptr, 0u);
return result;
} }
void DrmMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) { bool DrmMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) {
void *addressToUnmap = static_cast<DrmAllocation *>(multiGraphicsAllocation.getGraphicsAllocation(physicalAllocation->getRootDeviceIndex()))->getMmapPtr(); void *addressToUnmap = static_cast<DrmAllocation *>(multiGraphicsAllocation.getGraphicsAllocation(physicalAllocation->getRootDeviceIndex()))->getMmapPtr();
size_t sizeToUnmap = static_cast<DrmAllocation *>(multiGraphicsAllocation.getGraphicsAllocation(physicalAllocation->getRootDeviceIndex()))->getMmapSize(); size_t sizeToUnmap = static_cast<DrmAllocation *>(multiGraphicsAllocation.getGraphicsAllocation(physicalAllocation->getRootDeviceIndex()))->getMmapSize();
@@ -803,8 +808,8 @@ void DrmMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAll
delete allocation; delete allocation;
} }
} }
// Unmap the memory region
this->munmapFunction(addressToUnmap, sizeToUnmap); return (this->munmapFunction(addressToUnmap, sizeToUnmap) == 0);
} }
bool DrmMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) { bool DrmMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) {

View File

@@ -171,8 +171,8 @@ class DrmMemoryManager : public MemoryManager {
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override;
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override;
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override; GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override; GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override;
GraphicsAllocation *createSharedUnifiedMemoryAllocation(const AllocationData &allocationData); GraphicsAllocation *createSharedUnifiedMemoryAllocation(const AllocationData &allocationData);

View File

@@ -100,20 +100,24 @@ GfxMemoryAllocationMethod WddmMemoryManager::getPreferredAllocationMethod(const
return preferredAllocationMethod; return preferredAllocationMethod;
} }
void WddmMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) { bool WddmMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) {
const auto wddm = static_cast<OsContextWin *>(osContext)->getWddm(); const auto wddm = static_cast<OsContextWin *>(osContext)->getWddm();
wddm->freeGpuVirtualAddress(gpuRange, bufferSize); wddm->freeGpuVirtualAddress(gpuRange, bufferSize);
auto gfxPartition = getGfxPartition(rootDeviceIndex); auto gfxPartition = getGfxPartition(rootDeviceIndex);
uint64_t reservedAddress = 0u; uint64_t reservedAddress = 0u;
auto status = wddm->reserveGpuVirtualAddress(gpuRange, gfxPartition->getHeapMinimalAddress(HeapIndex::heapStandard64KB), gfxPartition->getHeapLimit(HeapIndex::heapStandard64KB), bufferSize, &reservedAddress); auto status = wddm->reserveGpuVirtualAddress(gpuRange, gfxPartition->getHeapMinimalAddress(HeapIndex::heapStandard64KB), gfxPartition->getHeapLimit(HeapIndex::heapStandard64KB), bufferSize, &reservedAddress);
UNRECOVERABLE_IF(status != STATUS_SUCCESS); if (status != STATUS_SUCCESS) {
return false;
}
physicalAllocation->setCpuPtrAndGpuAddress(nullptr, 0u); physicalAllocation->setCpuPtrAndGpuAddress(nullptr, 0u);
physicalAllocation->setReservedAddressRange(nullptr, 0u); physicalAllocation->setReservedAddressRange(nullptr, 0u);
WddmAllocation *wddmAllocation = reinterpret_cast<WddmAllocation *>(physicalAllocation); WddmAllocation *wddmAllocation = reinterpret_cast<WddmAllocation *>(physicalAllocation);
wddmAllocation->setMappedPhysicalMemoryReservation(false); wddmAllocation->setMappedPhysicalMemoryReservation(false);
return true;
} }
void WddmMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) { bool WddmMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) {
return true;
} }
bool WddmMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) { bool WddmMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) {

View File

@@ -87,8 +87,8 @@ class WddmMemoryManager : public MemoryManager, NEO::NonCopyableAndNonMovableCla
GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override; GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override;
GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override; GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override;
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override;
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override;
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override; bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override;
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override; GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;

View File

@@ -54,6 +54,17 @@ class MockBufferObject : public BufferObject {
return BufferObject::exec(used, startOffset, flags, requiresCoherency, osContext, vmHandleId, drmContextId, return BufferObject::exec(used, startOffset, flags, requiresCoherency, osContext, vmHandleId, drmContextId,
residency, residencyCount, execObjectsStorage, completionGpuAddress, completionValue); residency, residencyCount, execObjectsStorage, completionGpuAddress, completionValue);
} }
int unbind(OsContext *osContext, uint32_t vmHandleId) override {
errno = 0;
if (unbindErrno != 0) {
errno = unbindErrno;
return -1;
}
return BufferObject::unbind(osContext, vmHandleId);
}
int unbindErrno = 0;
}; };
class MockDrmAllocation : public DrmAllocation { class MockDrmAllocation : public DrmAllocation {

View File

@@ -50,8 +50,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
using MemoryManager::singleTemporaryAllocationsList; using MemoryManager::singleTemporaryAllocationsList;
using MemoryManager::supportsMultiStorageResources; using MemoryManager::supportsMultiStorageResources;
using MemoryManager::temporaryAllocations; using MemoryManager::temporaryAllocations;
using MemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory;
using MemoryManager::unMapPhysicalHostMemoryFromVirtualMemory;
using MemoryManager::useNonSvmHostPtrAlloc; using MemoryManager::useNonSvmHostPtrAlloc;
using MemoryManager::usmReuseInfo; using MemoryManager::usmReuseInfo;
using OsAgnosticMemoryManager::allocateGraphicsMemoryForImageFromHostPtr; using OsAgnosticMemoryManager::allocateGraphicsMemoryForImageFromHostPtr;
@@ -312,6 +310,24 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
return OsAgnosticMemoryManager::mapPhysicalHostMemoryToVirtualMemory(rootDeviceIndices, multiGraphicsAllocation, physicalAllocation, gpuRange, bufferSize); return OsAgnosticMemoryManager::mapPhysicalHostMemoryToVirtualMemory(rootDeviceIndices, multiGraphicsAllocation, physicalAllocation, gpuRange, bufferSize);
} }
bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override {
// Need to call actual unMapPhysicalDeviceMemoryFromVirtualMemory to ensure the virtual memory is unmapped.
bool retVal = OsAgnosticMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory(physicalAllocation, gpuRange, bufferSize, osContext, rootDeviceIndex);
if (failUnMapPhysicalToVirtualMemory) { // Return false if unmapping is supposed to fail.
return false;
}
return retVal;
}
bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override {
// Need to call actual unMapPhysicalDeviceMemoryFromVirtualMemory to ensure the virtual memory is unmapped.
bool retVal = OsAgnosticMemoryManager::unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuRange, bufferSize);
if (failUnMapPhysicalToVirtualMemory) { // Return false if unmapping is supposed to fail.
return false;
}
return retVal;
}
void registerIpcExportedAllocation(GraphicsAllocation *graphicsAllocation) override { void registerIpcExportedAllocation(GraphicsAllocation *graphicsAllocation) override {
registerIpcExportedAllocationCalled++; registerIpcExportedAllocationCalled++;
} }
@@ -387,6 +403,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
bool callBasePopulateOsHandles = true; bool callBasePopulateOsHandles = true;
bool callBaseAllocateGraphicsMemoryForNonSvmHostPtr = true; bool callBaseAllocateGraphicsMemoryForNonSvmHostPtr = true;
bool failMapPhysicalToVirtualMemory = false; bool failMapPhysicalToVirtualMemory = false;
bool failUnMapPhysicalToVirtualMemory = false;
bool returnMockGAFromDevicePool = false; bool returnMockGAFromDevicePool = false;
bool returnMockGAFromHostPool = false; bool returnMockGAFromHostPool = false;
std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment; std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment;

View File

@@ -573,8 +573,8 @@ TEST_F(DeviceGetCapsTest, givenFlagEnabled64kbPagesWhenCallConstructorMemoryMana
GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalLocalDeviceMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; }; GraphicsAllocation *allocatePhysicalHostMemory(const AllocationData &allocationData, AllocationStatus &status) override { return nullptr; };
void unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return; }; bool unMapPhysicalDeviceMemoryFromVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize, OsContext *osContext, uint32_t rootDeviceIndex) override { return false; };
void unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return; }; bool unMapPhysicalHostMemoryFromVirtualMemory(MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalDeviceMemoryToVirtualMemory(GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };
bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; }; bool mapPhysicalHostMemoryToVirtualMemory(RootDeviceIndicesContainer &rootDeviceIndices, MultiGraphicsAllocation &multiGraphicsAllocation, GraphicsAllocation *physicalAllocation, uint64_t gpuRange, size_t bufferSize) override { return false; };

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018-2024 Intel Corporation * Copyright (C) 2018-2025 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -462,9 +462,10 @@ TEST(BaseMemoryManagerTest, givenCalltoMapAndUnMapThenVirtialAddressSetUnSetOnPh
EXPECT_NE(nullptr, allocationBuffer); EXPECT_NE(nullptr, allocationBuffer);
uint64_t gpuAddress = 0x1234; uint64_t gpuAddress = 0x1234;
size_t size = 4096; size_t size = 4096;
memoryManager.mapPhysicalDeviceMemoryToVirtualMemory(allocationBuffer, gpuAddress, size); EXPECT_TRUE(memoryManager.mapPhysicalDeviceMemoryToVirtualMemory(allocationBuffer, gpuAddress, size));
EXPECT_EQ(gpuAddress, allocationBuffer->getGpuAddress()); EXPECT_EQ(gpuAddress, allocationBuffer->getGpuAddress());
memoryManager.unMapPhysicalDeviceMemoryFromVirtualMemory(allocationBuffer, gpuAddress, size, nullptr, 0u);
EXPECT_TRUE(memoryManager.unMapPhysicalDeviceMemoryFromVirtualMemory(allocationBuffer, gpuAddress, size, nullptr, 0u));
EXPECT_NE(gpuAddress, allocationBuffer->getGpuAddress()); EXPECT_NE(gpuAddress, allocationBuffer->getGpuAddress());
memoryManager.freeGraphicsMemory(allocationBuffer); memoryManager.freeGraphicsMemory(allocationBuffer);
} }

View File

@@ -125,7 +125,7 @@ TEST(MemoryManagerTest, givenDeviceGraphicsAllocationWhenMapCalledThenDontResetC
EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer()); EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer());
EXPECT_EQ(0x12300u, allocation.getGpuAddress()); EXPECT_EQ(0x12300u, allocation.getGpuAddress());
memoryManager.unMapPhysicalDeviceMemoryFromVirtualMemory(&allocation, 1, 1, nullptr, 0); EXPECT_TRUE(memoryManager.unMapPhysicalDeviceMemoryFromVirtualMemory(&allocation, 1, 1, nullptr, 0));
EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer()); EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer());
EXPECT_EQ(0u, allocation.getGpuAddress()); EXPECT_EQ(0u, allocation.getGpuAddress());
} }
@@ -149,7 +149,7 @@ TEST(MemoryManagerTest, givenHostGraphicsAllocationWhenMapCalledThenDontResetCpu
EXPECT_NE(multiGraphicsAllocation.getGraphicsAllocation(static_cast<uint32_t>(i)), nullptr); EXPECT_NE(multiGraphicsAllocation.getGraphicsAllocation(static_cast<uint32_t>(i)), nullptr);
} }
memoryManager.unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, static_cast<GraphicsAllocation *>(&allocation), 0x12300, 0); EXPECT_TRUE(memoryManager.unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, static_cast<GraphicsAllocation *>(&allocation), 0x12300, 0));
EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer()); EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer());
EXPECT_NE(0x12300u, allocation.getGpuAddress()); EXPECT_NE(0x12300u, allocation.getGpuAddress());
for (size_t i = 0; i < rootDeviceIndices.size(); i++) { for (size_t i = 0; i < rootDeviceIndices.size(); i++) {

View File

@@ -54,6 +54,7 @@
namespace NEO { namespace NEO {
namespace SysCalls { namespace SysCalls {
extern bool failMmap; extern bool failMmap;
extern bool failMunmap;
} // namespace SysCalls } // namespace SysCalls
} // namespace NEO } // namespace NEO
@@ -5950,8 +5951,6 @@ HWTEST_TEMPLATED_F(DrmMemoryManagerWithLocalMemoryTest, Given2MBLocalMemAlignmen
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
} }
using DrmMemoryManagerTest = Test<DrmMemoryManagerFixture>;
HWTEST_TEMPLATED_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThenAllocationIsFilledWithCorrectData) { HWTEST_TEMPLATED_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThenAllocationIsFilledWithCorrectData) {
mock->ioctlExpected.gemUserptr = 1; mock->ioctlExpected.gemUserptr = 1;
mock->ioctlExpected.gemWait = 1; mock->ioctlExpected.gemWait = 1;
@@ -7117,7 +7116,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocati
EXPECT_EQ(MemoryPool::localMemory, allocation->getMemoryPool()); EXPECT_EQ(MemoryPool::localMemory, allocation->getMemoryPool());
EXPECT_EQ(0u, allocation->getGpuAddress()); EXPECT_EQ(0u, allocation->getGpuAddress());
EXPECT_EQ(EngineLimits::maxHandleCount, allocation->getNumGmms()); EXPECT_EQ(EngineLimits::maxHandleCount, allocation->getNumGmms());
memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(allocation, gpuAddress, allocData.size); EXPECT_TRUE(memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(allocation, gpuAddress, allocData.size));
EXPECT_EQ(gpuAddress, allocation->getGpuAddress()); EXPECT_EQ(gpuAddress, allocation->getGpuAddress());
auto drmAllocation = static_cast<DrmAllocation *>(allocation); auto drmAllocation = static_cast<DrmAllocation *>(allocation);
@@ -7133,7 +7132,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocati
boAddress += boSize; boAddress += boSize;
} }
auto osContext = device->getDefaultEngine().osContext; auto osContext = device->getDefaultEngine().osContext;
memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(allocation, gpuAddress, allocData.size, osContext, 0u); EXPECT_TRUE(memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(allocation, gpuAddress, allocData.size, osContext, 0u));
EXPECT_EQ(0u, allocation->getGpuAddress()); EXPECT_EQ(0u, allocation->getGpuAddress());
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
} }
@@ -7154,7 +7153,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocati
EXPECT_NE(nullptr, kernelIsaAllocation); EXPECT_NE(nullptr, kernelIsaAllocation);
memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(kernelIsaAllocation, gpuAddress, allocData.size); EXPECT_TRUE(memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(kernelIsaAllocation, gpuAddress, allocData.size));
auto gpuAddressReserved = kernelIsaAllocation->getGpuAddress(); auto gpuAddressReserved = kernelIsaAllocation->getGpuAddress();
auto &bos = kernelIsaAllocation->getBOs(); auto &bos = kernelIsaAllocation->getBOs();
@@ -7173,7 +7172,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocati
EXPECT_EQ(0b1011u, storageInfo.memoryBanks.to_ulong()); EXPECT_EQ(0b1011u, storageInfo.memoryBanks.to_ulong());
auto osContext = device->getDefaultEngine().osContext; auto osContext = device->getDefaultEngine().osContext;
memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(kernelIsaAllocation, gpuAddress, allocData.size, osContext, 0u); EXPECT_TRUE(memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(kernelIsaAllocation, gpuAddress, allocData.size, osContext, 0u));
memoryManager->freeGraphicsMemory(kernelIsaAllocation); memoryManager->freeGraphicsMemory(kernelIsaAllocation);
} }
@@ -7196,7 +7195,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocati
EXPECT_EQ(MemoryPool::localMemory, allocation->getMemoryPool()); EXPECT_EQ(MemoryPool::localMemory, allocation->getMemoryPool());
EXPECT_EQ(0u, allocation->getGpuAddress()); EXPECT_EQ(0u, allocation->getGpuAddress());
EXPECT_EQ(EngineLimits::maxHandleCount, allocation->getNumGmms()); EXPECT_EQ(EngineLimits::maxHandleCount, allocation->getNumGmms());
memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(allocation, gpuAddress, allocData.size); EXPECT_TRUE(memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(allocation, gpuAddress, allocData.size));
EXPECT_EQ(gpuAddress, allocation->getGpuAddress()); EXPECT_EQ(gpuAddress, allocation->getGpuAddress());
auto drmAllocation = static_cast<DrmAllocation *>(allocation); auto drmAllocation = static_cast<DrmAllocation *>(allocation);
@@ -7212,7 +7211,7 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocati
boAddress += boSize; boAddress += boSize;
} }
auto osContext = device->getDefaultEngine().osContext; auto osContext = device->getDefaultEngine().osContext;
memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(allocation, gpuAddress, allocData.size, osContext, 0u); EXPECT_TRUE(memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(allocation, gpuAddress, allocData.size, osContext, 0u));
for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) { for (auto handleId = 0u; handleId < EngineLimits::maxHandleCount; handleId++) {
auto bo = bos[handleId]; auto bo = bos[handleId];
auto contextId = bo->getOsContextId(osContext); auto contextId = bo->getOsContextId(osContext);
@@ -7347,7 +7346,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDeviceBitfieldWithHole
EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(i)); EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(i));
} }
memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size); EXPECT_TRUE(memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size));
memoryManager->freeGraphicsMemory(physicalAllocation); memoryManager->freeGraphicsMemory(physicalAllocation);
} }
@@ -7466,7 +7465,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenSingleRootDeviceWhenMa
EXPECT_NE(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation()); EXPECT_NE(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation());
EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)); EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex));
memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size); EXPECT_TRUE(memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size));
memoryManager->freeGraphicsMemory(physicalAllocation); memoryManager->freeGraphicsMemory(physicalAllocation);
} }
@@ -7494,7 +7493,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenSingleRootDeviceWhenMa
EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)); EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex));
multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)->lock(addrToPtr(gpuAddress)); multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)->lock(addrToPtr(gpuAddress));
memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size); EXPECT_TRUE(memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size));
memoryManager->freeGraphicsMemory(physicalAllocation); memoryManager->freeGraphicsMemory(physicalAllocation);
} }
@@ -7522,7 +7521,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenSingleRootDeviceAndPri
EXPECT_NE(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation()); EXPECT_NE(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation());
EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)); EXPECT_NE(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex));
memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size); EXPECT_TRUE(memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, physicalAllocation, gpuAddress, allocData.size));
memoryManager->freeGraphicsMemory(physicalAllocation); memoryManager->freeGraphicsMemory(physicalAllocation);
} }
@@ -9180,3 +9179,48 @@ HWTEST_TEMPLATED_F(DrmMemoryManagerTest, givenDeviceUsmAllocationWhenLocalOnlyFl
EXPECT_EQ(0U, productHelper.getStorageInfoLocalOnlyFlagCalled); EXPECT_EQ(0U, productHelper.getStorageInfoLocalOnlyFlagCalled);
} }
// Test: unbind a device virtual memory allocation fails.
HWTEST_TEMPLATED_F(DrmMemoryManagerTest, givenDrmDeviceVMAllocationBufferObjectUnbindFails) {
const uint64_t gpuAddr = 0x1234;
const uint32_t rootDeviceIdx = 0u;
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[rootDeviceIdx]);
MockBufferObject bo(rootDeviceIdx, &drm, 3, 0, 0, 1);
MockDrmAllocation allocation(rootDeviceIdx, AllocationType::buffer, MemoryPool::system4KBPages);
bo.setAddress(gpuAddr);
allocation.bufferObjects[0] = &bo;
auto osContext = device->getDefaultEngine().osContext;
auto gfxAlloc = static_cast<GraphicsAllocation *>(&allocation);
bo.unbindErrno = EINVAL;
EXPECT_FALSE(memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(gfxAlloc, gpuAddr, MemoryConstants::pageSize, osContext, rootDeviceIdx));
bo.unbindErrno = errno = 0;
}
// Test: unmap host virtual memory allocations fails.
HWTEST_TEMPLATED_F(DrmMemoryManagerTest, givenDrmHostVMAllocationUnmapFails) {
const uint64_t gpuAddr = 0x1234;
const uint32_t rootDeviceIdx = 0u;
DrmMockResources drm(*executionEnvironment->rootDeviceEnvironments[rootDeviceIdx]);
MockBufferObject *bo = new MockBufferObject(rootDeviceIdx, &drm, 3, 0, 0, 1);
MockDrmAllocation *allocation = new MockDrmAllocation(rootDeviceIdx, AllocationType::bufferHostMemory, MemoryPool::system4KBPages);
allocation->setSize(MemoryConstants::pageSize);
bo->setAddress(gpuAddr);
allocation->bufferObjects[0] = bo;
auto gfxAlloc = static_cast<GraphicsAllocation *>(allocation);
MultiGraphicsAllocation gfxAllocs{1u};
gfxAllocs.addAllocation(gfxAlloc);
SysCalls::failMunmap = true;
EXPECT_FALSE(memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(gfxAllocs, gfxAlloc, gpuAddr, MemoryConstants::pageSize));
SysCalls::failMunmap = false;
}

View File

@@ -730,7 +730,7 @@ class WddmMemoryManagerSimpleTest : public ::testing::Test {
MockGdi *gdi = nullptr; MockGdi *gdi = nullptr;
}; };
TEST_F(WddmMemoryManagerSimpleTest, givenAllocateGraphicsMemoryWithPropertiesCalledWithDebugSurfaceTypeThenDebugSurfaceIsCreatedAndZerod) { TEST_F(WddmMemoryManagerSimpleTest, givenAllocateGraphicsMemoryWithPropertiesCalledWithDebugSurfaceTypeThenDebugSurfaceIsCreatedAndZeroed) {
DebugManagerStateRestore restorer; DebugManagerStateRestore restorer;
debugManager.flags.ForcePreferredAllocationMethod.set(static_cast<int32_t>(GfxMemoryAllocationMethod::useUmdSystemPtr)); debugManager.flags.ForcePreferredAllocationMethod.set(static_cast<int32_t>(GfxMemoryAllocationMethod::useUmdSystemPtr));
AllocationProperties debugSurfaceProperties{0, true, MemoryConstants::pageSize, AllocationType::debugContextSaveArea, false, false, 0b1011}; AllocationProperties debugSurfaceProperties{0, true, MemoryConstants::pageSize, AllocationType::debugContextSaveArea, false, false, 0b1011};
@@ -1206,9 +1206,8 @@ TEST_F(WddmMemoryManagerSimpleTest, GivenPhysicalDeviceMemoryAndVirtualMemoryThe
MemoryManager::AllocationStatus status; MemoryManager::AllocationStatus status;
auto allocation = memoryManager->allocatePhysicalLocalDeviceMemory(allocationData, status); auto allocation = memoryManager->allocatePhysicalLocalDeviceMemory(allocationData, status);
EXPECT_NE(nullptr, allocation); EXPECT_NE(nullptr, allocation);
auto res = memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(allocation, gpuRange, allocationData.size); EXPECT_TRUE(memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(allocation, gpuRange, allocationData.size));
EXPECT_TRUE(res); EXPECT_TRUE(memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(allocation, gpuRange, allocationData.size, osContext, 0u));
memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(allocation, gpuRange, allocationData.size, osContext, 0u);
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
} }
@@ -1229,9 +1228,8 @@ TEST_F(WddmMemoryManagerSimpleTest, GivenPhysicalHostMemoryAndVirtualMemoryThenM
rootDeviceIndices.pushUnique(0); rootDeviceIndices.pushUnique(0);
rootDeviceIndices.pushUnique(1); rootDeviceIndices.pushUnique(1);
MultiGraphicsAllocation multiGraphicsAllocations{2}; MultiGraphicsAllocation multiGraphicsAllocations{2};
auto res = memoryManager->mapPhysicalHostMemoryToVirtualMemory(rootDeviceIndices, multiGraphicsAllocations, allocation, gpuRange, allocationData.size); EXPECT_FALSE(memoryManager->mapPhysicalHostMemoryToVirtualMemory(rootDeviceIndices, multiGraphicsAllocations, allocation, gpuRange, allocationData.size));
EXPECT_FALSE(res); EXPECT_TRUE(memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocations, allocation, gpuRange, allocationData.size));
memoryManager->unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocations, allocation, gpuRange, allocationData.size);
} }
TEST_F(WddmMemoryManagerSimpleTest, givenZeroFenceValueOnSingleEngineRegisteredWhenHandleFenceCompletionIsCalledThenDoNotWaitOnCpu) { TEST_F(WddmMemoryManagerSimpleTest, givenZeroFenceValueOnSingleEngineRegisteredWhenHandleFenceCompletionIsCalledThenDoNotWaitOnCpu) {
@@ -4544,4 +4542,27 @@ TEST_F(WddmMemoryManagerBindlessHeapHelperCustomHeapAllocatorCfgTest, givenCusto
EXPECT_TRUE(allocation->isAllocInFrontWindowPool()); EXPECT_TRUE(allocation->isAllocInFrontWindowPool());
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
} }
TEST_F(WddmMemoryManagerSimpleTest, givenPhysicalDeviceMemoryAndVirtualMemoryThenUnmapFails) {
AllocationData allocationData;
allocationData.size = MemoryConstants::pageSize64k;
uint64_t gpuRange = 0x1234;
MemoryManager::AllocationStatus status;
auto allocation = memoryManager->allocatePhysicalLocalDeviceMemory(allocationData, status);
EXPECT_NE(nullptr, allocation);
EXPECT_TRUE(memoryManager->mapPhysicalDeviceMemoryToVirtualMemory(allocation, gpuRange, allocationData.size));
// Set the mock WDDM to return an error for reserveGpuVirtualAddress in the unMapPhysicalDeviceMemoryFromVirtualMemory call.
wddm->failReserveGpuVirtualAddress = true;
EXPECT_FALSE(memoryManager->unMapPhysicalDeviceMemoryFromVirtualMemory(allocation, gpuRange, allocationData.size, osContext, 0u));
wddm->failReserveGpuVirtualAddress = false;
// Complete the cleanup that was skipped in unMapPhysicalDeviceMemoryFromVirtualMemory.
allocation->setCpuPtrAndGpuAddress(nullptr, 0u);
allocation->setReservedAddressRange(nullptr, 0u);
WddmAllocation *wddmAllocation = reinterpret_cast<WddmAllocation *>(allocation);
wddmAllocation->setMappedPhysicalMemoryReservation(false);
memoryManager->freeGraphicsMemory(allocation);
}