fix: Return pageSize/Heap for reservation based on the size and devices

Related-To: NEO-9127,NEO-9142

- Change the heap/pageSize used based on the size of the reservation
required and the device heaps available.
- Return the page size required based on the size requested by the user
for virtual reservation and the devices on the system.
- Check the size passed in by the user in memory map and physical memory
allocation is valid for the heap and page size that is required.

Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
This commit is contained in:
Spruit, Neil R
2023-10-12 00:51:45 +00:00
committed by Compute-Runtime-Automation
parent 5a4fa180d6
commit 456f07212d
22 changed files with 434 additions and 57 deletions

View File

@@ -8,6 +8,7 @@
#pragma once
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/memory_manager/gfx_partition.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/mocks/mock_compilers.h"
#include "shared/test/common/mocks/mock_device.h"
@@ -411,6 +412,13 @@ class MemoryManagerIpcMock : public NEO::MemoryManager {
AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override {
return {};
}
AddressRange reserveGpuAddressOnHeap(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex, HeapIndex heap, size_t alignment) override {
return {};
}
size_t selectAlignmentAndHeap(size_t size, HeapIndex *heap) override {
*heap = HeapIndex::HEAP_STANDARD;
return MemoryConstants::pageSize64k;
}
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
@@ -629,6 +637,13 @@ class MemoryManagerIpcImplicitScalingMock : public NEO::MemoryManager {
AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override {
return {};
}
AddressRange reserveGpuAddressOnHeap(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex, HeapIndex heap, size_t alignment) override {
return {};
}
size_t selectAlignmentAndHeap(size_t size, HeapIndex *heap) override {
*heap = HeapIndex::HEAP_STANDARD;
return MemoryConstants::pageSize64k;
}
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };

View File

@@ -8,6 +8,7 @@
#include "shared/source/built_ins/sip.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/helpers/blit_properties.h"
#include "shared/source/memory_manager/gfx_partition.h"
#include "shared/test/common/mocks/mock_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_compilers.h"
#include "shared/test/common/mocks/mock_cpu_page_fault_manager.h"
@@ -1047,13 +1048,13 @@ TEST_F(ContextTest, whenCallingQueryVirtualMemPageSizeCorrectAlignmentIsReturned
pagesize = 0u;
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_EQ(pagesize, MemoryConstants::pageSize2M / 2);
EXPECT_EQ(pagesize, MemoryConstants::pageSize64k);
size = MemoryConstants::pageSize2M + 1000;
pagesize = 0u;
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
EXPECT_EQ(pagesize, MemoryConstants::pageSize2M);
EXPECT_EQ(pagesize, MemoryConstants::pageSize64k);
res = contextImp->destroy();
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
@@ -1350,28 +1351,6 @@ TEST_F(ContextTest, whenCallingVirtualMemoryFreeWithInvalidValuesThenFailuresRet
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithInvalidArgumentsThenFailureReturned) {
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;
res = contextImp->reserveVirtualMem(pStart, size, &ptr);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_SIZE, res);
size_t pagesize = 0u;
res = contextImp->queryVirtualMemPageSize(device, size, &pagesize);
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
res = contextImp->destroy();
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
class ReserveMemoryManagerMock : public NEO::MemoryManager {
public:
ReserveMemoryManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MemoryManager(executionEnvironment) {}
@@ -1393,6 +1372,16 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager {
}
return AddressRange{requiredStartAddress, size};
}
AddressRange reserveGpuAddressOnHeap(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex, HeapIndex heap, size_t alignment) override {
if (failReserveGpuAddress) {
return {};
}
return AddressRange{requiredStartAddress, size};
}
size_t selectAlignmentAndHeap(size_t size, HeapIndex *heap) override {
*heap = HeapIndex::HEAP_STANDARD;
return MemoryConstants::pageSize64k;
}
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
@@ -1638,6 +1627,35 @@ TEST_F(ContextTest, whenCallingVirtualMemoryReservationWhenOutOfMemoryThenOutOfM
EXPECT_EQ(ZE_RESULT_SUCCESS, res);
}
TEST_F(ContextTest, whenCallingVirtualMemoryReservationWithInvalidArgumentsThenUnsupportedSizeReturned) {
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);
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, whenCallingPhysicalMemoryAllocateWhenOutOfMemoryThenOutofMemoryReturned) {
ze_context_handle_t hContext;
ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0};

View File

@@ -8,6 +8,7 @@
#include "shared/source/built_ins/sip.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/memory_manager/gfx_partition.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "shared/test/common/mocks/mock_compilers.h"
@@ -76,6 +77,13 @@ class MemoryManagerEventPoolFailMock : public NEO::MemoryManager {
AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override {
return {};
}
AddressRange reserveGpuAddressOnHeap(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex, HeapIndex heap, size_t alignment) override {
return {};
}
size_t selectAlignmentAndHeap(size_t size, HeapIndex *heap) override {
*heap = HeapIndex::HEAP_STANDARD;
return MemoryConstants::pageSize64k;
}
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };

View File

@@ -6,6 +6,7 @@
*/
#include "shared/source/built_ins/sip.h"
#include "shared/source/memory_manager/gfx_partition.h"
#include "shared/source/os_interface/linux/drm_allocation.h"
#include "shared/source/os_interface/linux/drm_buffer_object.h"
#include "shared/source/os_interface/linux/drm_gem_close_worker.h"
@@ -74,6 +75,13 @@ class MemoryManagerIpcImplicitScalingObtainFdMock : public NEO::DrmMemoryManager
AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override {
return {};
}
AddressRange reserveGpuAddressOnHeap(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex, HeapIndex heap, size_t alignment) override {
return {};
}
size_t selectAlignmentAndHeap(size_t size, HeapIndex *heap) override {
*heap = HeapIndex::HEAP_STANDARD;
return MemoryConstants::pageSize64k;
}
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };
@@ -483,6 +491,13 @@ class MemoryManagerIpcObtainFdMock : public NEO::DrmMemoryManager {
AddressRange reserveGpuAddress(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override {
return {};
}
AddressRange reserveGpuAddressOnHeap(const uint64_t requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex, HeapIndex heap, size_t alignment) override {
return {};
}
size_t selectAlignmentAndHeap(size_t size, HeapIndex *heap) override {
*heap = HeapIndex::HEAP_STANDARD;
return MemoryConstants::pageSize64k;
}
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
NEO::GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const NEO::AllocationData &allocationData) override { return nullptr; };
NEO::GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const NEO::AllocationData &allocationData) override { return nullptr; };