feature: blocking makeResident for mapVirtualMem

Related-To: NEO-14547

Signed-off-by: Chandio, Bibrak Qamar <bibrak.qamar.chandio@intel.com>
This commit is contained in:
Chandio, Bibrak Qamar 2025-04-18 20:57:43 +00:00 committed by Compute-Runtime-Automation
parent 9d592b59bd
commit 58d8c907cd
3 changed files with 61 additions and 1 deletions

View File

@ -1355,7 +1355,7 @@ ze_result_t ContextImp::mapVirtualMem(const void *ptr,
virtualMemoryReservation->mappedAllocations.insert(std::pair<void *, NEO::MemoryMappedRange *>(const_cast<void *>(ptr), mappedRange));
this->driverHandle->getSvmAllocsManager()->insertSVMAlloc(allocData);
NEO::MemoryOperationsHandler *memoryOperationsIface = allocationNode->device->getRootDeviceEnvironment().memoryOperationsInterface.get();
auto success = memoryOperationsIface->makeResident(allocationNode->device, ArrayRef<NEO::GraphicsAllocation *>(&allocationNode->allocation, 1), false, false);
auto success = memoryOperationsIface->makeResident(allocationNode->device, ArrayRef<NEO::GraphicsAllocation *>(&allocationNode->allocation, 1), false, true);
ze_result_t res = changeMemoryOperationStatusToL0ResultType(success);
return res;
} else {

View File

@ -1308,6 +1308,64 @@ TEST_F(ContextTest, whenCallingMappingVirtualInterfacesOnPhysicalDeviceMemoryThe
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
TEST_F(ContextTest, whenCallingMappingVirtualInterfacesOnPhysicalDeviceMemoryThenMakeResidentIsCalledWithForcePagingFenceTrue) {
ze_context_handle_t hContext;
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>();
NEO::MockMemoryOperations *mockMemoryInterface = static_cast<NEO::MockMemoryOperations *>(
device->getNEODevice()->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface.get());
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
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);
EXPECT_GT(static_cast<int>(driverHandle->getMemoryManager()->getVirtualMemoryReservationMap().size()), 0);
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);
size_t offset = 0;
std::vector<ze_memory_access_attribute_t> memoryAccessFlags = {
ZE_MEMORY_ACCESS_ATTRIBUTE_READWRITE, ZE_MEMORY_ACCESS_ATTRIBUTE_READONLY,
ZE_MEMORY_ACCESS_ATTRIBUTE_NONE};
for (auto accessFlags : memoryAccessFlags) {
EXPECT_FALSE(mockMemoryInterface->makeResidentForcePagingFenceValue);
res = contextImp->mapVirtualMem(ptr, pagesize, mem, offset, accessFlags);
EXPECT_TRUE(mockMemoryInterface->makeResidentForcePagingFenceValue);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->unMapVirtualMem(ptr, pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
mockMemoryInterface->makeResidentForcePagingFenceValue = false;
}
res = contextImp->destroyPhysicalMem(mem);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->freeVirtualMem(ptr, pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->destroy();
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
TEST_F(ContextTest, whenCallingMappingVirtualInterfacesOnPhysicalHostMemoryThenSuccessIsReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};

View File

@ -45,6 +45,7 @@ class MockMemoryOperations : public MemoryOperationsHandler {
MemoryOperationsStatus makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations, bool isDummyExecNeeded, const bool forcePagingFence) override {
makeResidentCalledCount++;
makeResidentForcePagingFenceValue = forcePagingFence;
if (captureGfxAllocationsForMakeResident) {
for (auto &gfxAllocation : gfxAllocations) {
if (!gfxAllocation->getAubInfo().writeMemoryOnly) {
@ -117,6 +118,7 @@ class MockMemoryOperations : public MemoryOperationsHandler {
std::vector<GraphicsAllocation *> gfxAllocationsForMakeResident{};
int makeResidentCalledCount = 0;
bool makeResidentForcePagingFenceValue = false;
int evictCalledCount = 0;
int freeCalledCount = 0;
uint32_t isResidentCalledCount = 0;