Skip to content

Commit ffe2bd3

Browse files
Add ULTs for OsAgnosticMemoryManager
Related-To: NEO-2877 Change-Id: Id80fd66ced9d711ff74d85fa48741c95f9f750bb Signed-off-by: Igor Venevtsev <igor.venevtsev@intel.com>
1 parent c24bbac commit ffe2bd3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,43 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenForce32bitallocationI
579579
EXPECT_TRUE(memoryManager.peekForce32BitAllocations());
580580
}
581581

582+
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAskedFor32BitAllocationWhenLimitedAllocationIsEnabledThenGpuRangeFromExternalHeapIsAllocatiedAndBaseAddressIsSet) {
583+
if (is32bit) {
584+
GTEST_SKIP();
585+
}
586+
587+
ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment();
588+
MockMemoryManager memoryManager(*executionEnvironment);
589+
memoryManager.setForce32BitAllocations(true);
590+
memoryManager.forceLimitedRangeAllocator(0xFFFFFFFFF);
591+
592+
AllocationData allocationData;
593+
MockMemoryManager::getAllocationData(allocationData, {MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}, nullptr, StorageInfo{});
594+
auto gfxAllocation = memoryManager.allocateGraphicsMemoryWithAlignment(allocationData);
595+
ASSERT_NE(gfxAllocation, nullptr);
596+
EXPECT_NE(gfxAllocation->getGpuBaseAddress(), 0ull);
597+
EXPECT_EQ(gfxAllocation->getGpuBaseAddress(), memoryManager.getExternalHeapBaseAddress());
598+
memoryManager.freeGraphicsMemory(gfxAllocation);
599+
}
600+
601+
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAskedForNon32BitAllocationWhenLimitedAllocationIsEnabledThenGpuRangeFromiStandardHeapIsAllocatiedAndBaseAddressIsNotSet) {
602+
if (is32bit) {
603+
GTEST_SKIP();
604+
}
605+
606+
ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment();
607+
MockMemoryManager memoryManager(*executionEnvironment);
608+
memoryManager.forceLimitedRangeAllocator(0xFFFFFFFFF);
609+
610+
AllocationData allocationData;
611+
MockMemoryManager::getAllocationData(allocationData, {MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER}, nullptr, StorageInfo{});
612+
auto gfxAllocation = memoryManager.allocateGraphicsMemoryWithAlignment(allocationData);
613+
ASSERT_NE(gfxAllocation, nullptr);
614+
EXPECT_EQ(gfxAllocation->getGpuBaseAddress(), 0ull);
615+
EXPECT_EQ(gfxAllocation->getGpuAddress(), memoryManager.gfxPartition->getHeapLimit(HeapIndex::HEAP_STANDARD) + 1 - GfxPartition::heapGranularity - MemoryConstants::pageSize);
616+
memoryManager.freeGraphicsMemory(gfxAllocation);
617+
}
618+
582619
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemoryForImageIsCalledThenGraphicsAllocationIsReturned) {
583620
ExecutionEnvironment *executionEnvironment = platformImpl->peekExecutionEnvironment();
584621
MockMemoryManager memoryManager(*executionEnvironment);

unit_tests/mocks/mock_memory_manager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
3131
public:
3232
using MemoryManager::allocateGraphicsMemoryForNonSvmHostPtr;
3333
using MemoryManager::allocateGraphicsMemoryInPreferredPool;
34+
using MemoryManager::allocateGraphicsMemoryWithAlignment;
3435
using MemoryManager::allocateGraphicsMemoryWithProperties;
3536
using MemoryManager::AllocationData;
3637
using MemoryManager::createGraphicsAllocation;
@@ -100,6 +101,8 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
100101
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType);
101102
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
102103

104+
void forceLimitedRangeAllocator(uint64_t range) { gfxPartition->init(range, 0); }
105+
103106
uint32_t freeGraphicsMemoryCalled = 0u;
104107
uint32_t unlockResourceCalled = 0u;
105108
uint32_t lockResourceCalled = 0u;

0 commit comments

Comments
 (0)