Skip to content

Commit 3a008fa

Browse files
Revert "[1/n] Use GfxPartition for 32-bit allocations - WddmMemoryManager"
This reverts commit 2bb451e76d922861673e052f5f889658ac7db15f. Change-Id: I1deada59a291a96ef88c8b9b4f2b28861ad27347 Signed-off-by: Venevtsev, Igor <[email protected]>
1 parent 54c4678 commit 3a008fa

File tree

10 files changed

+44
-47
lines changed

10 files changed

+44
-47
lines changed

runtime/memory_manager/gfx_partition.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ class GfxPartition {
5454
return getHeap(heapIndex).getBase() + getHeap(heapIndex).getSize() - 1;
5555
}
5656

57-
uint64_t getHeapMinimalAddress(HeapIndex heapIndex) {
58-
return getHeapBase(heapIndex) + heapGranularity;
59-
}
60-
6157
static const uint64_t heapGranularity = MemoryConstants::pageSize64k;
6258

6359
static const std::array<HeapIndex, 4> heap32Names;

runtime/memory_manager/memory_manager.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ class MemoryManager {
106106

107107
virtual uint64_t getMaxApplicationAddress() = 0;
108108

109-
virtual uint64_t getInternalHeapBaseAddress() {
110-
return gfxPartition.getHeapBase(internalHeapIndex);
111-
}
112-
113-
uint64_t getExternalHeapBaseAddress() {
114-
return gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL);
115-
}
109+
virtual uint64_t getInternalHeapBaseAddress() = 0;
116110

117111
bool peek64kbPagesEnabled() const { return enable64kbpages; }
118112
bool peekForce32BitAllocations() const { return force32bitAllocations; }

