mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Revert "[2/n] Use GfxPartition for 32-bit allocations - DrmMemoryManager"
This reverts commit 1ce2f9564a.
Related-To: NEO-2877
Change-Id: Id17e0bce560ed1d934412067f9e41d39c529018f
Signed-off-by: Venevtsev, Igor <igor.venevtsev@intel.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
||||
@@ -56,6 +56,10 @@ AllocationProperties createAllocationProperties(size_t size, bool forcePin) {
|
||||
typedef Test<DrmMemoryManagerFixture> DrmMemoryManagerTest;
|
||||
typedef Test<DrmMemoryManagerFixtureWithoutQuietIoctlExpectation> DrmMemoryManagerWithExplicitExpectationsTest;
|
||||
|
||||
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDefaultDrmMemoryMangerWhenItIsCreatedThenItContainsInternal32BitAllocator) {
|
||||
EXPECT_NE(nullptr, memoryManager->getDrmInternal32BitAllocator());
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) {
|
||||
void *cpuPtr = (void *)0x30000;
|
||||
size_t size = 0x1000;
|
||||
@@ -213,7 +217,7 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation
|
||||
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, true, false, *executionEnvironment);
|
||||
ASSERT_NE(nullptr, memoryManager->getPinBB());
|
||||
|
||||
allocationData.size = 10 * MB;
|
||||
allocationData.size = 10 * 1024 * 1024;
|
||||
allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096);
|
||||
allocationData.flags.forcePin = true;
|
||||
auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData);
|
||||
@@ -707,8 +711,10 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedFor32BitAllocationThen32
|
||||
EXPECT_NE(nullptr, allocation->getUnderlyingBuffer());
|
||||
EXPECT_GE(allocation->getUnderlyingBufferSize(), size);
|
||||
|
||||
auto address64bit = allocation->getGpuAddressToPatch();
|
||||
EXPECT_LT(address64bit, MemoryConstants::max32BitAddress);
|
||||
uintptr_t address64bit = (uintptr_t)allocation->getGpuAddressToPatch();
|
||||
if (is32BitOsAllocatorAvailable) {
|
||||
EXPECT_LT(address64bit, max32BitAddress);
|
||||
}
|
||||
auto bo = allocation->getBO();
|
||||
EXPECT_GE(bo->peekUnmapSize(), 0u);
|
||||
EXPECT_TRUE(allocation->is32BitAllocation());
|
||||
@@ -738,6 +744,26 @@ 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;
|
||||
@@ -765,7 +791,11 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferAllocationThen
|
||||
auto bufferAddress = buffer->getGraphicsAllocation()->getGpuAddress();
|
||||
auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress();
|
||||
|
||||
EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress);
|
||||
uintptr_t address64bit = (uintptr_t)bufferAddress;
|
||||
|
||||
if (is32BitOsAllocatorAvailable) {
|
||||
EXPECT_LT(address64bit - baseAddress, max32BitAddress);
|
||||
}
|
||||
|
||||
delete buffer;
|
||||
}
|
||||
@@ -799,16 +829,20 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFromHos
|
||||
auto bufferAddress = buffer->getGraphicsAllocation()->getGpuAddress();
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(buffer->getGraphicsAllocation());
|
||||
|
||||
auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress();
|
||||
EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress);
|
||||
uintptr_t address64bitOnGpu = (uintptr_t)bufferAddress;
|
||||
|
||||
if (is32BitOsAllocatorAvailable) {
|
||||
auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress();
|
||||
EXPECT_LT(address64bitOnGpu - baseAddress, max32BitAddress);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(drmAllocation->is32BitAllocation());
|
||||
|
||||
auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer();
|
||||
auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize));
|
||||
auto allocationCpuPtr = (uintptr_t)drmAllocation->getUnderlyingBuffer();
|
||||
auto allocationPageOffset = allocationCpuPtr - alignDown(allocationCpuPtr, MemoryConstants::pageSize);
|
||||
|
||||
auto allocationGpuPtr = drmAllocation->getGpuAddress();
|
||||
auto allocationGpuOffset = ptrDiff(allocationGpuPtr, alignDown(allocationGpuPtr, MemoryConstants::pageSize));
|
||||
auto allocationGpuPtr = (uintptr_t)drmAllocation->getGpuAddress();
|
||||
auto allocationGpuOffset = allocationGpuPtr - alignDown(allocationGpuPtr, MemoryConstants::pageSize);
|
||||
|
||||
auto bufferObject = drmAllocation->getBO();
|
||||
|
||||
@@ -861,15 +895,19 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64B
|
||||
EXPECT_TRUE(buffer->isMemObjZeroCopy());
|
||||
auto bufferAddress = buffer->getGraphicsAllocation()->getGpuAddress();
|
||||
|
||||
auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress();
|
||||
EXPECT_LT(ptrDiff(bufferAddress, baseAddress), MemoryConstants::max32BitAddress);
|
||||
uintptr_t address64bit = (uintptr_t)bufferAddress;
|
||||
|
||||
if (is32BitOsAllocatorAvailable) {
|
||||
auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress();
|
||||
EXPECT_LT(address64bit - baseAddress, max32BitAddress);
|
||||
}
|
||||
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(buffer->getGraphicsAllocation());
|
||||
|
||||
EXPECT_TRUE(drmAllocation->is32BitAllocation());
|
||||
|
||||
auto allocationCpuPtr = drmAllocation->getUnderlyingBuffer();
|
||||
auto allocationPageOffset = ptrDiff(allocationCpuPtr, alignDown(allocationCpuPtr, MemoryConstants::pageSize));
|
||||
auto allocationCpuPtr = (uintptr_t)drmAllocation->getUnderlyingBuffer();
|
||||
auto allocationPageOffset = allocationCpuPtr - alignDown(allocationCpuPtr, MemoryConstants::pageSize);
|
||||
auto bufferObject = drmAllocation->getBO();
|
||||
|
||||
EXPECT_NE(0u, bufferObject->peekUnmapSize());
|
||||
@@ -892,22 +930,21 @@ TEST_F(DrmMemoryManagerTest, Given32bitAllocatorWhenAskedForBufferCreatedFrom64B
|
||||
TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenLimitedRangeAllocatorSetThenHeapSizeAndEndAddrCorrectlySetForGivenGpuRange) {
|
||||
memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF);
|
||||
|
||||
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);
|
||||
// check if limitedGpuAddressRangeAllocator is initialized
|
||||
EXPECT_NE(memoryManager->limitedGpuAddressRangeAllocator.get(), nullptr);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForAllocationWithAlignmentThenCorrectAllocatorTypeSelected) {
|
||||
// if limitedRangeAllocator is enabled by default on the platform, only limitedRangeAllocator case will be tested.
|
||||
auto limitedRange = memoryManager->isLimitedRange();
|
||||
if (limitedRange) {
|
||||
auto limitedRangeAllocator = memoryManager->getDrmLimitedRangeAllocator();
|
||||
if (limitedRangeAllocator) {
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.gemWait = 1;
|
||||
mock->ioctl_expected.gemClose = 1;
|
||||
@@ -924,7 +961,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 (limitedRange) {
|
||||
if (limitedRangeAllocator) {
|
||||
EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, bo->peekAllocationType());
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
} else {
|
||||
@@ -949,12 +986,9 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForAllocationWithAlignme
|
||||
|
||||
TestedDrmMemoryManager::AllocationData allocationData;
|
||||
|
||||
// emulate GPU address space exhaust
|
||||
memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF);
|
||||
memoryManager->gfxPartition.heapInit(HeapIndex::HEAP_STANDARD, 0x0, 0x10000);
|
||||
|
||||
memoryManager->forceLimitedRangeAllocator(0xFFFF);
|
||||
// set size to something bigger than allowed space
|
||||
allocationData.size = 0x20000;
|
||||
allocationData.size = 0x10000;
|
||||
EXPECT_EQ(nullptr, memoryManager->allocateGraphicsMemoryWithAlignment(allocationData));
|
||||
}
|
||||
|
||||
@@ -1009,7 +1043,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCr
|
||||
memoryManager->setForce32BitAllocations(true);
|
||||
context.setMemoryManager(memoryManager);
|
||||
|
||||
size_t size = 2 * GB;
|
||||
size_t size = 2 * 1024 * 1024 * 1024u;
|
||||
void *ptr = reinterpret_cast<void *>(0x100000000000);
|
||||
auto retVal = CL_SUCCESS;
|
||||
|
||||
@@ -1020,7 +1054,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCr
|
||||
ptr,
|
||||
retVal);
|
||||
|
||||
size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned
|
||||
size_t size2 = 4 * 1024 * 1024 * 1024u - 1u;
|
||||
|
||||
auto buffer2 = Buffer::create(
|
||||
&context,
|
||||
@@ -1032,12 +1066,12 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenUseHostPtrAndAllocHostPtrAreCr
|
||||
EXPECT_NE(retVal, CL_SUCCESS);
|
||||
EXPECT_EQ(nullptr, buffer2);
|
||||
|
||||
if (buffer) {
|
||||
if (is32BitOsAllocatorAvailable && buffer) {
|
||||
auto bufferPtr = buffer->getGraphicsAllocation()->getGpuAddress();
|
||||
|
||||
EXPECT_TRUE(buffer->getGraphicsAllocation()->is32BitAllocation());
|
||||
auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress();
|
||||
EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress);
|
||||
EXPECT_LT((uintptr_t)(bufferPtr - baseAddress), max32BitAddress);
|
||||
}
|
||||
|
||||
delete buffer;
|
||||
@@ -1051,7 +1085,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCr
|
||||
memoryManager->setForce32BitAllocations(true);
|
||||
context.setMemoryManager(memoryManager);
|
||||
|
||||
size_t size = 2 * GB;
|
||||
size_t size = 2 * 1024 * 1024 * 1024u;
|
||||
void *ptr = reinterpret_cast<void *>(0x100000000000);
|
||||
auto retVal = CL_SUCCESS;
|
||||
|
||||
@@ -1062,7 +1096,7 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCr
|
||||
nullptr,
|
||||
retVal);
|
||||
|
||||
size_t size2 = 4 * GB - MemoryConstants::pageSize; // Keep size aligned
|
||||
size_t size2 = 4 * 1024 * 1024 * 1024u - 1u;
|
||||
|
||||
auto buffer2 = Buffer::create(
|
||||
&context,
|
||||
@@ -1074,12 +1108,12 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCr
|
||||
EXPECT_NE(retVal, CL_SUCCESS);
|
||||
EXPECT_EQ(nullptr, buffer2);
|
||||
|
||||
if (buffer) {
|
||||
if (is32BitOsAllocatorAvailable && buffer) {
|
||||
auto bufferPtr = buffer->getGraphicsAllocation()->getGpuAddress();
|
||||
|
||||
EXPECT_TRUE(buffer->getGraphicsAllocation()->is32BitAllocation());
|
||||
auto baseAddress = buffer->getGraphicsAllocation()->getGpuBaseAddress();
|
||||
EXPECT_LT(ptrDiff(bufferPtr, baseAddress), MemoryConstants::max32BitAddress);
|
||||
EXPECT_LT((uintptr_t)(bufferPtr - baseAddress), max32BitAddress);
|
||||
}
|
||||
|
||||
delete buffer;
|
||||
@@ -1091,11 +1125,12 @@ TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIs
|
||||
memoryManager->setForce32BitAllocations(true);
|
||||
std::unique_ptr<Device> pDevice(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
|
||||
auto allocator = memoryManager->getDrmInternal32BitAllocator();
|
||||
size_t size = getSizeToMap();
|
||||
auto alloc = memoryManager->gfxPartition.heapAllocate(internalHeapIndex, size);
|
||||
auto alloc = allocator->allocate(size);
|
||||
EXPECT_NE(0llu, alloc);
|
||||
|
||||
size_t allocationSize = 4 * GB;
|
||||
size_t allocationSize = 4 * 1024 * 1024 * 1024llu;
|
||||
auto graphicsAllocation = memoryManager->allocate32BitGraphicsMemory(allocationSize, nullptr, GraphicsAllocation::AllocationType::INTERNAL_HEAP);
|
||||
EXPECT_EQ(nullptr, graphicsAllocation);
|
||||
EXPECT_TRUE(pDevice->getDeviceInfo().force32BitAddressess);
|
||||
@@ -1131,7 +1166,7 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag
|
||||
DrmAllocation *drmAllocation = static_cast<DrmAllocation *>(imageGraphicsAllocation);
|
||||
EXPECT_EQ(imgInfo.size, drmAllocation->getBO()->peekUnmapSize());
|
||||
|
||||
if (memoryManager->isLimitedRange()) {
|
||||
if (memoryManager->getDrmLimitedRangeAllocator() != nullptr) {
|
||||
EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType());
|
||||
} else {
|
||||
EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType());
|
||||
@@ -1146,7 +1181,7 @@ TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImag
|
||||
|
||||
memoryManager->freeGraphicsMemory(imageGraphicsAllocation);
|
||||
|
||||
if (!memoryManager->isLimitedRange()) {
|
||||
if (memoryManager->getDrmLimitedRangeAllocator() == nullptr) {
|
||||
EXPECT_EQ(1, mmapMockCallCount);
|
||||
EXPECT_EQ(1, munmapMockCallCount);
|
||||
}
|
||||
@@ -1356,8 +1391,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 limitedRange = memoryManager->isLimitedRange();
|
||||
if (!limitedRange) {
|
||||
auto limitedRangeAllocator = memoryManager->getDrmLimitedRangeAllocator();
|
||||
if (!limitedRangeAllocator) {
|
||||
EXPECT_EQ(0u, drmAllocation->getBO()->peekUnmapSize());
|
||||
} else {
|
||||
EXPECT_NE(0u, drmAllocation->getBO()->peekUnmapSize());
|
||||
@@ -1749,7 +1784,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre
|
||||
EXPECT_FALSE(graphicsAllocation->is32BitAllocation());
|
||||
EXPECT_EQ(1, lseekCalledCount);
|
||||
|
||||
if (memoryManager->isLimitedRange()) {
|
||||
if (memoryManager->getDrmLimitedRangeAllocator() != nullptr) {
|
||||
EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType());
|
||||
} else {
|
||||
EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType());
|
||||
@@ -1757,7 +1792,7 @@ TEST_F(DrmMemoryManagerTest, given32BitAddressingWhenBufferFromSharedHandleIsCre
|
||||
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
|
||||
if (!memoryManager->isLimitedRange()) {
|
||||
if (memoryManager->getDrmLimitedRangeAllocator() == nullptr) {
|
||||
EXPECT_EQ(1, mmapMockCallCount);
|
||||
EXPECT_EQ(1, munmapMockCallCount);
|
||||
}
|
||||
@@ -1794,7 +1829,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs
|
||||
EXPECT_FALSE(graphicsAllocation->is32BitAllocation());
|
||||
EXPECT_EQ(1, lseekCalledCount);
|
||||
|
||||
if (memoryManager->isLimitedRange()) {
|
||||
if (memoryManager->getDrmLimitedRangeAllocator() != nullptr) {
|
||||
EXPECT_EQ(INTERNAL_ALLOCATOR_WITH_DYNAMIC_BITRANGE, drmAllocation->getBO()->peekAllocationType());
|
||||
} else {
|
||||
EXPECT_EQ(MMAP_ALLOCATOR, drmAllocation->getBO()->peekAllocationType());
|
||||
@@ -1802,7 +1837,7 @@ TEST_F(DrmMemoryManagerTest, givenNon32BitAddressingWhenBufferFromSharedHandleIs
|
||||
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
|
||||
if (!memoryManager->isLimitedRange()) {
|
||||
if (memoryManager->getDrmLimitedRangeAllocator() == nullptr) {
|
||||
EXPECT_EQ(1, mmapMockCallCount);
|
||||
EXPECT_EQ(1, munmapMockCallCount);
|
||||
}
|
||||
@@ -2080,12 +2115,12 @@ TEST_F(DrmMemoryManagerTest, given32BitAllocatorWithHeapAllocatorWhenLargerFragm
|
||||
memoryManager->setForce32BitAllocations(true);
|
||||
|
||||
size_t allocationSize = 4 * MemoryConstants::pageSize;
|
||||
auto ptr = memoryManager->gfxPartition.heapAllocate(HeapIndex::HEAP_EXTERNAL, allocationSize);
|
||||
auto ptr = memoryManager->allocator32Bit->allocate(allocationSize);
|
||||
size_t smallAllocationSize = MemoryConstants::pageSize;
|
||||
memoryManager->gfxPartition.heapAllocate(HeapIndex::HEAP_EXTERNAL, smallAllocationSize);
|
||||
memoryManager->allocator32Bit->allocate(smallAllocationSize);
|
||||
|
||||
//now free first allocation , this will move it to chunks
|
||||
memoryManager->gfxPartition.heapFree(HeapIndex::HEAP_EXTERNAL, ptr, allocationSize);
|
||||
memoryManager->allocator32Bit->free(ptr, allocationSize);
|
||||
|
||||
//now ask for 3 pages, this will give ptr from chunks
|
||||
size_t pages3size = 3 * MemoryConstants::pageSize;
|
||||
@@ -2178,6 +2213,8 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(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());
|
||||
|
||||
@@ -2185,7 +2222,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit
|
||||
|
||||
auto gpuPtr = drmAllocation->getGpuAddress();
|
||||
|
||||
auto heapBase = memoryManager->getInternalHeapBaseAddress();
|
||||
auto heapBase = internalAllocator->getBase();
|
||||
auto heapSize = 4 * GB;
|
||||
|
||||
EXPECT_GE(gpuPtr, heapBase);
|
||||
@@ -2213,6 +2250,8 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternalAlloc
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(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());
|
||||
|
||||
@@ -2223,7 +2262,7 @@ TEST_F(DrmMemoryManagerTest, givenLimitedRangeAllocatorWhenAskedForInternalAlloc
|
||||
|
||||
auto gpuPtr = drmAllocation->getGpuAddress();
|
||||
|
||||
auto heapBase = memoryManager->getInternalHeapBaseAddress();
|
||||
auto heapBase = internalAllocator->getBase();
|
||||
auto heapSize = 4 * GB;
|
||||
|
||||
EXPECT_GE(gpuPtr, heapBase);
|
||||
@@ -2277,6 +2316,8 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(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());
|
||||
@@ -2285,7 +2326,7 @@ TEST_F(DrmMemoryManagerTest, givenMemoryManagerWhenAskedForInternalAllocationWit
|
||||
|
||||
auto gpuPtr = drmAllocation->getGpuAddress();
|
||||
|
||||
auto heapBase = memoryManager->getInternalHeapBaseAddress();
|
||||
auto heapBase = internalAllocator->getBase();
|
||||
auto heapSize = 4 * GB;
|
||||
|
||||
EXPECT_GE(gpuPtr, heapBase);
|
||||
@@ -2357,6 +2398,7 @@ 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);
|
||||
}
|
||||
@@ -2379,7 +2421,7 @@ TEST(MmapFlags, givenVariousMmapParametersGetTimeDeltaForTheOperation) {
|
||||
|
||||
std::vector<void *> pointersForFree;
|
||||
//allocate 4GB.
|
||||
auto size = 4 * GB;
|
||||
auto size = 4 * 1024 * 1024 * 1023u;
|
||||
unsigned int maxTime = 0;
|
||||
unsigned int minTime = -1;
|
||||
unsigned int totalTime = 0;
|
||||
@@ -2439,7 +2481,8 @@ TEST_F(DrmMemoryManagerBasic, givenDefaultDrmMemoryManagerWhenItIsQueriedForInte
|
||||
true,
|
||||
true,
|
||||
executionEnvironment));
|
||||
auto heapBase = memoryManager->gfxPartition.getHeapBase(internalHeapIndex);
|
||||
auto internalAllocator = memoryManager->getDrmInternal32BitAllocator();
|
||||
auto heapBase = internalAllocator->getBase();
|
||||
EXPECT_EQ(heapBase, memoryManager->getInternalHeapBaseAddress());
|
||||
}
|
||||
|
||||
@@ -2663,7 +2706,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE
|
||||
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(false, true, true, *executionEnvironment));
|
||||
ASSERT_NE(nullptr, memoryManager->getPinBB());
|
||||
|
||||
size_t size = 10 * MB;
|
||||
size_t size = 10 * 1024 * 1024;
|
||||
void *ptr = ::alignedMalloc(size, 4096);
|
||||
auto alloc = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{false, size}, ptr));
|
||||
ASSERT_NE(nullptr, alloc);
|
||||
@@ -2762,7 +2805,7 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor
|
||||
|
||||
memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF);
|
||||
|
||||
allocationData.size = 4 * MB + 16 * 1024;
|
||||
allocationData.size = 4llu * 1024 * 1024 + 16 * 1024;
|
||||
allocationData.hostPtr = reinterpret_cast<const void *>(0x10000000);
|
||||
auto allocation0 = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData);
|
||||
|
||||
@@ -2771,12 +2814,12 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor
|
||||
|
||||
memoryManager->freeGraphicsMemory(allocation0);
|
||||
|
||||
allocationData.size = 4 * MB + 12 * 1024;
|
||||
allocationData.size = 4llu * 1024 * 1024 + 12 * 1024;
|
||||
allocationData.hostPtr = reinterpret_cast<const void *>(0x30000000);
|
||||
allocation0 = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData);
|
||||
|
||||
EXPECT_EQ((uint64_t)(allocation0->getBO()->peekUnmapSize()), 4 * MB + 16 * 1024);
|
||||
EXPECT_EQ((uint64_t)(allocation0->getBO()->peekSize()), 4 * MB + 12 * 1024);
|
||||
EXPECT_EQ((uint64_t)(allocation0->getBO()->peekUnmapSize()), 4llu * 1024 * 1024 + 16 * 1024);
|
||||
EXPECT_EQ((uint64_t)(allocation0->getBO()->peekSize()), 4llu * 1024 * 1024 + 12 * 1024);
|
||||
|
||||
memoryManager->freeGraphicsMemory(allocation0);
|
||||
memoryManager->freeGraphicsMemory(allocation1);
|
||||
@@ -2788,7 +2831,7 @@ TEST_F(DrmMemoryManagerBasic, givenDrmMemoryManagerWhenAllocateGraphicsMemoryFor
|
||||
|
||||
memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF);
|
||||
|
||||
allocationData.size = 64 * GB;
|
||||
allocationData.size = 64llu * 1024 * 1024 * 1024;
|
||||
allocationData.hostPtr = reinterpret_cast<const void *>(0x100000000000);
|
||||
EXPECT_FALSE(memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData));
|
||||
}
|
||||
@@ -2838,7 +2881,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH
|
||||
mock->ioctl_expected.gemWait = 1;
|
||||
|
||||
AllocationData allocationData;
|
||||
allocationData.size = 10 * MB; // bigger than threshold
|
||||
allocationData.size = 10 * 1024 * 1024; // bigger than threshold
|
||||
allocationData.hostPtr = ::alignedMalloc(allocationData.size, 4096);
|
||||
allocationData.flags.forcePin = true;
|
||||
auto alloc = memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData);
|
||||
@@ -3000,15 +3043,32 @@ TEST_F(DrmMemoryManagerBasic, ifLimitedRangeAllocatorAvailableWhenAskedForAlloca
|
||||
|
||||
memoryManager->forceLimitedRangeAllocator(0xFFFFFFFFF);
|
||||
|
||||
auto limitedRangeAllocator = memoryManager->getDrmLimitedRangeAllocator();
|
||||
size_t size = 100u;
|
||||
auto ptr = memoryManager->gfxPartition.heapAllocate(HeapIndex::HEAP_STANDARD, size);
|
||||
auto address64bit = ptrDiff(ptr, memoryManager->gfxPartition.getHeapBase(HeapIndex::HEAP_STANDARD));
|
||||
auto ptr = limitedRangeAllocator->allocate(size);
|
||||
uintptr_t address64bit = (uintptr_t)ptr - (uintptr_t)limitedRangeAllocator->getBase();
|
||||
|
||||
EXPECT_LT(address64bit, platformDevices[0]->capabilityTable.gpuAddressSpace);
|
||||
|
||||
EXPECT_LT(0u, address64bit);
|
||||
|
||||
memoryManager->gfxPartition.heapFree(HeapIndex::HEAP_STANDARD, ptr, size);
|
||||
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());
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerBasic, givenDisabledHostPtrTrackingWhenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWithNotAlignedPtrIsPassedThenAllocationIsCreated) {
|
||||
|
||||
Reference in New Issue
Block a user