From 1ce2f9564ab3be8add6d362a4884dd149d471619 Mon Sep 17 00:00:00 2001 From: "Venevtsev, Igor" Date: Tue, 2 Apr 2019 17:33:59 +0200 Subject: [PATCH] [2/n] Use GfxPartition for 32-bit allocations - DrmMemoryManager Related-To: NEO-2877 Change-Id: Ic57d1e2cfb2629f50c6fd16e71861e8ee47f2b10 Signed-off-by: Venevtsev, Igor --- runtime/memory_manager/gfx_partition.h | 2 + runtime/os_interface/linux/CMakeLists.txt | 2 - .../os_interface/linux/drm_limited_range.cpp | 31 --- .../os_interface/linux/drm_limited_range.h | 34 --- .../os_interface/linux/drm_memory_manager.cpp | 112 ++++------ .../os_interface/linux/drm_memory_manager.h | 6 +- .../mocks/linux/mock_drm_memory_manager.h | 7 +- .../linux/drm_buffer_object_tests.cpp | 1 - .../linux/drm_memory_manager_tests.cpp | 194 ++++++------------ 9 files changed, 109 insertions(+), 280 deletions(-) delete mode 100644 runtime/os_interface/linux/drm_limited_range.cpp delete mode 100644 runtime/os_interface/linux/drm_limited_range.h diff --git a/runtime/memory_manager/gfx_partition.h b/runtime/memory_manager/gfx_partition.h index 3695836e50..b752e8302b 100644 --- a/runtime/memory_manager/gfx_partition.h +++ b/runtime/memory_manager/gfx_partition.h @@ -58,6 +58,8 @@ class GfxPartition { return getHeapBase(heapIndex) + heapGranularity; } + bool isLimitedRange() { return getHeap(HeapIndex::HEAP_SVM).getSize() == 0ull; } + static const uint64_t heapGranularity = MemoryConstants::pageSize64k; static const std::array heap32Names; diff --git a/runtime/os_interface/linux/CMakeLists.txt b/runtime/os_interface/linux/CMakeLists.txt index 7591179c43..e4f4e428a0 100644 --- a/runtime/os_interface/linux/CMakeLists.txt +++ b/runtime/os_interface/linux/CMakeLists.txt @@ -24,8 +24,6 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/drm_engine_mapper.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_gem_close_worker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_gem_close_worker.h - ${CMAKE_CURRENT_SOURCE_DIR}/drm_limited_range.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/drm_limited_range.h ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager.h ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_memory_manager_allocate_in_device_pool.cpp diff --git a/runtime/os_interface/linux/drm_limited_range.cpp b/runtime/os_interface/linux/drm_limited_range.cpp deleted file mode 100644 index f17818a580..0000000000 --- a/runtime/os_interface/linux/drm_limited_range.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2017-2019 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "runtime/os_interface/linux/drm_limited_range.h" - -#include "runtime/os_interface/debug_settings_manager.h" -#include "runtime/os_interface/linux/allocator_helper.h" - -using namespace NEO; - -NEO::AllocatorLimitedRange::AllocatorLimitedRange(uint64_t base, uint64_t size) : base(base), size(size), heapAllocator(std::make_unique(base, size)) { -} - -uint64_t NEO::AllocatorLimitedRange::allocate(size_t &size) { - if (size >= this->size) { - return 0llu; - } - return this->heapAllocator->allocate(size); -} - -void NEO::AllocatorLimitedRange::free(uint64_t ptr, size_t size) { - this->heapAllocator->free(ptr, size); -} - -uint64_t NEO::AllocatorLimitedRange::getBase() const { - return base; -} diff --git a/runtime/os_interface/linux/drm_limited_range.h b/runtime/os_interface/linux/drm_limited_range.h deleted file mode 100644 index c48ff02eea..0000000000 --- a/runtime/os_interface/linux/drm_limited_range.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2017-2019 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#pragma once -#include "runtime/helpers/aligned_memory.h" -#include "runtime/helpers/basic_math.h" -#include "runtime/helpers/ptr_math.h" -#include "runtime/utilities/heap_allocator.h" - -#include -#include -#include - -namespace NEO { -class AllocatorLimitedRange { - public: - AllocatorLimitedRange(uint64_t base, uint64_t size); - AllocatorLimitedRange() = delete; - ~AllocatorLimitedRange() = default; - - uint64_t allocate(size_t &size); - void free(uint64_t ptr, size_t size); - uint64_t getBase() const; - - protected: - uint64_t base = 0; - uint64_t size = 0; - std::unique_ptr heapAllocator; -}; -} // namespace NEO diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 288a059679..f70fe7c06f 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -18,7 +18,6 @@ #include "runtime/helpers/ptr_math.h" #include "runtime/helpers/surface_formats.h" #include "runtime/memory_manager/host_ptr_manager.h" -#include "runtime/os_interface/32bit_memory.h" #include "runtime/os_interface/linux/os_context_linux.h" #include "runtime/os_interface/linux/os_interface.h" #include "runtime/os_interface/linux/tiling_mode_helper.h" @@ -39,6 +38,7 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode, forcePinEnabled(forcePinAllowed), validateHostPtrMemory(validateHostPtrMemory) { gfxPartition.init(platformDevices[0]->capabilityTable.gpuAddressSpace); + MemoryManager::virtualPaddingAvailable = true; if (mode != gemCloseWorkerMode::gemCloseWorkerInactive) { gemCloseWorker.reset(new DrmGemCloseWorker(*this)); @@ -58,20 +58,9 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode, } else { pinBB->isAllocated = true; } - - initInternalRangeAllocator(platformDevices[0]->capabilityTable.gpuAddressSpace); } DrmMemoryManager::~DrmMemoryManager() { - if (this->limitedGpuAddressRangeAllocator) { - // freeing space for internal 32bit allocator - uint64_t size = 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize; - this->limitedGpuAddressRangeAllocator->free(this->internal32bitAllocator->getBase(), size); - - // freeing space for external 32bit allocator - size += MemoryConstants::pageSize; - this->limitedGpuAddressRangeAllocator->free(this->allocator32Bit->getBase(), size); - } applyCommonCleanup(); if (gemCloseWorker) { gemCloseWorker->close(false); @@ -82,28 +71,6 @@ DrmMemoryManager::~DrmMemoryManager() { } } -void DrmMemoryManager::initInternalRangeAllocator(size_t gpuRange) { - if (gpuRange < MemoryConstants::max48BitAddress || !DebugManager.flags.EnableHostPtrTracking.get()) { - // set the allocator with the whole reduced address space range - pageSize (base address) to - // avoid starting address of the heap to be 0, which could be interpreted as invalid address - // nullPtr. - this->limitedGpuAddressRangeAllocator.reset(new AllocatorLimitedRange(MemoryConstants::pageSize, gpuRange + 1 - MemoryConstants::pageSize)); - - // 0x1000 ~ 0xFFFFFFFF address space for external 32bit allocator // - uint64_t size = 4 * MemoryConstants::gigaByte - MemoryConstants::pageSize; - uint64_t allocatorBase = this->limitedGpuAddressRangeAllocator->allocate(size); - allocator32Bit.reset(new Allocator32bit(allocatorBase, size)); - - // 0x100000000 ~ 0x1FFFFFFFF address space for internal 32bit allocator // - size += MemoryConstants::pageSize; - allocatorBase = this->limitedGpuAddressRangeAllocator->allocate(size); - internal32bitAllocator.reset(new Allocator32bit(allocatorBase, size)); - } else { - // when in full range space, set the internal32bitAllocator using 32bit addressing allocator. - internal32bitAllocator.reset(new Allocator32bit); - } -} - void DrmMemoryManager::eraseSharedBufferObject(NEO::BufferObject *bo) { auto it = std::find(sharingBufferObjects.begin(), sharingBufferObjects.end(), bo); //If an object isReused = true, it must be in the vector @@ -162,12 +129,12 @@ uint32_t DrmMemoryManager::unreference(NEO::BufferObject *bo, bool synchronousDe uint64_t DrmMemoryManager::acquireGpuRange(size_t &size, StorageAllocatorType &storageType, bool specificBitness) { if (specificBitness && this->force32bitAllocations) { storageType = BIT32_ALLOCATOR_EXTERNAL; - return this->allocator32Bit->allocate(size); + return gfxPartition.heapAllocate(HeapIndex::HEAP_EXTERNAL, size); } - if (limitedGpuAddressRangeAllocator.get()) { + if (isLimitedRange()) { storageType = INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE; - return limitedGpuAddressRangeAllocator->allocate(size); + return gfxPartition.heapAllocate(HeapIndex::HEAP_STANDARD, size); } storageType = MMAP_ALLOCATOR; @@ -183,17 +150,17 @@ void DrmMemoryManager::releaseGpuRange(void *address, size_t unmapSize, StorageA uint64_t graphicsAddress = static_cast(reinterpret_cast(address)); if (allocatorType == BIT32_ALLOCATOR_EXTERNAL) { - allocator32Bit->free(graphicsAddress, unmapSize); + gfxPartition.heapFree(HeapIndex::HEAP_EXTERNAL, graphicsAddress, unmapSize); return; } if (allocatorType == BIT32_ALLOCATOR_INTERNAL) { - internal32bitAllocator->free(graphicsAddress, unmapSize); + gfxPartition.heapFree(internalHeapIndex, graphicsAddress, unmapSize); return; } UNRECOVERABLE_IF(allocatorType != INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE); - limitedGpuAddressRangeAllocator->free(graphicsAddress, unmapSize); + gfxPartition.heapFree(HeapIndex::HEAP_STANDARD, graphicsAddress, unmapSize); } NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, bool softpin) { @@ -252,10 +219,10 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const Alloc bo->isAllocated = true; - // if limitedRangeAlloction is enabled, memory allocation for bo in the limited Range heap is required - if (limitedGpuAddressRangeAllocator) { + // if Limited Range Alloction is enabled, memory allocation for bo in the limited Range heap is required + if (isLimitedRange()) { StorageAllocatorType allocType; - bo->gpuAddress = acquireGpuRange(cSize, allocType, false); + bo->gpuAddress = GmmHelper::canonize(acquireGpuRange(cSize, allocType, false)); if (!bo->gpuAddress) { bo->close(); delete bo; @@ -270,7 +237,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const Alloc emitPinningRequest(bo, allocationData); auto allocation = new DrmAllocation(allocationData.type, bo, res, bo->gpuAddress, cSize, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable); - allocation->setDriverAllocatedCpuPtr(limitedGpuAddressRangeAllocator ? res : nullptr); + allocation->setDriverAllocatedCpuPtr(isLimitedRange() ? res : nullptr); return allocation; } @@ -306,7 +273,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al bo->isAllocated = false; bo->setUnmapSize(alignedSize); - bo->gpuAddress = gpuVirtualAddress; + bo->gpuAddress = GmmHelper::canonize(gpuVirtualAddress); bo->setAllocationType(allocType); auto allocation = new DrmAllocation(allocationData.type, bo, const_cast(alignedPtr), gpuVirtualAddress, @@ -345,8 +312,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A return nullptr; } bo->size = allocationData.imgInfo->size; - bo->gpuAddress = gpuRange; - + bo->gpuAddress = GmmHelper::canonize(gpuRange); auto ret2 = bo->setTiling(I915_TILING_Y, static_cast(allocationData.imgInfo->rowPitch)); DEBUG_BREAK_IF(ret2 != true); ((void)(ret2)); @@ -361,14 +327,14 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImageImpl(const A DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) { auto internal = useInternal32BitAllocator(allocationData.type); - auto allocatorToUse = internal ? internal32bitAllocator.get() : allocator32Bit.get(); + auto allocatorToUse = internal ? internalHeapIndex : HeapIndex::HEAP_EXTERNAL; auto allocatorType = internal ? BIT32_ALLOCATOR_INTERNAL : BIT32_ALLOCATOR_EXTERNAL; if (allocationData.hostPtr) { uintptr_t inputPtr = reinterpret_cast(allocationData.hostPtr); auto allocationSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size); auto realAllocationSize = allocationSize; - auto gpuVirtualAddress = allocatorToUse->allocate(realAllocationSize); + auto gpuVirtualAddress = gfxPartition.heapAllocate(allocatorToUse, realAllocationSize); if (!gpuVirtualAddress) { return nullptr; } @@ -377,47 +343,41 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio BufferObject *bo = allocUserptr(alignedUserPointer, allocationSize, 0, true); if (!bo) { - allocatorToUse->free(gpuVirtualAddress, realAllocationSize); + gfxPartition.heapFree(allocatorToUse, gpuVirtualAddress, realAllocationSize); return nullptr; } bo->isAllocated = false; bo->setUnmapSize(realAllocationSize); - bo->gpuAddress = gpuVirtualAddress; + bo->gpuAddress = GmmHelper::canonize(gpuVirtualAddress); bo->setAllocationType(allocatorType); auto allocation = new DrmAllocation(allocationData.type, bo, const_cast(allocationData.hostPtr), ptrOffset(gpuVirtualAddress, inputPointerOffset), allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false); allocation->set32BitAllocation(true); - allocation->setGpuBaseAddress(allocatorToUse->getBase()); + allocation->setGpuBaseAddress(gfxPartition.getHeapBase(allocatorToUse)); return allocation; } size_t alignedAllocationSize = alignUp(allocationData.size, MemoryConstants::pageSize); auto allocationSize = alignedAllocationSize; - auto res = allocatorToUse->allocate(allocationSize); + auto res = gfxPartition.heapAllocate(allocatorToUse, allocationSize); if (!res) { return nullptr; } - void *ptrAlloc = reinterpret_cast(res); + auto ptrAlloc = alignedMallocWrapper(alignedAllocationSize, MemoryConstants::allocationAlignment); - if (limitedGpuAddressRangeAllocator) { - ptrAlloc = alignedMallocWrapper(alignedAllocationSize, MemoryConstants::allocationAlignment); - - if (!ptrAlloc) { - allocatorToUse->free(res, allocationSize); - return nullptr; - } + if (!ptrAlloc) { + gfxPartition.heapFree(allocatorToUse, res, allocationSize); + return nullptr; } BufferObject *bo = allocUserptr(reinterpret_cast(ptrAlloc), alignedAllocationSize, 0, true); if (!bo) { - if (limitedGpuAddressRangeAllocator) { - alignedFreeWrapper(ptrAlloc); - } - allocatorToUse->free(res, allocationSize); + alignedFreeWrapper(ptrAlloc); + gfxPartition.heapFree(allocatorToUse, res, allocationSize); return nullptr; } @@ -425,15 +385,15 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemoryImpl(const Allocatio bo->setUnmapSize(allocationSize); bo->setAllocationType(allocatorType); - bo->gpuAddress = res; + bo->gpuAddress = GmmHelper::canonize(res); - // softpin to the GPU address, res if it uses limitedRange Allocation + // softpin to the GPU address, res if it uses Limited Range Allocation auto allocation = new DrmAllocation(allocationData.type, bo, ptrAlloc, res, alignedAllocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing, false); allocation->set32BitAllocation(true); - allocation->setGpuBaseAddress(allocatorToUse->getBase()); - allocation->setDriverAllocatedCpuPtr(limitedGpuAddressRangeAllocator ? ptrAlloc : nullptr); + allocation->setGpuBaseAddress(gfxPartition.getHeapBase(allocatorToUse)); + allocation->setDriverAllocatedCpuPtr(ptrAlloc); return allocation; } @@ -463,7 +423,7 @@ BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t si } bo->size = size; - bo->gpuAddress = gpuRange; + bo->gpuAddress = GmmHelper::canonize(gpuRange); bo->setUnmapSize(size); bo->setAllocationType(storageType); return bo; @@ -506,9 +466,9 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o if (requireSpecificBitness && this->force32bitAllocations) { drmAllocation->set32BitAllocation(true); - drmAllocation->setGpuBaseAddress(getExternalHeapBaseAddress()); - } else if (this->limitedGpuAddressRangeAllocator.get()) { - drmAllocation->setGpuBaseAddress(this->limitedGpuAddressRangeAllocator->getBase()); + drmAllocation->setGpuBaseAddress(gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL)); + } else if (isLimitedRange()) { + drmAllocation->setGpuBaseAddress(gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD)); } if (properties.imgInfo) { @@ -542,7 +502,7 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation if (!bo) { return nullptr; } - bo->gpuAddress = gpuRange; + bo->gpuAddress = GmmHelper::canonize(gpuRange); bo->setUnmapSize(sizeWithPadding); bo->setAllocationType(storageType); return new DrmAllocation(inputGraphicsAllocation->getAllocationType(), bo, srcPtr, ptrOffset(gpuRange, offset), sizeWithPadding, @@ -627,11 +587,11 @@ uint64_t DrmMemoryManager::getMaxApplicationAddress() { } uint64_t DrmMemoryManager::getInternalHeapBaseAddress() { - return this->internal32bitAllocator->getBase(); + return gfxPartition.getHeapBase(internalHeapIndex); } uint64_t DrmMemoryManager::getExternalHeapBaseAddress() { - return this->allocator32Bit->getBase(); + return gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL); } MemoryManager::AllocationStatus DrmMemoryManager::populateOsHandles(OsHandleStorage &handleStorage) { diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index fe91eec65e..1480fbcaa9 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -9,7 +9,6 @@ #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/linux/drm_allocation.h" #include "runtime/os_interface/linux/drm_buffer_object.h" -#include "runtime/os_interface/linux/drm_limited_range.h" #include "runtime/os_interface/linux/drm_neo.h" #include "drm_gem_close_worker.h" @@ -18,6 +17,7 @@ #include namespace NEO { + class BufferObject; class Drm; @@ -56,6 +56,7 @@ class DrmMemoryManager : public MemoryManager { DrmGemCloseWorker *peekGemCloseWorker() const { return this->gemCloseWorker.get(); } void *reserveCpuAddressRange(size_t size) override; void releaseReservedCpuAddressRange(void *reserved, size_t size) override; + bool isLimitedRange() { return gfxPartition.isLimitedRange(); } protected: BufferObject *findAndReferenceSharedBufferObject(int boHandle); @@ -66,7 +67,6 @@ class DrmMemoryManager : public MemoryManager { bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable); uint64_t acquireGpuRange(size_t &size, StorageAllocatorType &allocType, bool requireSpecificBitness); void releaseGpuRange(void *address, size_t unmapSize, StorageAllocatorType allocatorType); - void initInternalRangeAllocator(size_t range); void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const; DrmAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override; @@ -93,7 +93,5 @@ class DrmMemoryManager : public MemoryManager { decltype(&close) closeFunction = close; std::vector sharingBufferObjects; std::mutex mtx; - std::unique_ptr internal32bitAllocator; - std::unique_ptr limitedGpuAddressRangeAllocator; }; } // namespace NEO diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index 93b64e2bdb..2db2e12365 100644 --- a/unit_tests/mocks/linux/mock_drm_memory_manager.h +++ b/unit_tests/mocks/linux/mock_drm_memory_manager.h @@ -50,8 +50,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { using DrmMemoryManager::allocator32Bit; using DrmMemoryManager::allocUserptr; using DrmMemoryManager::createGraphicsAllocation; - using DrmMemoryManager::internal32bitAllocator; - using DrmMemoryManager::limitedGpuAddressRangeAllocator; + using DrmMemoryManager::gfxPartition; using DrmMemoryManager::pinThreshold; using DrmMemoryManager::setDomainCpu; using DrmMemoryManager::sharingBufferObjects; @@ -101,10 +100,8 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { } DrmGemCloseWorker *getgemCloseWorker() { return this->gemCloseWorker.get(); } - void forceLimitedRangeAllocator(uint64_t range) { initInternalRangeAllocator(range); } + void forceLimitedRangeAllocator(uint64_t range) { gfxPartition.init(range); } - Allocator32bit *getDrmInternal32BitAllocator() const { return internal32bitAllocator.get(); } - AllocatorLimitedRange *getDrmLimitedRangeAllocator() const { return limitedGpuAddressRangeAllocator.get(); } DrmAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { bool allocateMemory = ptr == nullptr; AllocationData allocationData; diff --git a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp index 5144427cc4..8256e8b2d5 100644 --- a/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp +++ b/unit_tests/os_interface/linux/drm_buffer_object_tests.cpp @@ -5,7 +5,6 @@ * */ -#include "runtime/os_interface/32bit_memory.h" #include "runtime/os_interface/linux/drm_buffer_object.h" #include "test.h" #include "unit_tests/os_interface/linux/device_command_stream_fixture.h" diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index 82d4744559..fb3cb89619 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -56,10 +56,6 @@ AllocationProperties createAllocationProperties(size_t size, bool forcePin) { typedef Test DrmMemoryManagerTest; typedef Test DrmMemoryManagerWithExplicitExpectationsTest; -TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDefaultDrmMemoryMangerWhenItIsCreatedThenItContainsInternal32BitAllocator) { - EXPECT_NE(nullptr, memoryManager->getDrmInternal32BitAllocator()); -} - TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) { void *cpuPtr = (void *)0x30000; size_t size = 0x1000; @@ -217,7 +213,7 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation auto memoryManager = std::make_unique(false, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); - allocationData.size = 10 * 1024 * 1024; + allocationData.size = 10 * MB; allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); allocationData.flags.forcePin = true; auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); @@ -711,10 +707,8 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32 EXPECT_NE(nullptr, allocation->getUnderlyingBuffer()); EXPECT_GE(allocation->getUnderlyingBufferSize(), size); - uintptr_t address64bit = (uintptr_t)allocation->getGpuAddressToPatch(); - if (is32BitOsAllocatorAvailable) { - EXPECT_LT(address64bit, max32BitAddress); - } + auto address64bit = allocation->getGpuAddressToPatch(); + EXPECT_LT(address64bit, MemoryConstants::max32BitAddress); auto bo = allocation->getBO(); EXPECT_GE(bo->peekUnmapSize(), 0u); EXPECT_TRUE(allocation->is32BitAllocation()); @@ -744,26 +738,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationWhenLi memoryManager->freeGraphicsMemory(allocation); } -TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithTrueMutlipleTimesThenAllocatorIsReused) { - // allocator32Bit is created unconditionally when limitedRangeAllocation is enabled. - if (!memoryManager->limitedGpuAddressRangeAllocator.get()) { - EXPECT_EQ(nullptr, memoryManager->allocator32Bit.get()); - } - - memoryManager->setForce32BitAllocations(true); - EXPECT_NE(nullptr, memoryManager->allocator32Bit.get()); - auto currentAllocator = memoryManager->allocator32Bit.get(); - memoryManager->setForce32BitAllocations(true); - EXPECT_EQ(memoryManager->allocator32Bit.get(), currentAllocator); -} - -TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithFalseThenAllocatorIsNotDeleted) { - memoryManager->setForce32BitAllocations(true); - EXPECT_NE(nullptr, memoryManager->allocator32Bit.get()); - memoryManager->setForce32BitAllocations(false); - EXPECT_NE(nullptr, memoryManager->allocator32Bit.get()); -} - TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen32BitBufferIsReturned) { DebugManagerStateRestore dbgRestorer; mock->ioctl_expected.gemUserptr = 1; @@ -791,11 +765,7 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen auto bufferAddress = buffer->getGraphicsAllocation()->getGpuAddress(); auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress(); - uintptr_t address64bit = (uintptr_t)bufferAddress; - - if (is32BitOsAllocatorAvailable) { - EXPECT_LT(address64bit - baseAddress, max32BitAddress); - } + EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); delete buffer; } @@ -829,20 +799,16 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHos auto bufferAddress = buffer->getGraphicsAllocation()->getGpuAddress(); auto drmAllocation = static_cast(buffer->getGraphicsAllocation()); - uintptr_t address64bitOnGpu = (uintptr_t)bufferAddress; - - if (is32BitOsAllocatorAvailable) { - auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress(); - EXPECT_LT(address64bitOnGpu - baseAddress, max32BitAddress); - } + auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress(); + EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); EXPECT_TRUE(drmAllocation->is32BitAllocation()); - auto allocationCpuPtr = (uintptr_t)drmAllocation->getUnderlyingBuffer(); - auto allocationPageOffset = allocationCpuPtr - alignDown(allocationCpuPtr, MemoryConstants::pageSize); + auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer(); + auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); - auto allocationGpuPtr = (uintptr_t)drmAllocation->getGpuAddress(); - auto allocationGpuOffset = allocationGpuPtr - alignDown(allocationGpuPtr, MemoryConstants::pageSize); + auto allocationGpuPtr = drmAllocation->getGpuAddress(); + auto allocationGpuOffset = ptrDiff(allocationGpuPtr, alignDown(allocationGpuPtr, MemoryConstants::pageSize)); auto bufferObject = drmAllocation->getBO(); @@ -895,19 +861,15 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64B EXPECT_TRUE(buffer->isMemObjZeroCopy()); auto bufferAddress = buffer->getGraphicsAllocation()->getGpuAddress(); - uintptr_t address64bit = (uintptr_t)bufferAddress; - - if (is32BitOsAllocatorAvailable) { - auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress(); - EXPECT_LT(address64bit - baseAddress, max32BitAddress); - } + auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress(); + EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress); auto drmAllocation = static_cast(buffer->getGraphicsAllocation()); EXPECT_TRUE(drmAllocation->is32BitAllocation()); - auto allocationCpuPtr = (uintptr_t)drmAllocation->getUnderlyingBuffer(); - auto allocationPageOffset = allocationCpuPtr - alignDown(allocationCpuPtr, MemoryConstants::pageSize); + auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer(); + auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize)); auto bufferObject = drmAllocation->getBO(); EXPECT_NE(0u, bufferObject->peekUnmapSize()); @@ -930,21 +892,22 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64B TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenLimitedRangeAllocatorSetThenHeapSizeAndEndAddrCorrectlySetForGivenGpuRange) { memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); - // check if limitedGpuAddressRangeAllocator is initialized - EXPECT_NE(memoryManager->limitedGpuAddressRangeAllocator.get(), nullptr); + uint64_t sizeBig = 4 * MemoryConstants::megaByte + MemoryConstants::pageSize; + auto gpuAddressLimitedRange = memoryManager->gfxPartition.heapAllocate(HeapIndex::HEAP_STANDARD, sizeBig); + EXPECT_LT(memoryManager->gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD), gpuAddressLimitedRange); + EXPECT_GT(memoryManager->gfxPartition.getHeapLimit(HeapIndex::HEAP_STANDARD), gpuAddressLimitedRange + sizeBig); + EXPECT_EQ(memoryManager->gfxPartition.getHeapMinimalAddress(HeapIndex::HEAP_STANDARD), gpuAddressLimitedRange); - uint64_t size = MemoryConstants::pageSize; - auto baseAddressLimitedRange = memoryManager->limitedGpuAddressRangeAllocator->allocate(size); - EXPECT_EQ(0x1000000000u, baseAddressLimitedRange + size); - - auto baseInternal32BitAlloc = memoryManager->internal32bitAllocator->allocate(size); - EXPECT_EQ(memoryManager->internal32bitAllocator->getBase() + 4 * MemoryConstants::gigaByte, baseInternal32BitAlloc + size); + auto gpuInternal32BitAlloc = memoryManager->gfxPartition.heapAllocate(internalHeapIndex, sizeBig); + EXPECT_LT(memoryManager->gfxPartition.getHeapBase(internalHeapIndex), gpuInternal32BitAlloc); + EXPECT_GT(memoryManager->gfxPartition.getHeapLimit(internalHeapIndex), gpuInternal32BitAlloc + sizeBig); + EXPECT_EQ(memoryManager->gfxPartition.getHeapMinimalAddress(internalHeapIndex), gpuInternal32BitAlloc); } TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForAllocationWithAlignmentThenCorrectAllocatorTypeSelected) { // if limitedRangeAllocator is enabled by default on the platform, only limitedRangeAllocator case will be tested. - auto limitedRangeAllocator = memoryManager->getDrmLimitedRangeAllocator(); - if (limitedRangeAllocator) { + auto limitedRange = memoryManager->isLimitedRange(); + if (limitedRange) { mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; @@ -961,7 +924,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForAllocationWithAlignme // if limitedRangeAllocator is enabled by default on the platform, expect the allocator type // is always INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE - if (limitedRangeAllocator) { + if (limitedRange) { EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, bo->peekAllocationType()); memoryManager->freeGraphicsMemory(allocation); } else { @@ -986,9 +949,12 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForAllocationWithAlignme TestedDrmMemoryManager::AllocationData allocationData; - memoryManager->forceLimitedRangeAllocator(0xFFFF); + // emulate GPU address space exhaust + memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); + memoryManager->gfxPartition.heapInit(HeapIndex::HEAP_STANDARD, 0x0, 0x10000); + // set size to something bigger than allowed space - allocationData.size = 0x10000; + allocationData.size = 0x20000; EXPECT_EQ(nullptr, memoryManager->allocateGraphicsMemoryWithAlignment(allocationData)); } @@ -1043,7 +1009,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCr memoryManager->setForce32BitAllocations(true); context.setMemoryManager(memoryManager); - size_t size = 2 * 1024 * 1024 * 1024u; + size_t size = 2 * GB; void *ptr = reinterpret_cast(0x100000000000); auto retVal = CL_SUCCESS; @@ -1054,7 +1020,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCr ptr, retVal); - size_t size2 = 4 * 1024 * 1024 * 1024u - 1u; + size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned auto buffer2 = Buffer::create( &context, @@ -1066,12 +1032,12 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCr EXPECT_NE(retVal, CL_SUCCESS); EXPECT_EQ(nullptr, buffer2); - if (is32BitOsAllocatorAvailable && buffer) { + if (buffer) { auto bufferPtr = buffer->getGraphicsAllocation()->getGpuAddress(); EXPECT_TRUE(buffer->getGraphicsAllocation()->is32BitAllocation()); auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress(); - EXPECT_LT((uintptr_t)(bufferPtr - baseAddress), max32BitAddress); + EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress); } delete buffer; @@ -1085,7 +1051,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCr memoryManager->setForce32BitAllocations(true); context.setMemoryManager(memoryManager); - size_t size = 2 * 1024 * 1024 * 1024u; + size_t size = 2 * GB; void *ptr = reinterpret_cast(0x100000000000); auto retVal = CL_SUCCESS; @@ -1096,7 +1062,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCr nullptr, retVal); - size_t size2 = 4 * 1024 * 1024 * 1024u - 1u; + size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned auto buffer2 = Buffer::create( &context, @@ -1108,12 +1074,12 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCr EXPECT_NE(retVal, CL_SUCCESS); EXPECT_EQ(nullptr, buffer2); - if (is32BitOsAllocatorAvailable && buffer) { + if (buffer) { auto bufferPtr = buffer->getGraphicsAllocation()->getGpuAddress(); EXPECT_TRUE(buffer->getGraphicsAllocation()->is32BitAllocation()); auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress(); - EXPECT_LT((uintptr_t)(bufferPtr - baseAddress), max32BitAddress); + EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress); } delete buffer; @@ -1125,12 +1091,11 @@ TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIs memoryManager->setForce32BitAllocations(true); std::unique_ptr pDevice(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto allocator = memoryManager->getDrmInternal32BitAllocator(); size_t size = getSizeToMap(); - auto alloc = allocator->allocate(size); + auto alloc = memoryManager->gfxPartition.heapAllocate(internalHeapIndex, size); EXPECT_NE(0llu, alloc); - size_t allocationSize = 4 * 1024 * 1024 * 1024llu; + size_t allocationSize = 4 * GB; auto graphicsAllocation = memoryManager->allocate32BitGraphicsMemory(allocationSize, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP); EXPECT_EQ(nullptr, graphicsAllocation); EXPECT_TRUE(pDevice->getDeviceInfo().force32BitAddressess); @@ -1166,7 +1131,7 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag DrmAllocation *drmAllocation = static_cast(imageGraphicsAllocation); EXPECT_EQ(imgInfo.size, drmAllocation->getBO()->peekUnmapSize()); - if (memoryManager->getDrmLimitedRangeAllocator() != nullptr) { + if (memoryManager->isLimitedRange()) { EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); } else { EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType()); @@ -1181,7 +1146,7 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag memoryManager->freeGraphicsMemory(imageGraphicsAllocation); - if (memoryManager->getDrmLimitedRangeAllocator() == nullptr) { + if (!memoryManager->isLimitedRange()) { EXPECT_EQ(1, mmapMockCallCount); EXPECT_EQ(1, munmapMockCallCount); } @@ -1391,8 +1356,8 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenMemoryAllocatedForImageThe // if limitedRangeAllocator is enabled, gpuRange is acquired and it should be // set as unmapsize for freeing in the furture. - auto limitedRangeAllocator = memoryManager->getDrmLimitedRangeAllocator(); - if (!limitedRangeAllocator) { + auto limitedRange = memoryManager->isLimitedRange(); + if (!limitedRange) { EXPECT_EQ(0u, drmAllocation->getBO()->peekUnmapSize()); } else { EXPECT_NE(0u, drmAllocation->getBO()->peekUnmapSize()); @@ -1784,7 +1749,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); - if (memoryManager->getDrmLimitedRangeAllocator() != nullptr) { + if (memoryManager->isLimitedRange()) { EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); } else { EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType()); @@ -1792,7 +1757,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre memoryManager->freeGraphicsMemory(graphicsAllocation); - if (memoryManager->getDrmLimitedRangeAllocator() == nullptr) { + if (!memoryManager->isLimitedRange()) { EXPECT_EQ(1, mmapMockCallCount); EXPECT_EQ(1, munmapMockCallCount); } @@ -1829,7 +1794,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs EXPECT_FALSE(graphicsAllocation->is32BitAllocation()); EXPECT_EQ(1, lseekCalledCount); - if (memoryManager->getDrmLimitedRangeAllocator() != nullptr) { + if (memoryManager->isLimitedRange()) { EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType()); } else { EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType()); @@ -1837,7 +1802,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs memoryManager->freeGraphicsMemory(graphicsAllocation); - if (memoryManager->getDrmLimitedRangeAllocator() == nullptr) { + if (!memoryManager->isLimitedRange()) { EXPECT_EQ(1, mmapMockCallCount); EXPECT_EQ(1, munmapMockCallCount); } @@ -2115,12 +2080,12 @@ TEST_F(DrmMemoryManagerTest, given32BitAllocatorWithHeapAllocatorWhenLargerFragm memoryManager->setForce32BitAllocations(true); size_t allocationSize = 4 * MemoryConstants::pageSize; - auto ptr = memoryManager->allocator32Bit->allocate(allocationSize); + auto ptr = memoryManager->gfxPartition.heapAllocate(HeapIndex::HEAP_EXTERNAL, allocationSize); size_t smallAllocationSize = MemoryConstants::pageSize; - memoryManager->allocator32Bit->allocate(smallAllocationSize); + memoryManager->gfxPartition.heapAllocate(HeapIndex::HEAP_EXTERNAL, smallAllocationSize); //now free first allocation , this will move it to chunks - memoryManager->allocator32Bit->free(ptr, allocationSize); + memoryManager->gfxPartition.heapFree(HeapIndex::HEAP_EXTERNAL, ptr, allocationSize); //now ask for 3 pages, this will give ptr from chunks size_t pages3size = 3 * MemoryConstants::pageSize; @@ -2213,8 +2178,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, drmAllocation); - auto internalAllocator = memoryManager->getDrmInternal32BitAllocator(); - EXPECT_NE(nullptr, drmAllocation->getUnderlyingBuffer()); EXPECT_EQ(bufferSize, drmAllocation->getUnderlyingBufferSize()); @@ -2222,7 +2185,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit auto gpuPtr = drmAllocation->getGpuAddress(); - auto heapBase = internalAllocator->getBase(); + auto heapBase = memoryManager->getInternalHeapBaseAddress(); auto heapSize = 4 * GB; EXPECT_GE(gpuPtr, heapBase); @@ -2250,8 +2213,6 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternalAlloc auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, drmAllocation); - auto internalAllocator = memoryManager->getDrmInternal32BitAllocator(); - EXPECT_NE(nullptr, drmAllocation->getUnderlyingBuffer()); EXPECT_EQ(bufferSize, drmAllocation->getUnderlyingBufferSize()); @@ -2262,7 +2223,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternalAlloc auto gpuPtr = drmAllocation->getGpuAddress(); - auto heapBase = internalAllocator->getBase(); + auto heapBase = memoryManager->getInternalHeapBaseAddress(); auto heapSize = 4 * GB; EXPECT_GE(gpuPtr, heapBase); @@ -2316,8 +2277,6 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit auto drmAllocation = static_cast(memoryManager->allocate32BitGraphicsMemory(bufferSize, ptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP)); ASSERT_NE(nullptr, drmAllocation); - auto internalAllocator = memoryManager->getDrmInternal32BitAllocator(); - EXPECT_NE(nullptr, drmAllocation->getUnderlyingBuffer()); EXPECT_EQ(ptr, drmAllocation->getUnderlyingBuffer()); EXPECT_EQ(bufferSize, drmAllocation->getUnderlyingBufferSize()); @@ -2326,7 +2285,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit auto gpuPtr = drmAllocation->getGpuAddress(); - auto heapBase = internalAllocator->getBase(); + auto heapBase = memoryManager->getInternalHeapBaseAddress(); auto heapSize = 4 * GB; EXPECT_GE(gpuPtr, heapBase); @@ -2398,7 +2357,6 @@ TEST(Allocator32BitUsingHeapAllocator, given32BitAllocatorWhenFirstMMapFailsThen auto ptr = mock32BitAllocator.allocate(size); EXPECT_NE(0llu, ptr); EXPECT_EQ(2u, mmapCallCount); - EXPECT_NE(nullptr, osInternals->heapBasePtr); EXPECT_NE(0u, osInternals->heapSize); } @@ -2421,7 +2379,7 @@ TEST(MmapFlags, givenVariousMmapParametersGetTimeDeltaForTheOperation) { std::vector pointersForFree; //allocate 4GB. - auto size = 4 * 1024 * 1024 * 1023u; + auto size = 4 * GB; unsigned int maxTime = 0; unsigned int minTime = -1; unsigned int totalTime = 0; @@ -2481,8 +2439,7 @@ TEST_F(DrmMemoryManagerBasic, givenDefaultDrmMemoryManagerWhenItIsQueriedForInte true, true, executionEnvironment)); - auto internalAllocator = memoryManager->getDrmInternal32BitAllocator(); - auto heapBase = internalAllocator->getBase(); + auto heapBase = memoryManager->gfxPartition.getHeapBase(internalHeapIndex); EXPECT_EQ(heapBase, memoryManager->getInternalHeapBaseAddress()); } @@ -2706,7 +2663,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(false, true, true, *executionEnvironment)); ASSERT_NE(nullptr, memoryManager->getPinBB()); - size_t size = 10 * 1024 * 1024; + size_t size = 10 * MB; void *ptr = ::alignedMalloc(size, 4096); auto alloc = static_cast(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr)); ASSERT_NE(nullptr, alloc); @@ -2805,7 +2762,7 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); - allocationData.size = 4llu * 1024 * 1024 + 16 * 1024; + allocationData.size = 4 * MB + 16 * 1024; allocationData.hostPtr = reinterpret_cast(0x10000000); auto allocation0 = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData); @@ -2814,12 +2771,12 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor memoryManager->freeGraphicsMemory(allocation0); - allocationData.size = 4llu * 1024 * 1024 + 12 * 1024; + allocationData.size = 4 * MB + 12 * 1024; allocationData.hostPtr = reinterpret_cast(0x30000000); allocation0 = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData); - EXPECT_EQ((uint64_t)(allocation0->getBO()->peekUnmapSize()), 4llu * 1024 * 1024 + 16 * 1024); - EXPECT_EQ((uint64_t)(allocation0->getBO()->peekSize()), 4llu * 1024 * 1024 + 12 * 1024); + EXPECT_EQ((uint64_t)(allocation0->getBO()->peekUnmapSize()), 4 * MB + 16 * 1024); + EXPECT_EQ((uint64_t)(allocation0->getBO()->peekSize()), 4 * MB + 12 * 1024); memoryManager->freeGraphicsMemory(allocation0); memoryManager->freeGraphicsMemory(allocation1); @@ -2831,7 +2788,7 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); - allocationData.size = 64llu * 1024 * 1024 * 1024; + allocationData.size = 64 * GB; allocationData.hostPtr = reinterpret_cast(0x100000000000); EXPECT_FALSE(memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData)); } @@ -2881,7 +2838,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH mock->ioctl_expected.gemWait = 1; AllocationData allocationData; - allocationData.size = 10 * 1024 * 1024; // bigger than threshold + allocationData.size = 10 * MB; // bigger than threshold allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096); allocationData.flags.forcePin = true; auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData); @@ -3043,32 +3000,15 @@ TEST_F(DrmMemoryManagerBasic, ifLimitedRangeAllocatorAvailableWhenAskedForAlloca memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF); - auto limitedRangeAllocator = memoryManager->getDrmLimitedRangeAllocator(); size_t size = 100u; - auto ptr = limitedRangeAllocator->allocate(size); - uintptr_t address64bit = (uintptr_t)ptr - (uintptr_t)limitedRangeAllocator->getBase(); + auto ptr = memoryManager->gfxPartition.heapAllocate(HeapIndex::HEAP_STANDARD, size); + auto address64bit = ptrDiff(ptr, memoryManager->gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD)); EXPECT_LT(address64bit, platformDevices[0]->capabilityTable.gpuAddressSpace); EXPECT_LT(0u, address64bit); - limitedRangeAllocator->free(ptr, size); -} - -TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWithNonZeroBaseAndSizeWhenAskedForBaseThenCorrectBaseIsReturned) { - uint64_t size = 100u; - uint64_t base = 0x23000; - AllocatorLimitedRange allocator(base, size); - - EXPECT_EQ(base, allocator.getBase()); -} - -TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWithZeroBaseAndSizeWhenAskedForBaseThenCorrectBaseIsReturned) { - uint64_t size = 100u; - uint64_t base = 0x1000; - AllocatorLimitedRange allocator(base, size); - - EXPECT_EQ(base, allocator.getBase()); + memoryManager->gfxPartition.heapFree(HeapIndex::HEAP_STANDARD, ptr, size); } TEST_F(DrmMemoryManagerBasic, givenDisabledHostPtrTrackingWhenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWithNotAlignedPtrIsPassedThenAllocationIsCreated) {