Skip to content

Commit bac85dd

Browse files
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: Luzynski, Sebastian Jozef <sebastian.jozef.luzynski@intel.com>
1 parent f5575a1 commit bac85dd

File tree

7 files changed

+54
-50
lines changed

7 files changed

+54
-50
lines changed

level_zero/core/test/unit_tests/sources/module/test_module.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ HWTEST_F(ModuleTranslationUnitTest, WhenCreatingFromZeBinaryThenLinkerInputIsCre
21782178
EXPECT_NE(nullptr, moduleTuValid.programInfo.linkerInput.get());
21792179
}
21802180

2181-
TEST_F(ModuleTranslationUnitTest, WhenCreatingFromZeBinaryAndGlobalsAreExportedThenTheirAllocationTypeIsSVM) {
2181+
TEST_F(ModuleTranslationUnitTest, WhenCreatingFromZeBinaryAndGlobalsAreExportedThenTheirAllocationTypeIsUSMDevice) {
21822182
std::string zeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===('
21832183
kernels:
21842184
- name : kernel
@@ -2217,8 +2217,14 @@ TEST_F(ModuleTranslationUnitTest, WhenCreatingFromZeBinaryAndGlobalsAreExportedT
22172217
zebin.data(), zebin.size());
22182218
auto retVal = moduleTu.processUnpackedBinary();
22192219
EXPECT_TRUE(retVal);
2220-
EXPECT_EQ(AllocationType::SVM_ZERO_COPY, moduleTu.globalConstBuffer->getAllocationType());
2221-
EXPECT_EQ(AllocationType::SVM_ZERO_COPY, moduleTu.globalVarBuffer->getAllocationType());
2220+
EXPECT_EQ(AllocationType::BUFFER, moduleTu.globalConstBuffer->getAllocationType());
2221+
EXPECT_EQ(AllocationType::BUFFER, moduleTu.globalVarBuffer->getAllocationType());
2222+
2223+
auto svmAllocsManager = device->getDriverHandle()->getSvmAllocsManager();
2224+
auto globalConstBufferAllocType = svmAllocsManager->getSVMAlloc(reinterpret_cast<void *>(moduleTu.globalConstBuffer->getGpuAddress()))->memoryType;
2225+
auto globalVarBufferAllocType = svmAllocsManager->getSVMAlloc(reinterpret_cast<void *>(moduleTu.globalVarBuffer->getGpuAddress()))->memoryType;
2226+
EXPECT_EQ(DEVICE_UNIFIED_MEMORY, globalConstBufferAllocType);
2227+
EXPECT_EQ(DEVICE_UNIFIED_MEMORY, globalVarBufferAllocType);
22222228
}
22232229

22242230
HWTEST_F(ModuleTranslationUnitTest, WhenBuildOptionsAreNullThenReuseExistingOptions) {

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ uint64_t DrmMemoryManager::getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t
12291229
}
12301230

12311231
bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) {
1232-
if (graphicsAllocation->getUnderlyingBuffer() || !isLocalMemorySupported(graphicsAllocation->getRootDeviceIndex())) {
1232+
if (graphicsAllocation->getUnderlyingBuffer()) {
12331233
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy);
12341234
}
12351235
return copyMemoryToAllocationBanks(graphicsAllocation, destinationOffset, memoryToCopy, sizeToCopy, maxNBitValue(graphicsAllocation->storageInfo.getNumBanks()));

shared/source/program/program_initialization.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc
3939
rootDeviceIndices.push_back(rootDeviceIndex);
4040
std::map<uint32_t, DeviceBitfield> subDeviceBitfields;
4141
subDeviceBitfields.insert({rootDeviceIndex, deviceBitfield});
42-
auto ptr = svmAllocManager->createSVMAlloc(size, svmProps, rootDeviceIndices, subDeviceBitfields);
42+
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, rootDeviceIndices, subDeviceBitfields);
43+
unifiedMemoryProperties.device = &device;
44+
auto ptr = svmAllocManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties);
4345
DEBUG_BREAK_IF(ptr == nullptr);
4446
if (ptr == nullptr) {
4547
return nullptr;
4648
}
47-
auto svmAlloc = svmAllocManager->getSVMAlloc(ptr);
48-
UNRECOVERABLE_IF(svmAlloc == nullptr);
49-
gpuAllocation = svmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
49+
auto usmAlloc = svmAllocManager->getSVMAlloc(ptr);
50+
UNRECOVERABLE_IF(usmAlloc == nullptr);
51+
gpuAllocation = usmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
5052
} else {
5153
auto allocationType = constant ? AllocationType::CONSTANT_SURFACE : AllocationType::GLOBAL_SURFACE;
5254
gpuAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex,

shared/test/common/mocks/mock_graphics_allocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MockGraphicsAllocation : public MemoryAllocation {
2020
using MemoryAllocation::allocationOffset;
2121
using MemoryAllocation::allocationType;
2222
using MemoryAllocation::aubInfo;
23+
using MemoryAllocation::cpuPtr;
2324
using MemoryAllocation::gpuAddress;
2425
using MemoryAllocation::MemoryAllocation;
2526
using MemoryAllocation::memoryPool;

shared/test/unit_test/memory_manager/memory_manager_tests.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77

8+
#include "shared/test/common/mocks/mock_graphics_allocation.h"
89
#include "shared/test/common/mocks/mock_memory_manager.h"
910

1011
#include "gtest/gtest.h"
@@ -19,3 +20,15 @@ TEST(MemoryManagerTest, WhenCallingIsAllocationTypeToCaptureThenScratchAndPrivat
1920
EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(AllocationType::LINEAR_STREAM));
2021
EXPECT_TRUE(mockMemoryManager.isAllocationTypeToCapture(AllocationType::INTERNAL_HEAP));
2122
}
23+
24+
TEST(MemoryManagerTest, givenAllocationWithNullCpuPtrThenMemoryCopyToAllocationReturnsFalse) {
25+
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
26+
MockMemoryManager memoryManager(false, false, executionEnvironment);
27+
constexpr uint8_t allocationSize = 10;
28+
uint8_t allocationStorage[allocationSize] = {0};
29+
MockGraphicsAllocation allocation{allocationStorage, allocationSize};
30+
allocation.cpuPtr = nullptr;
31+
constexpr size_t offset = 0;
32+
33+
EXPECT_FALSE(memoryManager.copyMemoryToAllocation(&allocation, offset, nullptr, 0));
34+
}

shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
14951495
size_t sourceAllocationSize = MemoryConstants::pageSize;
14961496
size_t destinationAllocationSize = sourceAllocationSize + offset;
14971497

1498-
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, destinationAllocationSize);
1498+
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize);
14991499
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
15001500