runtime/os_interface/windows/wddm/wddm.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ void Wddm::initGfxPartition(GfxPartition &outGfxPartition) const {
769769
outGfxPartition.heapInit(HeapIndex::HEAP_STANDARD64KB, gfxPartition.Standard64KB.Base, gfxPartition.Standard64KB.Limit - gfxPartition.Standard64KB.Base + 1);
770770

771771
for (auto heap : GfxPartition::heap32Names) {
772-
outGfxPartition.heapInit(heap, gfxPartition.Heap32[static_cast<uint32_t>(heap)].Base,
772+
outGfxPartition.heapInit(heap, gfxPartition.Heap32[static_cast<uint32_t>(heap)].Base + MemoryConstants::pageSize,
773773
gfxPartition.Heap32[static_cast<uint32_t>(heap)].Limit - gfxPartition.Heap32[static_cast<uint32_t>(heap)].Base + 1);
774774
}
775775
}
@@ -791,6 +791,14 @@ PFND3DKMT_ESCAPE Wddm::getEscapeHandle() const {
791791
return gdi->escape;
792792
}
793793

794+
uint64_t Wddm::getExternalHeapBase() const {
795+
return alignUp(gfxPartition.Heap32[static_cast<uint32_t>(HeapIndex::HEAP_EXTERNAL)].Base, MemoryConstants::pageSize);
796+
}
797+
798+
uint64_t Wddm::getExternalHeapSize() const {
799+
return alignDown(gfxPartition.Heap32[static_cast<uint32_t>(HeapIndex::HEAP_EXTERNAL)].Limit - gfxPartition.Heap32[static_cast<uint32_t>(HeapIndex::HEAP_EXTERNAL)].Base, MemoryConstants::pageSize);
800+
}
801+
794802
VOID *Wddm::registerTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, WddmResidencyController &residencyController) {
795803
if (DebugManager.flags.DoNotRegisterTrimCallback.get()) {
796804
return nullptr;

runtime/os_interface/windows/wddm/wddm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class Wddm {
129129
return static_cast<uint32_t>(hwContextId);
130130
}
131131

132+
uint64_t getExternalHeapBase() const;
133+
uint64_t getExternalHeapSize() const;
134+
132135
std::unique_ptr<SettingsReader> registryReader;
133136

134137
GmmPageTableMngr *getPageTableManager() const { return pageTableManager.get(); }

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ WddmMemoryManager::WddmMemoryManager(ExecutionEnvironment &executionEnvironment)
3939
wddm(executionEnvironment.osInterface->get()->getWddm()) {
4040
DEBUG_BREAK_IF(wddm == nullptr);
4141

42+
allocator32Bit = std::unique_ptr<Allocator32bit>(new Allocator32bit(wddm->getExternalHeapBase(), wddm->getExternalHeapSize()));
4243
asyncDeleterEnabled = DebugManager.flags.EnableDeferredDeleter.get();
4344
if (asyncDeleterEnabled)
4445
deferredDeleter = createDeferredDeleter();
@@ -211,7 +212,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
211212
return nullptr;
212213
}
213214

214-
auto baseAddress = useInternal32BitAllocator(allocationData.type) ? getInternalHeapBaseAddress() : getExternalHeapBaseAddress();
215+
auto baseAddress = useInternal32BitAllocator(allocationData.type) ? getInternalHeapBaseAddress() : allocator32Bit->getBase();
215216
wddmAllocation->setGpuBaseAddress(GmmHelper::canonize(baseAddress));
216217

217218
DebugManager.logAllocation(wddmAllocation.get());
@@ -240,7 +241,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl
240241
allocation->setReservedAddressRange(ptr, size);
241242
} else if (requireSpecificBitness && this->force32bitAllocations) {
242243
allocation->set32BitAllocation(true);
243-
allocation->setGpuBaseAddress(GmmHelper::canonize(getExternalHeapBaseAddress()));
244+
allocation->setGpuBaseAddress(GmmHelper::canonize(allocator32Bit->getBase()));
244245
}
245246
status = mapGpuVirtualAddressWithRetry(allocation.get(), allocation->getReservedAddressPtr());
246247
DEBUG_BREAK_IF(!status);
@@ -482,6 +483,10 @@ uint64_t WddmMemoryManager::getMaxApplicationAddress() {
482483
return wddm->getMaxApplicationAddress();
483484
}
484485

486+
uint64_t WddmMemoryManager::getInternalHeapBaseAddress() {
487+
return wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Base;
488+
}
489+
485490
bool WddmMemoryManager::mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) {
486491
return wddm->updateAuxTable(graphicsAllocation->getGpuAddress(), graphicsAllocation->getDefaultGmm(), true);
487492
}
@@ -544,7 +549,7 @@ uint32_t WddmMemoryManager::mapGpuVirtualAddress(WddmAllocation *graphicsAllocat
544549
for (auto handleId = startingIndex; handleId < graphicsAllocation->getNumHandles(); handleId++) {
545550

546551
if (!wddm->mapGpuVirtualAddress(graphicsAllocation->getGmm(handleId), graphicsAllocation->getHandles()[handleId],
547-
gfxPartition.getHeapMinimalAddress(heapIndex), gfxPartition.getHeapLimit(heapIndex),
552+
gfxPartition.getHeapBase(heapIndex), gfxPartition.getHeapLimit(heapIndex),
548553
addressToMap, graphicsAllocation->getGpuAddressToModify())) {
549554
return numMappedAllocations;
550555
}
@@ -556,8 +561,8 @@ uint32_t WddmMemoryManager::mapGpuVirtualAddress(WddmAllocation *graphicsAllocat
556561
void WddmMemoryManager::obtainGpuAddressIfNeeded(WddmAllocation *allocation) {
557562
if (allocation->getNumHandles() > 1u) {
558563
auto heapIndex = selectHeap(allocation, false, executionEnvironment.isFullRangeSvm());
559-
allocation->preferredGpuAddress = wddm->reserveGpuVirtualAddress(gfxPartition.getHeapMinimalAddress(heapIndex),
560-
gfxPartition.getHeapLimit(heapIndex), allocation->getAlignedSize());
564+
allocation->preferredGpuAddress = wddm->reserveGpuVirtualAddress(gfxPartition.getHeapBase(heapIndex), gfxPartition.getHeapLimit(heapIndex),
565+
allocation->getAlignedSize());
561566
}
562567
}
563568

runtime/os_interface/windows/wddm_memory_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class WddmMemoryManager : public MemoryManager {
4949

5050
uint64_t getSystemSharedMemory() override;
5151
uint64_t getMaxApplicationAddress() override;
52+
uint64_t getInternalHeapBaseAddress() override;
5253

5354
bool tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
5455

unit_tests/memory_manager/gfx_partition_tests.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ void testGfxPartition(uint64_t gpuAddressSpace) {
6969
continue;
7070
}
7171

72-
EXPECT_GT(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap));
73-
EXPECT_EQ(gfxPartition.getHeapMinimalAddress(heap), gfxPartition.getHeapBase(heap) + GfxPartition::heapGranularity);
74-
7572
auto ptrBig = gfxPartition.heapAllocate(heap, sizeBig);
7673
EXPECT_NE(ptrBig, 0ull);
7774
EXPECT_LT(gfxPartition.getHeapBase(heap), ptrBig);

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,6 @@ TEST_F(MemoryAllocatorTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocatio
336336
EXPECT_NE(&allocation->fragmentsStorage, &handleStorage);
337337
}
338338

339-
TEST_F(MemoryAllocatorTest, defaultInternalHeapBaseIsInitialized) {
340-
EXPECT_LE(0ull, memoryManager->MemoryManager::getInternalHeapBaseAddress());
341-
}
342-
343-
TEST_F(MemoryAllocatorTest, defaultExternalHeapBaseIsNotNull) {
344-
EXPECT_LT(0ull, memoryManager->getExternalHeapBaseAddress());
345-
}
346-
347339
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithTrueMutlipleTimesThenAllocatorIsReused) {
348340
memoryManager->setForce32BitAllocations(true);
349341
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());

unit_tests/os_interface/windows/mock_wddm_memory_manager.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class MockWddmMemoryManager : public MemoryManagerCreate<WddmMemoryManager> {
2222
using BaseClass::allocateGraphicsMemoryWithProperties;
2323
using BaseClass::createGraphicsAllocation;
2424
using BaseClass::createWddmAllocation;
25-
using BaseClass::gfxPartition;
2625
using BaseClass::localMemorySupported;
2726
using MemoryManagerCreate<WddmMemoryManager>::MemoryManagerCreate;
2827

unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ TEST(WddmAllocationTest, givenMemoryPoolWhenPassedToWddmAllocationConstructorThe
105105
EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation2.getMemoryPool());
106106
}
107107

108-
TEST(WddmMemoryManagerExternalHeapTest, externalHeapIsCreatedWithCorrectBase) {
108+
TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase) {
109109
HardwareInfo *hwInfo;
110110
auto executionEnvironment = getExecutionEnvironmentImpl(hwInfo);
111111
std::unique_ptr<WddmMock> wddm(static_cast<WddmMock *>(Wddm::createWddm()));
@@ -116,7 +116,9 @@ TEST(WddmMemoryManagerExternalHeapTest, externalHeapIsCreatedWithCorrectBase) {
116116

117117
std::unique_ptr<WddmMemoryManager> memoryManager = std::unique_ptr<WddmMemoryManager>(new WddmMemoryManager(*executionEnvironment));
118118

119-
EXPECT_EQ(base, memoryManager->getExternalHeapBaseAddress());
119+
ASSERT_NE(nullptr, memoryManager->allocator32Bit.get());
120+
121+
EXPECT_EQ(base, memoryManager->allocator32Bit->getBase());
120122
}
121123

122124
TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) {
@@ -275,7 +277,7 @@ TEST_F(WddmMemoryManagerSimpleTest,
275277
givenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWhenNotAlignedPtrIsPassedThenAlignedGraphicsAllocationIsCreated) {
276278
memoryManager.reset(new MockWddmMemoryManager(false, false, *executionEnvironment));
277279
auto size = 13u;
278-
auto hostPtr = reinterpret_cast<const void *>(0x10001);
280+
auto hostPtr = reinterpret_cast<const void *>(0x5001);
279281

280282
AllocationData allocationData;
281283
allocationData.size = size;
@@ -517,7 +519,7 @@ TEST_F(WddmMemoryManagerTest, createAllocationFromSharedHandleReturns32BitAllocW
517519
if (is64bit) {
518520
EXPECT_TRUE(gpuAllocation->is32BitAllocation());
519521

520-
uint64_t base = memoryManager->getExternalHeapBaseAddress();
522+
uint64_t base = memoryManager->allocator32Bit->getBase();
521523
EXPECT_EQ(GmmHelper::canonize(base), gpuAllocation->getGpuBaseAddress());
522524
}
523525

@@ -848,8 +850,8 @@ TEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithNullptr) {
848850
auto *gpuAllocation = memoryManager->allocate32BitGraphicsMemory(3 * MemoryConstants::pageSize, nullptr, GraphicsAllocation::AllocationType::BUFFER);
849851

850852
ASSERT_NE(nullptr, gpuAllocation);
851-
EXPECT_LT(GmmHelper::canonize(memoryManager->gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress());
852-
EXPECT_GT(GmmHelper::canonize(memoryManager->gfxPartition.getHeapLimit(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress() + gpuAllocation->getUnderlyingBufferSize());
853+
EXPECT_LE(GmmHelper::canonize(wddm->getExternalHeapBase()), gpuAllocation->getGpuAddress());
854+
EXPECT_GT(GmmHelper::canonize(wddm->getExternalHeapBase()) + wddm->getExternalHeapSize() - 1, gpuAllocation->getGpuAddress());
853855

854856
EXPECT_EQ(0u, gpuAllocation->fragmentsStorage.fragmentCount);
855857
memoryManager->freeGraphicsMemory(gpuAllocation);
@@ -860,8 +862,8 @@ TEST_F(WddmMemoryManagerTest, given32BitAllocationWhenItIsCreatedThenItHasNonZer
860862

861863
ASSERT_NE(nullptr, gpuAllocation);
862864
EXPECT_NE(0llu, gpuAllocation->getGpuAddressToPatch());
863-
EXPECT_LT(GmmHelper::canonize(memoryManager->gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress());
864-
EXPECT_GT(GmmHelper::canonize(memoryManager->gfxPartition.getHeapLimit(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress() + gpuAllocation->getUnderlyingBufferSize());
865+
EXPECT_LE(GmmHelper::canonize(wddm->getExternalHeapBase()), gpuAllocation->getGpuAddress());
866+
EXPECT_GT(GmmHelper::canonize(wddm->getExternalHeapBase()) + wddm->getExternalHeapSize() - 1, gpuAllocation->getGpuAddress());
865867
memoryManager->freeGraphicsMemory(gpuAllocation);
866868
}
867869

@@ -875,8 +877,8 @@ TEST_F(WddmMemoryManagerTest, Allocate32BitMemoryWithMisalignedHostPtrDoesNotDoT
875877

876878
EXPECT_EQ(alignSizeWholePage(misalignedPtr, misalignedSize), gpuAllocation->getUnderlyingBufferSize());
877879

878-
EXPECT_LT(GmmHelper::canonize(memoryManager->gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress());
879-
EXPECT_GT(GmmHelper::canonize(memoryManager->gfxPartition.getHeapLimit(HeapIndex::HEAP_EXTERNAL)), gpuAllocation->getGpuAddress() + gpuAllocation->getUnderlyingBufferSize());
880+
EXPECT_LE(GmmHelper::canonize(wddm->getExternalHeapBase()), gpuAllocation->getGpuAddress());
881+
EXPECT_GT(GmmHelper::canonize(wddm->getExternalHeapBase()) + wddm->getExternalHeapSize() - 1, gpuAllocation->getGpuAddress());
880882

881883
EXPECT_EQ(0u, gpuAllocation->fragmentsStorage.fragmentCount);
882884

@@ -892,7 +894,7 @@ TEST_F(WddmMemoryManagerTest, Allocate32BitMemorySetsCannonizedGpuBaseAddress) {
892894

893895
ASSERT_NE(nullptr, gpuAllocation);
894896

895-
uint64_t cannonizedAddress = GmmHelper::canonize(memoryManager->gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL));
897+
uint64_t cannonizedAddress = GmmHelper::canonize(wddm->getExternalHeapBase());
896898
EXPECT_EQ(cannonizedAddress, gpuAllocation->getGpuBaseAddress());
897899

898900
memoryManager->freeGraphicsMemory(gpuAllocation);
@@ -975,7 +977,7 @@ TEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGpuV
975977
}
976978

977979
TEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstMapGpuVaFailSecondAfterDrainSuccessThenCreateAllocation) {
978-
void *ptr = reinterpret_cast<void *>(0x10000);
980+
void *ptr = reinterpret_cast<void *>(0x1000);
979981
size_t size = 0x1000;
980982
std::unique_ptr<Gmm> gmm(new Gmm(ptr, size, false));
981983

@@ -1014,10 +1016,10 @@ TEST_F(WddmMemoryManagerTest, givenNullPtrAndSizePassedToCreateInternalAllocatio
10141016
EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize());
10151017
EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress());
10161018
auto cannonizedHeapBase = GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress());
1017-
auto cannonizedHeapEnd = GmmHelper::canonize(memoryManager->gfxPartition.getHeapLimit(internalHeapIndex));
1019+
auto cannonizedHeapEnd = GmmHelper::canonize(this->wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Limit);
10181020

1019-
EXPECT_GT(wddmAllocation->getGpuAddress(), cannonizedHeapBase);
1020-
EXPECT_LT(wddmAllocation->getGpuAddress() + wddmAllocation->getUnderlyingBufferSize(), cannonizedHeapEnd);
1021+
EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase);
1022+
EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd);
10211023

10221024
EXPECT_NE(nullptr, wddmAllocation->getDriverAllocatedCpuPtr());
10231025
EXPECT_TRUE(wddmAllocation->is32BitAllocation());
@@ -1033,10 +1035,10 @@ TEST_F(WddmMemoryManagerTest, givenPtrAndSizePassedToCreateInternalAllocationWhe
10331035
EXPECT_EQ(4096u, wddmAllocation->getUnderlyingBufferSize());
10341036
EXPECT_NE((uint64_t)wddmAllocation->getUnderlyingBuffer(), wddmAllocation->getGpuAddress());
10351037
auto cannonizedHeapBase = GmmHelper::canonize(memoryManager->getInternalHeapBaseAddress());
1036-
auto cannonizedHeapEnd = GmmHelper::canonize(memoryManager->gfxPartition.getHeapLimit(internalHeapIndex));
1038+
auto cannonizedHeapEnd = GmmHelper::canonize(wddm->getGfxPartition().Heap32[static_cast<uint32_t>(internalHeapIndex)].Limit);
10371039

1038-
EXPECT_GT(wddmAllocation->getGpuAddress(), cannonizedHeapBase);
1039-
EXPECT_LT(wddmAllocation->getGpuAddress() + wddmAllocation->getUnderlyingBufferSize(), cannonizedHeapEnd);
1040+
EXPECT_GE(wddmAllocation->getGpuAddress(), cannonizedHeapBase);
1041+
EXPECT_LE(wddmAllocation->getGpuAddress(), cannonizedHeapEnd);
10401042

10411043
EXPECT_EQ(nullptr, wddmAllocation->getDriverAllocatedCpuPtr());
10421044
EXPECT_TRUE(wddmAllocation->is32BitAllocation());

0 commit comments

Comments
 (0)