Move kernel globals from SVM to USM device

With this change, module's data sections will be allocated in USM device pool
instead of SVM or USM shared.

Signed-off-by: Sebastian Luzynski <sebastian.jozef.luzynski@intel.com>
This commit is contained in:
Sebastian Luzynski
2022-09-12 10:02:36 +00:00
committed by Compute-Runtime-Automation
parent 24b1cfbff5
commit 706a5a7a8c
7 changed files with 54 additions and 50 deletions

View File

@@ -20,6 +20,7 @@ class MockGraphicsAllocation : public MemoryAllocation {
using MemoryAllocation::allocationOffset;
using MemoryAllocation::allocationType;
using MemoryAllocation::aubInfo;
using MemoryAllocation::cpuPtr;
using MemoryAllocation::gpuAddress;
using MemoryAllocation::MemoryAllocation;
using MemoryAllocation::memoryPool;

View File

@@ -5,6 +5,7 @@
*
*/
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "gtest/gtest.h"
@@ -19,3 +20,15 @@ TEST(MemoryManagerTest, WhenCallingIsAllocationTypeToCaptureThenScratchAndPrivat
EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(AllocationType::LINEAR_STREAM));
EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(AllocationType::INTERNAL_HEAP));
}
TEST(MemoryManagerTest, givenAllocationWithNullCpuPtrThenMemoryCopyToAllocationReturnsFalse) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
MockMemoryManager memoryManager(false, false, executionEnvironment);
constexpr uint8_t allocationSize = 10;
uint8_t allocationStorage[allocationSize] = {0};
MockGraphicsAllocation allocation{allocationStorage, allocationSize};
allocation.cpuPtr = nullptr;
constexpr size_t offset = 0;
EXPECT_FALSE(memoryManager.copyMemoryToAllocation(&allocation, offset, nullptr, 0));
}

View File

@@ -1495,7 +1495,7 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
size_t sourceAllocationSize = MemoryConstants::pageSize;
size_t destinationAllocationSize = sourceAllocationSize + offset;
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, destinationAllocationSize);
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize);
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
AllocationData allocData;
@@ -1507,19 +1507,19 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
allocData.storageInfo.memoryBanks.set(0, true);
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status);
ASSERT_NE(nullptr, allocation);
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
EXPECT_TRUE(ret);
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[0].get(), offset), dataToCopy.data(), dataToCopy.size()));
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManager.lockedLocalMemory[0].get(), offset), dataToCopy.data(), dataToCopy.size()));
drmMemoryManger.freeGraphicsMemory(allocation);
drmMemoryManager.freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationFailsToLockResourceThenItReturnsFalse) {
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, 0);
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, 0);
std::vector<uint8_t> dataToCopy(MemoryConstants::pageSize, 1u);
AllocationData allocData;
@@ -1530,13 +1530,13 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
allocData.rootDeviceIndex = rootDeviceIndex;
allocData.storageInfo.memoryBanks.set(0, true);
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status);
ASSERT_NE(nullptr, allocation);
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size());
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size());
EXPECT_FALSE(ret);
drmMemoryManger.freeGraphicsMemory(allocation);
drmMemoryManager.freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationWithCpuPtrThenAllocationIsFilledWithCorrectData) {
@@ -1544,18 +1544,18 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
size_t sourceAllocationSize = MemoryConstants::pageSize;
size_t destinationAllocationSize = sourceAllocationSize + offset;
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, false, 0);
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, false, 0);
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
auto allocation = drmMemoryManger.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, destinationAllocationSize, AllocationType::KERNEL_ISA, mockDeviceBitfield});
auto allocation = drmMemoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, destinationAllocationSize, AllocationType::KERNEL_ISA, mockDeviceBitfield});
ASSERT_NE(nullptr, allocation);
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
EXPECT_TRUE(ret);
EXPECT_EQ(0, memcmp(ptrOffset(allocation->getUnderlyingBuffer(), offset), dataToCopy.data(), dataToCopy.size()));
drmMemoryManger.freeGraphicsMemory(allocation);
drmMemoryManager.freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationOnAllMemoryBanksReturnsSuccessThenAllocationIsFilledWithCorrectData) {
@@ -1563,7 +1563,7 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
size_t sourceAllocationSize = MemoryConstants::pageSize;
size_t destinationAllocationSize = sourceAllocationSize + offset;
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, destinationAllocationSize);
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize);
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
AllocationData allocData;
@@ -1574,17 +1574,17 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
allocData.storageInfo.memoryBanks = maxNBitValue(MemoryBanks::getBankForLocalMemory(3));
allocData.rootDeviceIndex = rootDeviceIndex;
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status);
ASSERT_NE(nullptr, allocation);
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
EXPECT_TRUE(ret);
for (auto index = 0u; index < 3; index++) {
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[index].get(), offset), dataToCopy.data(), dataToCopy.size()));
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManager.lockedLocalMemory[index].get(), offset), dataToCopy.data(), dataToCopy.size()));
}
drmMemoryManger.freeGraphicsMemory(allocation);
drmMemoryManager.freeGraphicsMemory(allocation);
}
typedef Test<DrmMemoryManagerFixturePrelim> DrmMemoryManagerTestPrelim;