15011501
AllocationData allocData;
@@ -1507,19 +1507,19 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
15071507
allocData.storageInfo.memoryBanks.set(0, true);
15081508

15091509
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
1510-
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
1510+
auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status);
15111511
ASSERT_NE(nullptr, allocation);
15121512

1513-
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
1513+
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
15141514
EXPECT_TRUE(ret);
15151515

1516-
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[0].get(), offset), dataToCopy.data(), dataToCopy.size()));
1516+
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManager.lockedLocalMemory[0].get(), offset), dataToCopy.data(), dataToCopy.size()));
15171517

1518-
drmMemoryManger.freeGraphicsMemory(allocation);
1518+
drmMemoryManager.freeGraphicsMemory(allocation);
15191519
}
15201520

15211521
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationFailsToLockResourceThenItReturnsFalse) {
1522-
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, 0);
1522+
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, 0);
15231523
std::vector<uint8_t> dataToCopy(MemoryConstants::pageSize, 1u);
15241524

15251525
AllocationData allocData;
@@ -1530,40 +1530,40 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
15301530
allocData.rootDeviceIndex = rootDeviceIndex;
15311531
allocData.storageInfo.memoryBanks.set(0, true);
15321532
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
1533-
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
1533+
auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status);
15341534
ASSERT_NE(nullptr, allocation);
15351535

1536-
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size());
1536+
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, 0, dataToCopy.data(), dataToCopy.size());
15371537
EXPECT_FALSE(ret);
15381538

1539-
drmMemoryManger.freeGraphicsMemory(allocation);
1539+
drmMemoryManager.freeGraphicsMemory(allocation);
15401540
}
15411541

15421542
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationWithCpuPtrThenAllocationIsFilledWithCorrectData) {
15431543
size_t offset = 3;
15441544
size_t sourceAllocationSize = MemoryConstants::pageSize;
15451545
size_t destinationAllocationSize = sourceAllocationSize + offset;
15461546

1547-
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, false, 0);
1547+
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, false, 0);
15481548
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
15491549

1550-
auto allocation = drmMemoryManger.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, destinationAllocationSize, AllocationType::KERNEL_ISA, mockDeviceBitfield});
1550+
auto allocation = drmMemoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, destinationAllocationSize, AllocationType::KERNEL_ISA, mockDeviceBitfield});
15511551
ASSERT_NE(nullptr, allocation);
15521552

1553-
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
1553+
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
15541554
EXPECT_TRUE(ret);
15551555

15561556
EXPECT_EQ(0, memcmp(ptrOffset(allocation->getUnderlyingBuffer(), offset), dataToCopy.data(), dataToCopy.size()));
15571557

1558-
drmMemoryManger.freeGraphicsMemory(allocation);
1558+
drmMemoryManager.freeGraphicsMemory(allocation);
15591559
}
15601560

