Improve address alignment logic.

Resolves: NEO-7543

Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek 2022-11-24 12:10:05 +00:00 committed by Compute-Runtime-Automation
parent 31acfd8dbb
commit a104636b31
2 changed files with 5 additions and 5 deletions

View File

@ -1374,7 +1374,7 @@ uint64_t getGpuAddress(const AlignmentSelector &alignmentSelector, HeapAssigner
default: default:
AlignmentSelector::CandidateAlignment alignment = alignmentSelector.selectAlignment(sizeAllocated); AlignmentSelector::CandidateAlignment alignment = alignmentSelector.selectAlignment(sizeAllocated);
if (gfxPartition->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0 && !resource48Bit) { if (gfxPartition->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0 && !resource48Bit) {
auto alignSize = true; auto alignSize = sizeAllocated >= 8 * MemoryConstants::gigaByte && Math::isPow2(sizeAllocated);
if (DebugManager.flags.UseHighAlignmentForHeapExtended.get() != -1) { if (DebugManager.flags.UseHighAlignmentForHeapExtended.get() != -1) {
alignSize = !!DebugManager.flags.UseHighAlignmentForHeapExtended.get(); alignSize = !!DebugManager.flags.UseHighAlignmentForHeapExtended.get();
} }

View File

@ -5123,12 +5123,12 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenOversize
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
} }
TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenHeapExtendedWhenAllocationsAreMadeTheyAreAlignedToPreviousPowerOfTwo) { TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenAllocationsThatAreAlignedToPowerOf2InSizeAndAreGreaterThen8GBThenTheyAreAlignedToPreviousPowerOfTwoForGpuVirtualAddress) {
if (!memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED)) { if (!memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED)) {
GTEST_SKIP(); GTEST_SKIP();
} }
auto size = 16 * MemoryConstants::megaByte; auto size = 8 * MemoryConstants::gigaByte;
auto status = MemoryManager::AllocationStatus::Error; auto status = MemoryManager::AllocationStatus::Error;
AllocationData allocData; AllocationData allocData;
@ -5142,14 +5142,14 @@ TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenHeapExte
EXPECT_EQ(allocData.size, static_cast<DrmAllocation *>(allocation)->getBO()->peekSize()); EXPECT_EQ(allocData.size, static_cast<DrmAllocation *>(allocation)->getBO()->peekSize());
EXPECT_TRUE(allocation->getGpuAddress() % size == 0u); EXPECT_TRUE(allocation->getGpuAddress() % size == 0u);
size = 33 * MemoryConstants::megaByte; size = 8 * MemoryConstants::gigaByte + MemoryConstants::pageSize64k;
allocData.size = size; allocData.size = size;
auto allocation2 = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status); auto allocation2 = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status);
EXPECT_EQ(MemoryManager::AllocationStatus::Success, status); EXPECT_EQ(MemoryManager::AllocationStatus::Success, status);
ASSERT_NE(nullptr, allocation2); ASSERT_NE(nullptr, allocation2);
EXPECT_EQ(allocData.size, allocation2->getUnderlyingBufferSize()); EXPECT_EQ(allocData.size, allocation2->getUnderlyingBufferSize());
EXPECT_EQ(allocData.size, static_cast<DrmAllocation *>(allocation2)->getBO()->peekSize()); EXPECT_EQ(allocData.size, static_cast<DrmAllocation *>(allocation2)->getBO()->peekSize());
EXPECT_TRUE(allocation2->getGpuAddress() % Math::prevPowerOfTwo(size) == 0u); EXPECT_TRUE(allocation2->getGpuAddress() % MemoryConstants::pageSize2Mb == 0u);
memoryManager->freeGraphicsMemory(allocation); memoryManager->freeGraphicsMemory(allocation);
memoryManager->freeGraphicsMemory(allocation2); memoryManager->freeGraphicsMemory(allocation2);