From f08e552f4d43bcdc5eb75171a82047df2542f4f5 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Mon, 5 Dec 2022 08:22:46 +0000 Subject: [PATCH] Create multiple-BOs shared allocation in single lmem regions in non-acc mode Related-To: NEO-6839 Signed-off-by: Milczarek, Slawomir --- .../os_interface/linux/drm_memory_manager.cpp | 12 +++-- ...m_memory_manager_localmem_prelim_tests.cpp | 51 ++++++++++++++++++- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 38921a7fc1..3297b3f1f1 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1818,8 +1818,8 @@ void *DrmMemoryManager::lockBufferObject(BufferObject *bo) { return bo->peekLockedAddress(); } -void createMemoryRegionsForSharedAllocation(const HardwareInfo &hwInfo, MemoryInfo &memoryInfo, const AllocationData &allocationData, MemRegionsVec &memRegions) { - auto memoryBanks = allocationData.storageInfo.memoryBanks; +MemRegionsVec createMemoryRegionsForSharedAllocation(const HardwareInfo &hwInfo, MemoryInfo &memoryInfo, const AllocationData &allocationData, DeviceBitfield memoryBanks) { + MemRegionsVec memRegions; if (allocationData.usmInitialPlacement == GraphicsAllocation::UsmInitialPlacement::CPU) { // System memory region @@ -1845,6 +1845,8 @@ void createMemoryRegionsForSharedAllocation(const HardwareInfo &hwInfo, MemoryIn auto regionClassAndInstance = memoryInfo.getMemoryRegionClassAndInstance(0u, hwInfo); memRegions.push_back(regionClassAndInstance); } + + return memRegions; } GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const AllocationData &allocationData) { @@ -1879,9 +1881,6 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const auto pHwInfo = drm.getRootDeviceEnvironment().getHardwareInfo(); - MemRegionsVec memRegions; - createMemoryRegionsForSharedAllocation(*pHwInfo, *memoryInfo, allocationData, memRegions); - BufferObjects bos{}; auto currentAddress = cpuPointer; auto remainingSize = size; @@ -1895,6 +1894,9 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const break; } + auto memoryBanks = DebugManager.flags.CreateContextWithAccessCounters.get() > 0 ? allocationData.storageInfo.memoryBanks : DeviceBitfield(1 << handleId); + auto memRegions = createMemoryRegionsForSharedAllocation(*pHwInfo, *memoryInfo, allocationData, memoryBanks); + auto ret = memoryInfo->createGemExt(memRegions, currentSize, handle, {}, -1); if (ret) { diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp index 734617a245..4d30ba8e20 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_localmem_prelim_tests.cpp @@ -323,7 +323,53 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, whenCreateUnifiedMemoryAllocationT memoryManager->freeGraphicsMemory(allocation); } -TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, whenCreateUnifiedMemoryAllocationWithMultiMemoryRegionsThenGemCreateExtIsUsedWithAllRegions) { +TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, whenCreateUnifiedMemoryAllocationWithMultiMemoryRegionsThenGemCreateExtIsUsedWithSingleLmemRegions) { + std::vector regionInfo(3); + regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 1}; + regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)}; + regionInfo[2].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(1, 0)}; + + auto hwInfo = mock->getRootDeviceEnvironment().getMutableHardwareInfo(); + hwInfo->gtSystemInfo.MultiTileArchInfo.IsValid = 1; + hwInfo->gtSystemInfo.MultiTileArchInfo.TileCount = 3; + + mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock)); + mock->queryEngineInfo(); + mock->ioctlCallsCount = 0; + DeviceBitfield devices = 0b11; + AllocationProperties gpuProperties{ + 0u, + true, + MemoryConstants::megaByte, + AllocationType::UNIFIED_SHARED_MEMORY, + false, + devices}; + gpuProperties.alignment = MemoryConstants::pageSize64k; + gpuProperties.usmInitialPlacement = GraphicsAllocation::UsmInitialPlacement::CPU; + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(gpuProperties); + + ASSERT_NE(allocation, nullptr); + EXPECT_NE(static_cast(allocation)->getMmapPtr(), nullptr); + EXPECT_NE(static_cast(allocation)->getMmapSize(), 0u); + EXPECT_EQ(allocation->getAllocationOffset(), 0u); + + const auto &createExt = mock->context.receivedCreateGemExt.value(); + EXPECT_EQ(1u, createExt.handle); + + const auto &memRegions = createExt.memoryRegions; + ASSERT_EQ(memRegions.size(), 2u); + EXPECT_EQ(memRegions[0].memoryClass, drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM); + EXPECT_EQ(memRegions[0].memoryInstance, 1u); + EXPECT_EQ(memRegions[1].memoryClass, drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE); + EXPECT_EQ(memRegions[1].memoryInstance, regionInfo[2].region.memoryInstance); + + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenCreateContextWithAccessCountersWhenCreateUnifiedMemoryAllocationWithMultiMemoryRegionsThenGemCreateExtIsUsedWithAllRegions) { + DebugManagerStateRestore restorer; + DebugManager.flags.CreateContextWithAccessCounters.set(1); + std::vector regionInfo(4); regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 1}; regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)}; @@ -574,9 +620,10 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenUseKmdMigrationAndUsmInitialP unifiedMemoryManager.freeSVMAlloc(ptr); } -TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenUseKmdMigrationAndUsmInitialPlacementSetToGpuWhenCreateSharedUnifiedMemoryAllocationOnMultiTileArchitectureThenKmdMigratedAllocationIsCreatedWithCorrectRegionsOrder) { +TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenUseKmdMigrationWithAccessCountersAndUsmInitialPlacementSetToGpuWhenCreateSharedUnifiedMemoryAllocationOnMultiTileArchitectureThenKmdMigratedAllocationIsCreatedWithCorrectRegionsOrder) { DebugManagerStateRestore restorer; DebugManager.flags.UseKmdMigration.set(1); + DebugManager.flags.CreateContextWithAccessCounters.set(1); DebugManager.flags.UsmInitialPlacement.set(1); RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex}; std::map deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};