15611561
TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationOnAllMemoryBanksReturnsSuccessThenAllocationIsFilledWithCorrectData) {
15621562
size_t offset = 3;
15631563
size_t sourceAllocationSize = MemoryConstants::pageSize;
15641564
size_t destinationAllocationSize = sourceAllocationSize + offset;
15651565

1566-
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManger(*executionEnvironment, true, destinationAllocationSize);
1566+
DrmMemoryManagerToTestCopyMemoryToAllocation drmMemoryManager(*executionEnvironment, true, destinationAllocationSize);
15671567
std::vector<uint8_t> dataToCopy(sourceAllocationSize, 1u);
15681568

15691569
AllocationData allocData;
@@ -1574,17 +1574,17 @@ TEST_F(DrmMemoryManagerCopyMemoryToAllocationPrelimTest, givenDrmMemoryManagerWh
15741574
allocData.storageInfo.memoryBanks = maxNBitValue(MemoryBanks::getBankForLocalMemory(3));
15751575
allocData.rootDeviceIndex = rootDeviceIndex;
15761576
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
1577-
auto allocation = drmMemoryManger.allocateGraphicsMemoryInDevicePool(allocData, status);
1577+
auto allocation = drmMemoryManager.allocateGraphicsMemoryInDevicePool(allocData, status);
15781578
ASSERT_NE(nullptr, allocation);
15791579

1580-
auto ret = drmMemoryManger.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
1580+
auto ret = drmMemoryManager.copyMemoryToAllocation(allocation, offset, dataToCopy.data(), dataToCopy.size());
15811581
EXPECT_TRUE(ret);
15821582

15831583
for (auto index = 0u; index < 3; index++) {
1584-
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManger.lockedLocalMemory[index].get(), offset), dataToCopy.data(), dataToCopy.size()));
1584+
EXPECT_EQ(0, memcmp(ptrOffset(drmMemoryManager.lockedLocalMemory[index].get(), offset), dataToCopy.data(), dataToCopy.size()));
15851585
}
15861586

1587-
drmMemoryManger.freeGraphicsMemory(allocation);
1587+
drmMemoryManager.freeGraphicsMemory(allocation);
15881588
}
15891589

15901590
typedef Test<DrmMemoryManagerFixturePrelim> DrmMemoryManagerTestPrelim;

shared/test/unit_test/program/program_initialization_tests.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreNotExportedTh
6262
device.getMemoryManager()->freeGraphicsMemory(alloc);
6363
}
6464

65-
TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsSvmAllocation) {
65+
TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenMemoryIsAllocatedAsUsmDeviceAllocation) {
6666
MockDevice device{};
6767
REQUIRE_SVM_OR_SKIP(&device);
6868
MockMemoryManager memoryManager;
@@ -77,10 +77,11 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM
7777

7878
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
7979
ASSERT_NE(nullptr, alloc);
80-
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
80+
ASSERT_EQ(MemoryConstants::pageSize64k, alloc->getUnderlyingBufferSize());
8181
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
8282
ASSERT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress()))));
83-
EXPECT_FALSE(alloc->isMemObjectsAllocationWithWritableFlags());
83+
EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags());
84+
EXPECT_EQ(DEVICE_UNIFIED_MEMORY, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(alloc->getGpuAddress()))->memoryType);
8485
svmAllocsManager.freeSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress())));
8586

8687
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalVariables, initData.data());
@@ -99,10 +100,11 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM
99100

100101
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
101102
ASSERT_NE(nullptr, alloc);
102-
ASSERT_EQ(initData.size(), alloc->getUnderlyingBufferSize());
103+
ASSERT_EQ(MemoryConstants::pageSize64k, alloc->getUnderlyingBufferSize());
103104
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
104105
EXPECT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress()))));
105106
EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags());
107+
EXPECT_EQ(DEVICE_UNIFIED_MEMORY, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(alloc->getGpuAddress()))->memoryType);
106108
svmAllocsManager.freeSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress())));
107109
}
108110

@@ -181,26 +183,6 @@ TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreNotExportedAndAllocationFailsThenG
181183
EXPECT_EQ(nullptr, alloc);
182184
}
183185

184-
TEST(AllocateGlobalSurfaceTest, WhenGlobalsAreExportedAndAllocationFailsThenGracefullyReturnsNullptr) {
185-
MockDevice device{};
186-
MockMemoryManager memoryManager{*device.getExecutionEnvironment()};
187-
MockSVMAllocsManager svmAllocsManager(&memoryManager, false);
188-
memoryManager.failInAllocateWithSizeAndAlignment = true;
189-
WhiteBox<LinkerInput> linkerInputExportGlobalVariables;
190-
WhiteBox<LinkerInput> linkerInputExportGlobalConstants;
191-
linkerInputExportGlobalVariables.traits.exportsGlobalVariables = true;
192-
linkerInputExportGlobalConstants.traits.exportsGlobalConstants = true;
193-
std::vector<uint8_t> initData;
194-
initData.resize(64, 7U);
195-
GraphicsAllocation *alloc = nullptr;
196-
197-
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), true /* constant */, &linkerInputExportGlobalConstants, initData.data());
198-
EXPECT_EQ(nullptr, alloc);
199-
200-
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), false /* constant */, &linkerInputExportGlobalVariables, initData.data());
201-
EXPECT_EQ(nullptr, alloc);
202-
}
203-
204186
TEST(AllocateGlobalSurfaceTest, GivenAllocationInLocalMemoryWhichRequiresBlitterWhenAllocatingNonSvmAllocationThenBlitterIsUsed) {
205187
REQUIRE_SVM_OR_SKIP(defaultHwInfo.get());
206188
DebugManagerStateRestore restorer;

0 commit comments

Comments
 (0)