fix: Check Unaligned before rounding size expected from reserve

Related-To: NEO-9127

- Fix the calc to check unaligned before rounding the expected size from
reserve memory.

Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
This commit is contained in:
Spruit, Neil R 2023-10-19 17:47:30 +00:00 committed by Compute-Runtime-Automation
parent 4dfa12c8eb
commit faaceaaff8
2 changed files with 64 additions and 1 deletions

View File

@ -1051,7 +1051,11 @@ size_t ContextImp::getPageAlignedSizeRequired(size_t size, NEO::HeapIndex *heapR
}
// Given a size larger than the pageSize, then round the size up to the next pageSize alignment if unaligned
if (size > pageSize) {
return ((size + pageSize) & (~pageSize));
if (size % pageSize > 0) {
return ((size + pageSize) & (~pageSize));
} else {
return size;
}
}
return pageSize;
}

View File

@ -1656,6 +1656,65 @@ TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithInvalidArgumentsThenU
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithInvalidMultiPageSizeInArgumentsThenUnsupportedSizeReturned) {
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);
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
void *pStart = 0x0;
size_t size = 64u;
void *ptr = nullptr;
size_t pagesize = 0u;
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
size = pagesize * 3 + 10;
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
NEO::MemoryManager *failingReserveMemoryManager = new ReserveMemoryManagerMock(*neoDevice->executionEnvironment);
auto memoryManager = driverHandle->getMemoryManager();
driverHandle->setMemoryManager(failingReserveMemoryManager);
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_SIZE, res);
driverHandle->setMemoryManager(memoryManager);
delete failingReserveMemoryManager;
res = contextImp->destroy();
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithValidMultiPageSizeInArgumentsThenSuccessReturned) {
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);
ContextImp *contextImp = static_cast<ContextImp *>(L0::Context::fromHandle(hContext));
void *pStart = 0x0;
size_t size = 64u;
void *ptr = nullptr;
size_t pagesize = 0u;
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
size = pagesize * 3;
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->freeVirtualMem(ptr, size);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->destroy();
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
TEST_F(ContextTest, whenCallingPhysicalMemoryAllocateWhenOutOfMemoryThenOutofMemoryReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};