feature: support physical host memory

Related-To: NEO-11981

Signed-off-by: Wenbin Lu <wenbin.lu@intel.com>
This commit is contained in:
Wenbin Lu
2024-09-12 03:01:48 +00:00
committed by Compute-Runtime-Automation
parent cd629f04ed
commit 2ba80ce114
29 changed files with 893 additions and 109 deletions

View File

@@ -22,8 +22,6 @@
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "hw_cmds.h"
using namespace NEO;
TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) {
@@ -350,12 +348,26 @@ TEST(BaseMemoryManagerTest, givenDebugVariableSetWhenCompressedBufferIsCreatedTh
memoryManager.freeGraphicsMemory(allocationBufferCompressed);
}
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryThenPhysicalAllocationReturned) {
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsDeviceMemoryThenPhysicalAllocationReturned) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
MemoryManagerCreate<OsAgnosticMemoryManager> memoryManager(false, true, executionEnvironment);
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_NE(nullptr, allocationBuffer);
memoryManager.freeGraphicsMemory(allocationBuffer);
}
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsHostMemoryThenPhysicalAllocationReturned) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
MemoryManagerCreate<OsAgnosticMemoryManager> memoryManager(false, true, executionEnvironment);
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = false;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_NE(nullptr, allocationBuffer);
@@ -365,8 +377,8 @@ TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryThenPhysica
class MockMemoryManagerLocalMemory : public OsAgnosticMemoryManager {
public:
using OsAgnosticMemoryManager::localMemorySupported;
using OsAgnosticMemoryManager::mapPhysicalToVirtualMemory;
using OsAgnosticMemoryManager::unMapPhysicalToVirtualMemory;
using OsAgnosticMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory;
using OsAgnosticMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory;
MockMemoryManagerLocalMemory(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(executionEnvironment) {}
};
@@ -377,6 +389,7 @@ TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryWithoutLoca
memoryManager.localMemorySupported[0] = 0;
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_NE(nullptr, allocationBuffer);
@@ -392,25 +405,39 @@ class MockMemoryManagerNoLocalMemoryFail : public OsAgnosticMemoryManager {
}
};
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryWithoutLocalMemoryThenNullptrReturned) {
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsDeviceMemoryWithoutLocalMemoryThenNullptrReturned) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
MemoryManagerCreate<MockMemoryManagerNoLocalMemoryFail> memoryManager(false, true, executionEnvironment);
memoryManager.localMemorySupported[0] = 0;
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_EQ(nullptr, allocationBuffer);
}
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryWithLocalMemoryThenNullptrReturned) {
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsDeviceMemoryWithLocalMemoryThenNullptrReturned) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
MemoryManagerCreate<MockMemoryManagerNoLocalMemoryFail> memoryManager(false, true, executionEnvironment);
memoryManager.localMemorySupported[0] = 1;
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_EQ(nullptr, allocationBuffer);
}
TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsHostMemoryThenNullptrReturned) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
MemoryManagerCreate<MockMemoryManagerNoLocalMemoryFail> memoryManager(false, true, executionEnvironment);
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::bufferHostMemory, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMHostAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_EQ(nullptr, allocationBuffer);
@@ -418,8 +445,8 @@ TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryWithLocalMe
class MockAgnosticMemoryManager : public OsAgnosticMemoryManager {
public:
using OsAgnosticMemoryManager::mapPhysicalToVirtualMemory;
using OsAgnosticMemoryManager::unMapPhysicalToVirtualMemory;
using OsAgnosticMemoryManager::mapPhysicalDeviceMemoryToVirtualMemory;
using OsAgnosticMemoryManager::unMapPhysicalDeviceMemoryFromVirtualMemory;
MockAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(executionEnvironment) {}
};
@@ -429,14 +456,15 @@ TEST(BaseMemoryManagerTest, givenCalltoMapAndUnMapThenVirtialAddressSetUnSetOnPh
MemoryManagerCreate<MockAgnosticMemoryManager> memoryManager(false, true, executionEnvironment);
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_NE(nullptr, allocationBuffer);
uint64_t gpuAddress = 0x1234;
size_t size = 4096;
memoryManager.mapPhysicalToVirtualMemory(allocationBuffer, gpuAddress, size);
memoryManager.mapPhysicalDeviceMemoryToVirtualMemory(allocationBuffer, gpuAddress, size);
EXPECT_EQ(gpuAddress, allocationBuffer->getGpuAddress());
memoryManager.unMapPhysicalToVirtualMemory(allocationBuffer, gpuAddress, size, nullptr, 0u);
memoryManager.unMapPhysicalDeviceMemoryFromVirtualMemory(allocationBuffer, gpuAddress, size, nullptr, 0u);
EXPECT_NE(gpuAddress, allocationBuffer->getGpuAddress());
memoryManager.freeGraphicsMemory(allocationBuffer);
}
@@ -464,6 +492,7 @@ TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryWithFailedR
memoryManager.localMemorySupported[0] = 1;
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_EQ(nullptr, allocationBuffer);
@@ -477,6 +506,7 @@ TEST(BaseMemoryManagerTest, givenCalltoAllocatePhysicalGraphicsMemoryWithFailedL
memoryManager.failAllocate = true;
AllocationProperties allocPropertiesBuffer(mockRootDeviceIndex, 1, AllocationType::buffer, mockDeviceBitfield);
allocPropertiesBuffer.flags.isUSMDeviceAllocation = true;
auto allocationBuffer = memoryManager.allocatePhysicalGraphicsMemory(allocPropertiesBuffer);
EXPECT_EQ(nullptr, allocationBuffer);
@@ -941,4 +971,4 @@ TEST(MemoryManagerTest, givenDebugVariableToToggleGpuVaBitsWhenAllocatingResourc
memoryManager.freeGraphicsMemory(allocation);
}
}
}