View File

@@ -62,7 +62,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh
device.getMemoryManager()->freeGraphicsMemory(alloc);
}
TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsSvmAllocation) {
TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsUsmDeviceAllocation) {
MockDevice device{};
REQUIRE_SVM_OR_SKIP(&device);
MockMemoryManager memoryManager;
@@ -77,10 +77,11 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
ASSERT_NE(nullptr, alloc);
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
ASSERT_EQ(MemoryConstants::pageSize64k, alloc->getUnderlyingBufferSize());
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
ASSERT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress()))));
EXPECT_FALSE(alloc->isMemObjectsAllocationWithWritableFlags());
EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags());
EXPECT_EQ(DEVICE_UNIFIED_MEMORY, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(alloc->getGpuAddress()))->memoryType);
svmAllocsManager.freeSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress())));
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalVariables, initData.data());
@@ -99,10 +100,11 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
ASSERT_NE(nullptr, alloc);
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
ASSERT_EQ(MemoryConstants::pageSize64k, alloc->getUnderlyingBufferSize());
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
EXPECT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress()))));
EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags());
EXPECT_EQ(DEVICE_UNIFIED_MEMORY, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(alloc->getGpuAddress()))->memoryType);
svmAllocsManager.freeSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress())));
}
@@ -181,26 +183,6 @@ TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreNotExportedAndAllocationFailsThenG
EXPECT_EQ(nullptr, alloc);
}
TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreExportedAndAllocationFailsThenGracefullyReturnsNullptr) {
MockDevice device{};
MockMemoryManager memoryManager{*device.getExecutionEnvironment()};
MockSVMAllocsManager svmAllocsManager(&memoryManager, false);
memoryManager.failInAllocateWithSizeAndAlignment = true;
WhiteBox<LinkerInput> linkerInputExportGlobalVariables;
WhiteBox<LinkerInput> linkerInputExportGlobalConstants;
linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true;
linkerInputExportGlobalConstants.traits.exportsGlobalConstants = true;
std::vector<uint8_t> initData;
initData.resize(64, 7U);
GraphicsAllocation *alloc = nullptr;
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
EXPECT_EQ(nullptr, alloc);
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
EXPECT_EQ(nullptr, alloc);
}
TEST(AllocateGlobalSurfaceTest, GivenAllocationInLocalMemoryWhichRequiresBlitterWhenAllocatingNonSvmAllocationThenBlitterIsUsed) {
REQUIRE_SVM_OR_SKIP(defaultHwInfo.get());
DebugManagerStateRestore restorer;