mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-22 10:17:01 +08:00
Introduced standard heap with 2MB alignment on Linux
Related-To: NEO-5507 Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
c1cabb505a
commit
049166688c
@@ -80,7 +80,8 @@ void testGfxPartition(MockGfxPartition &gfxPartition, uint64_t gfxBase, uint64_t
|
||||
gfxBase += sizeHeap32;
|
||||
}
|
||||
|
||||
uint64_t sizeStandard = (gfxTop - gfxBase) >> 1;
|
||||
uint32_t numStandardHeaps = static_cast<uint32_t>(HeapIndex::HEAP_STANDARD2MB) - static_cast<uint32_t>(HeapIndex::HEAP_STANDARD) + 1;
|
||||
uint64_t sizeStandard = alignDown((gfxTop - gfxBase) / numStandardHeaps, GfxPartition::heapGranularity);
|
||||
|
||||
EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_STANDARD));
|
||||
auto heapStandardBase = gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD);
|
||||
@@ -94,11 +95,19 @@ void testGfxPartition(MockGfxPartition &gfxPartition, uint64_t gfxBase, uint64_t
|
||||
auto heapStandard64KbBase = gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD64KB);
|
||||
auto heapStandard64KbSize = gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD64KB);
|
||||
EXPECT_TRUE(isAligned<GfxPartition::heapGranularity>(heapStandard64KbBase));
|
||||
|
||||
EXPECT_EQ(heapStandard64KbBase, heapStandardBase + heapStandardSize);
|
||||
EXPECT_EQ(heapStandard64KbSize, heapStandardSize);
|
||||
EXPECT_EQ(heapStandard64KbBase + heapStandard64KbSize, gfxTop);
|
||||
EXPECT_EQ(gfxBase + sizeStandard, gfxTop);
|
||||
|
||||
gfxBase += sizeStandard;
|
||||
EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_STANDARD2MB));
|
||||
auto heapStandard2MbBase = gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD2MB);
|
||||
auto heapStandard2MbSize = gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD2MB);
|
||||
EXPECT_TRUE(isAligned<GfxPartition::heapGranularity>(heapStandard2MbBase));
|
||||
EXPECT_EQ(heapStandard2MbBase, heapStandard64KbBase + heapStandard64KbSize);
|
||||
EXPECT_EQ(heapStandard2MbSize, heapStandard64KbSize);
|
||||
|
||||
EXPECT_LE(heapStandard2MbBase + heapStandard2MbSize, gfxTop);
|
||||
EXPECT_LE(gfxBase + sizeStandard, gfxTop);
|
||||
|
||||
EXPECT_EQ(gfxPartition.getHeapMinimalAddress(HeapIndex::HEAP_INTERNAL_FRONT_WINDOW), gfxPartition.getHeapBase(HeapIndex::HEAP_INTERNAL_FRONT_WINDOW));
|
||||
EXPECT_EQ(gfxPartition.getHeapMinimalAddress(HeapIndex::HEAP_INTERNAL_DEVICE_FRONT_WINDOW), gfxPartition.getHeapBase(HeapIndex::HEAP_INTERNAL_DEVICE_FRONT_WINDOW));
|
||||
@@ -113,7 +122,9 @@ void testGfxPartition(MockGfxPartition &gfxPartition, uint64_t gfxBase, uint64_t
|
||||
|
||||
const bool isInternalHeapType = heap == HeapIndex::HEAP_INTERNAL || heap == HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY;
|
||||
|
||||
if (isInternalHeapType) {
|
||||
if (heap == HeapIndex::HEAP_SVM) {
|
||||
EXPECT_EQ(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap));
|
||||
} else if (isInternalHeapType) {
|
||||
EXPECT_EQ(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap) + GfxPartition::internalFrontWindowPoolSize);
|
||||
} else {
|
||||
EXPECT_GT(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap));
|
||||
@@ -202,7 +213,8 @@ TEST(GfxPartitionTest, GivenFullRange48BitSvmHeap64KbSplitWhenTestingGfxPartitio
|
||||
uint64_t gfxBase = is32bit ? MemoryConstants::maxSvmAddress + 1 : maxNBitValue(48 - 1) + 1;
|
||||
uint64_t gfxTop = maxNBitValue(48) + 1;
|
||||
|
||||
auto heapStandardSize = (gfxTop - gfxBase - 4 * sizeHeap32) / 2;
|
||||
auto numStandardHeaps = static_cast<uint32_t>(HeapIndex::HEAP_STANDARD2MB) - static_cast<uint32_t>(HeapIndex::HEAP_STANDARD) + 1;
|
||||
auto heapStandardSize = alignDown((gfxTop - gfxBase - 4 * sizeHeap32) / numStandardHeaps, GfxPartition::heapGranularity);
|
||||
auto heapStandard64KBSize = alignDown(heapStandardSize / numRootDevices, GfxPartition::heapGranularity);
|
||||
|
||||
EXPECT_EQ(heapStandard64KBSize, gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD64KB));
|
||||
@@ -219,7 +231,8 @@ TEST(GfxPartitionTest, GivenFullRange47BitSvmHeap64KbSplitWhenTestingGfxPartitio
|
||||
uint64_t gfxBase = is32bit ? MemoryConstants::maxSvmAddress + 1 : (uint64_t)gfxPartition.getReservedCpuAddressRange();
|
||||
uint64_t gfxTop = is32bit ? maxNBitValue(47) + 1 : gfxBase + gfxPartition.getReservedCpuAddressRangeSize();
|
||||
|
||||
auto heapStandardSize = ((gfxTop - gfxBase) - 4 * sizeHeap32) / 2;
|
||||
auto numStandardHeaps = static_cast<uint32_t>(HeapIndex::HEAP_STANDARD2MB) - static_cast<uint32_t>(HeapIndex::HEAP_STANDARD) + 1;
|
||||
auto heapStandardSize = alignDown((gfxTop - gfxBase - 4 * sizeHeap32) / numStandardHeaps, GfxPartition::heapGranularity);
|
||||
auto heapStandard64KBSize = alignDown(heapStandardSize / numRootDevices, GfxPartition::heapGranularity);
|
||||
|
||||
EXPECT_EQ(heapStandard64KBSize, gfxPartition.getHeapSize(HeapIndex::HEAP_STANDARD64KB));
|
||||
|
||||
@@ -581,17 +581,15 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenNotSetUseSystemMemoryWhenGraphicsAl
|
||||
EXPECT_NE(0u, gpuAddress);
|
||||
|
||||
auto heap = HeapIndex::HEAP_STANDARD64KB;
|
||||
auto sizeReserved = alignUp(sizeAligned, 2 * MemoryConstants::megaByte);
|
||||
if (memoryManager->getGfxPartition(0)->getHeapLimit(HeapIndex::HEAP_EXTENDED)) {
|
||||
heap = HeapIndex::HEAP_EXTENDED;
|
||||
sizeReserved = alignUp(sizeAligned, MemoryConstants::pageSize);
|
||||
}
|
||||
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapBase(heap)), gpuAddress);
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(0)->getHeapLimit(heap)), gpuAddress);
|
||||
EXPECT_EQ(0u, allocation->getGpuBaseAddress());
|
||||
EXPECT_EQ(sizeAligned, allocation->getUnderlyingBufferSize());
|
||||
EXPECT_EQ(gpuAddress, reinterpret_cast<uint64_t>(allocation->getReservedAddressPtr()));
|
||||
EXPECT_EQ(sizeReserved, allocation->getReservedAddressSize());
|
||||
EXPECT_EQ(sizeAligned, allocation->getReservedAddressSize());
|
||||
|
||||
EXPECT_EQ(1u, allocation->storageInfo.getNumBanks());
|
||||
EXPECT_EQ(allocData.storageInfo.getMemoryBanks(), allocation->storageInfo.getMemoryBanks());
|
||||
@@ -642,7 +640,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenNotSetUseSystemMemoryWhenGraphicsAl
|
||||
EXPECT_EQ(0u, allocation->getGpuBaseAddress());
|
||||
EXPECT_EQ(sizeAligned, allocation->getUnderlyingBufferSize());
|
||||
EXPECT_EQ(gpuAddress, reinterpret_cast<uint64_t>(allocation->getReservedAddressPtr()));
|
||||
EXPECT_EQ(alignUp(sizeAligned, 2 * MemoryConstants::megaByte), allocation->getReservedAddressSize());
|
||||
EXPECT_EQ(sizeAligned, allocation->getReservedAddressSize());
|
||||
|
||||
EXPECT_EQ(1u, allocation->storageInfo.getNumBanks());
|
||||
EXPECT_EQ(allocData.storageInfo.getMemoryBanks(), allocation->storageInfo.getMemoryBanks());
|
||||
@@ -1254,7 +1252,7 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenGraphicsAllocationInDevicePoolIsAll
|
||||
EXPECT_NE(0u, gpuAddress);
|
||||
EXPECT_EQ(sizeAlignedTo64KB, allocation->getUnderlyingBufferSize());
|
||||
EXPECT_EQ(gpuAddress, reinterpret_cast<uint64_t>(allocation->getReservedAddressPtr()));
|
||||
EXPECT_EQ(alignUp(sizeAlignedTo64KB, 2 * MemoryConstants::megaByte), allocation->getReservedAddressSize());
|
||||
EXPECT_EQ(sizeAlignedTo64KB, allocation->getReservedAddressSize());
|
||||
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(allocation);
|
||||
auto bo = drmAllocation->getBO();
|
||||
|
||||
@@ -1061,7 +1061,7 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenCreatingGraphicsAllocation64k
|
||||
EXPECT_EQ(nullptr, allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenRequiresStandard64KBHeapSetToFalseThenStandardHeapIsUsed) {
|
||||
TEST_F(DrmMemoryManagerTest, givenRequiresStandard2MBHeapSetToFalseThenStandardHeapIsUsed) {
|
||||
const uint32_t rootDeviceIndex = 0;
|
||||
size_t bufferSize = 4096u;
|
||||
uint64_t range = memoryManager->acquireGpuRange(bufferSize, false, rootDeviceIndex, false);
|
||||
@@ -1070,13 +1070,13 @@ TEST_F(DrmMemoryManagerTest, givenRequiresStandard64KBHeapSetToFalseThenStandard
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD)), range);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenRequiresStandard64KBHeapSetToTrueThenStandard64KBHeapIsUsed) {
|
||||
TEST_F(DrmMemoryManagerTest, givenRequiresStandard2MBHeapSetToTrueThenStandard2MBHeapIsUsed) {
|
||||
const uint32_t rootDeviceIndex = 0;
|
||||
size_t bufferSize = 4096u;
|
||||
uint64_t range = memoryManager->acquireGpuRange(bufferSize, false, rootDeviceIndex, true);
|
||||
|
||||
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), range);
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), range);
|
||||
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD2MB)), range);
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD2MB)), range);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, GivenShareableEnabledWhenAskedToCreateGraphicsAllocationThenValidAllocationIsReturnedAndStandard64KBHeapIsUsed) {
|
||||
@@ -1090,8 +1090,8 @@ TEST_F(DrmMemoryManagerTest, GivenShareableEnabledWhenAskedToCreateGraphicsAlloc
|
||||
EXPECT_NE(nullptr, allocation);
|
||||
EXPECT_NE(0u, allocation->getGpuAddress());
|
||||
|
||||
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(allocation->getRootDeviceIndex())->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), allocation->getGpuAddress());
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(allocation->getRootDeviceIndex())->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), allocation->getGpuAddress());
|
||||
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(allocation->getRootDeviceIndex())->getHeapBase(HeapIndex::HEAP_STANDARD2MB)), allocation->getGpuAddress());
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(allocation->getRootDeviceIndex())->getHeapLimit(HeapIndex::HEAP_STANDARD2MB)), allocation->getGpuAddress());
|
||||
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
@@ -2008,8 +2008,8 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory
|
||||
EXPECT_EQ(this->mock->inputFd, static_cast<int32_t>(handle));
|
||||
|
||||
auto gpuAddress = graphicsAllocation->getGpuAddress();
|
||||
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), gpuAddress);
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), gpuAddress);
|
||||
EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD2MB)), gpuAddress);
|
||||
EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD2MB)), gpuAddress);
|
||||
|
||||
DrmAllocation *drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
|
||||
auto bo = drmAllocation->getBO();
|
||||
|
||||
@@ -184,14 +184,20 @@ bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
|
||||
gfxBase += gfxHeap32Size;
|
||||
}
|
||||
|
||||
uint64_t gfxStandardSize = alignDown((gfxTop - gfxBase) >> 1, heapGranularity);
|
||||
uint32_t numStandardHeaps = static_cast<uint32_t>(HeapIndex::HEAP_STANDARD2MB) - static_cast<uint32_t>(HeapIndex::HEAP_STANDARD) + 1;
|
||||
uint64_t gfxStandardSize = alignDown((gfxTop - gfxBase) / numStandardHeaps, heapGranularity);
|
||||
|
||||
heapInit(HeapIndex::HEAP_STANDARD, gfxBase, gfxStandardSize);
|
||||
gfxBase += gfxStandardSize;
|
||||
|
||||
// Split HEAP_STANDARD64K among root devices
|
||||
auto gfxStandard64KBSize = alignDown(gfxStandardSize / numRootDevices, GfxPartition::heapGranularity);
|
||||
heapInitWithAllocationAlignment(HeapIndex::HEAP_STANDARD64KB, gfxBase + rootDeviceIndex * gfxStandard64KBSize, gfxStandard64KBSize, 2 * MemoryConstants::megaByte);
|
||||
heapInitWithAllocationAlignment(HeapIndex::HEAP_STANDARD64KB, gfxBase + rootDeviceIndex * gfxStandard64KBSize, gfxStandard64KBSize, MemoryConstants::pageSize64k);
|
||||
gfxBase += gfxStandardSize;
|
||||
|
||||
// Split HEAP_STANDARD2MB among root devices
|
||||
auto gfxStandard2MBSize = alignDown(gfxStandardSize / numRootDevices, GfxPartition::heapGranularity);
|
||||
heapInitWithAllocationAlignment(HeapIndex::HEAP_STANDARD2MB, gfxBase + rootDeviceIndex * gfxStandard2MBSize, gfxStandard2MBSize, 2 * MemoryConstants::megaByte);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ enum class HeapIndex : uint32_t {
|
||||
HEAP_EXTERNAL = 3u,
|
||||
HEAP_STANDARD,
|
||||
HEAP_STANDARD64KB,
|
||||
HEAP_STANDARD2MB,
|
||||
HEAP_SVM,
|
||||
HEAP_EXTENDED,
|
||||
HEAP_EXTERNAL_FRONT_WINDOW,
|
||||
@@ -83,7 +84,8 @@ class GfxPartition {
|
||||
}
|
||||
|
||||
uint64_t getHeapMinimalAddress(HeapIndex heapIndex) {
|
||||
if (heapIndex == HeapIndex::HEAP_EXTERNAL_DEVICE_FRONT_WINDOW ||
|
||||
if (heapIndex == HeapIndex::HEAP_SVM ||
|
||||
heapIndex == HeapIndex::HEAP_EXTERNAL_DEVICE_FRONT_WINDOW ||
|
||||
heapIndex == HeapIndex::HEAP_EXTERNAL_FRONT_WINDOW ||
|
||||
heapIndex == HeapIndex::HEAP_INTERNAL_DEVICE_FRONT_WINDOW ||
|
||||
heapIndex == HeapIndex::HEAP_INTERNAL_FRONT_WINDOW) {
|
||||
@@ -103,7 +105,7 @@ class GfxPartition {
|
||||
|
||||
bool isLimitedRange() { return getHeap(HeapIndex::HEAP_SVM).getSize() == 0ull; }
|
||||
|
||||
static const uint64_t heapGranularity = MemoryConstants::pageSize64k;
|
||||
static const uint64_t heapGranularity = 2 * MemoryConstants::megaByte;
|
||||
static constexpr size_t externalFrontWindowPoolSize = 16 * MemoryConstants::megaByte;
|
||||
static constexpr size_t internalFrontWindowPoolSize = 1 * MemoryConstants::megaByte;
|
||||
|
||||
|
||||
@@ -161,13 +161,13 @@ uint32_t DrmMemoryManager::unreference(NEO::BufferObject *bo, bool synchronousDe
|
||||
return r;
|
||||
}
|
||||
|
||||
uint64_t DrmMemoryManager::acquireGpuRange(size_t &size, bool specificBitness, uint32_t rootDeviceIndex, bool requiresStandard64KBHeap) {
|
||||
uint64_t DrmMemoryManager::acquireGpuRange(size_t &size, bool specificBitness, uint32_t rootDeviceIndex, bool requiresStandard2MBHeap) {
|
||||
auto gfxPartition = getGfxPartition(rootDeviceIndex);
|
||||
if (specificBitness && this->force32bitAllocations) {
|
||||
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_EXTERNAL, size));
|
||||
}
|
||||
if (requiresStandard64KBHeap) {
|
||||
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD64KB, size));
|
||||
if (requiresStandard2MBHeap) {
|
||||
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD2MB, size));
|
||||
}
|
||||
return GmmHelper::canonize(gfxPartition->heapAllocate(HeapIndex::HEAP_STANDARD, size));
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
void pushSharedBufferObject(BufferObject *bo);
|
||||
BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex);
|
||||
bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable);
|
||||
uint64_t acquireGpuRange(size_t &size, bool requireSpecificBitness, uint32_t rootDeviceIndex, bool requiresStandard64KBHeap);
|
||||
uint64_t acquireGpuRange(size_t &size, bool requireSpecificBitness, uint32_t rootDeviceIndex, bool requiresStandard2MBHeap);
|
||||
MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex);
|
||||
void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const;
|
||||
uint32_t getDefaultDrmContextId() const;
|
||||
|
||||
Reference in New Issue
Block a user