View File

@@ -98,7 +98,7 @@ TEST(MemoryManagerTest, givenAllocationWithNullCpuPtrThenMemoryCopyToAllocationR
EXPECT_FALSE(memoryManager.copyMemoryToAllocation(&allocation, offset, nullptr, 0));
}
TEST(MemoryManagerTest, givenGraphicsAllocationWhenMapCalledThenDontResetCpuAddress) {
TEST(MemoryManagerTest, givenDeviceGraphicsAllocationWhenMapCalledThenDontResetCpuAddress) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
MockMemoryManager memoryManager(false, false, executionEnvironment);
@@ -106,15 +106,42 @@ TEST(MemoryManagerTest, givenGraphicsAllocationWhenMapCalledThenDontResetCpuAddr
MockGraphicsAllocation allocation{&allocationStorage, 1};
EXPECT_NE(nullptr, allocation.getUnderlyingBuffer());
EXPECT_TRUE(memoryManager.mapPhysicalToVirtualMemory(&allocation, 0x12300, 0));
EXPECT_TRUE(memoryManager.mapPhysicalDeviceMemoryToVirtualMemory(&allocation, 0x12300, 0));
EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer());
EXPECT_EQ(0x12300u, allocation.getGpuAddress());
memoryManager.unMapPhysicalToVirtualMemory(&allocation, 1, 1, nullptr, 0);
memoryManager.unMapPhysicalDeviceMemoryFromVirtualMemory(&allocation, 1, 1, nullptr, 0);
EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer());
EXPECT_EQ(0u, allocation.getGpuAddress());
}
TEST(MemoryManagerTest, givenHostGraphicsAllocationWhenMapCalledThenDontResetCpuAddress) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
MockMemoryManager memoryManager(false, false, executionEnvironment);
uint8_t allocationStorage = 0;
MockGraphicsAllocation allocation{&allocationStorage, 1};
EXPECT_NE(nullptr, allocation.getUnderlyingBuffer());
RootDeviceIndicesContainer rootDeviceIndices;
rootDeviceIndices.pushUnique(0);
rootDeviceIndices.pushUnique(1);
MultiGraphicsAllocation multiGraphicsAllocation{static_cast<uint32_t>(rootDeviceIndices.size())};
EXPECT_TRUE(memoryManager.mapPhysicalHostMemoryToVirtualMemory(rootDeviceIndices, multiGraphicsAllocation, &allocation, 0x12300, 0));
EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer());
EXPECT_NE(0x12300u, allocation.getGpuAddress());
for (size_t i = 0; i < rootDeviceIndices.size(); i++) {
EXPECT_NE(multiGraphicsAllocation.getGraphicsAllocation(static_cast<uint32_t>(i)), nullptr);
}
memoryManager.unMapPhysicalHostMemoryFromVirtualMemory(multiGraphicsAllocation, static_cast<GraphicsAllocation *>(&allocation), 0x12300, 0);
EXPECT_EQ(&allocationStorage, allocation.getUnderlyingBuffer());
EXPECT_NE(0x12300u, allocation.getGpuAddress());
for (size_t i = 0; i < rootDeviceIndices.size(); i++) {
EXPECT_EQ(multiGraphicsAllocation.getGraphicsAllocation(static_cast<uint32_t>(i)), nullptr);
}
}
TEST(MemoryManagerTest, givenDefaultMemoryManagerWhenItIsAskedForBudgetExhaustionThenFalseIsReturned) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
MockMemoryManager memoryManager(false, false, executionEnvironment);
@@ -3335,4 +3362,4 @@ TEST(MemoryManagerTest, WhenGettingExtraDevicePropertiesThenPropertiesRemainUnch
EXPECT_EQ(moduleId, 0u);
EXPECT_EQ(serverType, 0u);
}
}