Cleanup host ptr manager

Change-Id: I0fc9df41a08255eef8072666c1c5c16806e0f7cf
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-10-24 08:46:54 +02:00
committed by sys_ocldev
parent e128cb7a7c
commit 129380c1a6
21 changed files with 271 additions and 183 deletions

View File

@@ -5,9 +5,12 @@
*
*/
#include "gtest/gtest.h"
#include "runtime/memory_manager/host_ptr_manager.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/ptr_math.h"
#include "runtime/memory_manager/memory_constants.h"
#include "unit_tests/fixtures/memory_manager_fixture.h"
#include "unit_tests/gen_common/test.h"
#include "unit_tests/mocks/mock_host_ptr_manager.h"
using namespace OCLRT;
@@ -15,7 +18,7 @@ TEST(HostPtrManager, AlignedPointerAndAlignedSizeAskedForAllocationCountReturnsO
auto size = MemoryConstants::pageSize * 10;
void *ptr = (void *)0x1000;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(1u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::MIDDLE);
@@ -35,7 +38,7 @@ TEST(HostPtrManager, AlignedPointerAndNotAlignedSizeAskedForAllocationCountRetur
auto size = MemoryConstants::pageSize * 10 - 1;
void *ptr = (void *)0x1000;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(2u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::MIDDLE);
@@ -58,7 +61,7 @@ TEST(HostPtrManager, NotAlignedPointerAndNotAlignedSizeAskedForAllocationCountRe
auto size = MemoryConstants::pageSize * 10 - 1;
void *ptr = (void *)0x1045;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(3u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::LEADING);
@@ -85,7 +88,7 @@ TEST(HostPtrManager, NotAlignedPointerAndNotAlignedSizeWithinOnePageAskedForAllo
auto size = 200;
void *ptr = (void *)0x1045;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(1u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::LEADING);
@@ -110,7 +113,7 @@ TEST(HostPtrManager, NotAlignedPointerAndNotAlignedSizeWithinTwoPagesAskedForAll
auto size = MemoryConstants::pageSize;
void *ptr = (void *)0x1045;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(2u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::LEADING);
@@ -136,7 +139,7 @@ TEST(HostPtrManager, AlignedPointerAndAlignedSizeOfOnePageAskedForAllocationCoun
auto size = MemoryConstants::pageSize * 10;
void *ptr = (void *)0x1000;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(1u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::MIDDLE);
@@ -161,7 +164,7 @@ TEST(HostPtrManager, NotAlignedPointerAndSizeThatFitsToPageAskedForAllocationCou
auto size = MemoryConstants::pageSize * 10 - 1;
void *ptr = (void *)0x1001;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(2u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::LEADING);
@@ -187,7 +190,7 @@ TEST(HostPtrManager, AlignedPointerAndPageSizeAskedForAllocationCountRetrunsMidd
auto size = MemoryConstants::pageSize;
void *ptr = (void *)0x1000;
AllocationRequirements reqs = HostPtrManager::getAllocationRequirements(ptr, size);
AllocationRequirements reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
EXPECT_EQ(1u, reqs.requiredFragmentsCount);
EXPECT_EQ(reqs.AllocationFragments[0].fragmentPosition, FragmentPosition::MIDDLE);
@@ -211,8 +214,8 @@ TEST(HostPtrManager, AlignedPointerAndPageSizeAskedForAllocationCountRetrunsMidd
TEST(HostPtrManager, AllocationRequirementsForMiddleAllocationThatIsNotStoredInManagerAskedForGraphicsAllocationReturnsNotAvailable) {
auto size = MemoryConstants::pageSize;
void *ptr = (void *)0x1000;
auto reqs = HostPtrManager::getAllocationRequirements(ptr, size);
HostPtrManager hostPtrManager;
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
MockHostPtrManager hostPtrManager;
auto gpuAllocationFragments = hostPtrManager.populateAlreadyAllocatedFragments(reqs, nullptr);
EXPECT_EQ(nullptr, gpuAllocationFragments.fragmentStorageData[0].osHandleStorage);
@@ -225,7 +228,7 @@ TEST(HostPtrManager, AllocationRequirementsForMiddleAllocationThatIsNotStoredInM
TEST(HostPtrManager, AllocationRequirementsForMiddleAllocationThatIsStoredInManagerAskedForGraphicsAllocationReturnsProperAllocationAndIncreasesRefCount) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
FragmentStorage allocationFragment;
auto cpuPtr = (void *)0x1000;
auto ptrSize = MemoryConstants::pageSize;
@@ -236,7 +239,7 @@ TEST(HostPtrManager, AllocationRequirementsForMiddleAllocationThatIsStoredInMana
hostPtrManager.storeFragment(allocationFragment);
auto reqs = HostPtrManager::getAllocationRequirements(cpuPtr, ptrSize);
auto reqs = MockHostPtrManager::getAllocationRequirements(cpuPtr, ptrSize);
auto gpuAllocationFragments = hostPtrManager.populateAlreadyAllocatedFragments(reqs, nullptr);
@@ -253,7 +256,7 @@ TEST(HostPtrManager, AllocationRequirementsForMiddleAllocationThatIsStoredInMana
TEST(HostPtrManager, AllocationRequirementsForAllocationWithinSizeOfStoredAllocationInManagerAskedForGraphicsAllocationReturnsProperAllocation) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
FragmentStorage allocationFragment;
auto cpuPtr = (void *)0x1000;
auto ptrSize = MemoryConstants::pageSize * 10;
@@ -264,7 +267,7 @@ TEST(HostPtrManager, AllocationRequirementsForAllocationWithinSizeOfStoredAlloca
hostPtrManager.storeFragment(allocationFragment);
auto reqs = HostPtrManager::getAllocationRequirements(cpuPtr, MemoryConstants::pageSize);
auto reqs = MockHostPtrManager::getAllocationRequirements(cpuPtr, MemoryConstants::pageSize);
auto gpuAllocationFragments = hostPtrManager.populateAlreadyAllocatedFragments(reqs, nullptr);
@@ -280,7 +283,7 @@ TEST(HostPtrManager, AllocationRequirementsForAllocationWithinSizeOfStoredAlloca
}
TEST(HostPtrManager, HostPtrAndSizeStoredToHostPtrManagerIncreasesTheContainerCount) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
FragmentStorage allocationFragment;
EXPECT_EQ(allocationFragment.fragmentCpuPointer, nullptr);
@@ -293,7 +296,7 @@ TEST(HostPtrManager, HostPtrAndSizeStoredToHostPtrManagerIncreasesTheContainerCo
}
TEST(HostPtrManager, HostPtrAndSizeStoredToHostPtrManagerTwiceReturnsOneAsFragmentCount) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
FragmentStorage allocationFragment;
@@ -304,14 +307,14 @@ TEST(HostPtrManager, HostPtrAndSizeStoredToHostPtrManagerTwiceReturnsOneAsFragme
}
TEST(HostPtrManager, EmptyHostPtrManagerAskedForFragmentReturnsNullptr) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
auto fragment = hostPtrManager.getFragment((void *)0x10121);
EXPECT_EQ(nullptr, fragment);
EXPECT_EQ(0u, hostPtrManager.getFragmentCount());
}
TEST(HostPtrManager, NonEmptyHostPtrManagerAskedForFragmentReturnsProperFragmentWithRefCountOne) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
FragmentStorage fragment;
void *cpuPtr = (void *)0x10121;
auto fragmentSize = 101u;
@@ -330,7 +333,7 @@ TEST(HostPtrManager, NonEmptyHostPtrManagerAskedForFragmentReturnsProperFragment
}
TEST(HostPtrManager, HostPtrManagerFilledTwiceWithTheSamePointerWhenAskedForFragmentReturnsItWithRefCountSetToTwo) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
FragmentStorage fragment;
void *cpuPtr = (void *)0x10121;
auto fragmentSize = 101u;
@@ -350,7 +353,7 @@ TEST(HostPtrManager, HostPtrManagerFilledTwiceWithTheSamePointerWhenAskedForFrag
}
TEST(HostPtrManager, GivenHostPtrManagerFilledWithFragmentsWhenFragmentIsBeingReleasedThenManagerMaintainsProperRefferenceCount) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
FragmentStorage fragment;
void *cpuPtr = (void *)0x1000;
auto fragmentSize = MemoryConstants::pageSize;
@@ -392,7 +395,7 @@ TEST(HostPtrManager, GivenOsHandleStorageWhenAskedToStoreTheFragmentThenFragment
storage.fragmentStorageData[1].cpuPtr = cpu2;
storage.fragmentStorageData[1].fragmentSize = size2;
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
EXPECT_EQ(0u, hostPtrManager.getFragmentCount());
@@ -410,7 +413,7 @@ TEST(HostPtrManager, GivenHostPtrFilledWith3TripleFragmentsWhenAskedForPopulatio
void *cpuPtr = (void *)0x1001;
auto fragmentSize = MemoryConstants::pageSize * 10;
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
auto reqs = hostPtrManager.getAllocationRequirements(cpuPtr, fragmentSize);
ASSERT_EQ(3u, reqs.requiredFragmentsCount);
@@ -497,7 +500,7 @@ TEST(HostPtrManager, FragmentFindWhenFragmentSizeIsZero) {
}
TEST(HostPtrManager, FragmentFindWhenFragmentSizeIsNotZero) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
auto size1 = MemoryConstants::pageSize;
@@ -544,7 +547,7 @@ TEST(HostPtrManager, FragmentFindWhenFragmentSizeIsNotZero) {
}
TEST(HostPtrManager, FragmentCheck) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
auto size1 = MemoryConstants::pageSize;
@@ -621,7 +624,7 @@ TEST(HostPtrManager, GivenHostPtrManagerFilledWithBigFragmentWhenAskedForFragmne
FragmentStorage fragment;
fragment.fragmentCpuPointer = bigPtr;
fragment.fragmentSize = bigSize;
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
hostPtrManager.storeFragment(fragment);
EXPECT_EQ(1u, hostPtrManager.getFragmentCount());
@@ -663,7 +666,7 @@ TEST(HostPtrManager, GivenHostPtrManagerFilledWithFragmentsWhenCheckedForOverlap
FragmentStorage fragment;
fragment.fragmentCpuPointer = bigPtr;
fragment.fragmentSize = bigSize;
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
hostPtrManager.storeFragment(fragment);
EXPECT_EQ(1u, hostPtrManager.getFragmentCount());
@@ -688,7 +691,7 @@ TEST(HostPtrManager, GivenHostPtrManagerFilledWithFragmentsWhenCheckedForOverlap
EXPECT_EQ(nullptr, fragment4);
}
TEST(HostPtrManager, GivenEmptyHostPtrManagerWhenAskedForOverlapingThenNoOverlappingIsReturned) {
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
auto bigPtr = (void *)0x04000;
auto bigSize = 10 * MemoryConstants::pageSize;
@@ -705,7 +708,7 @@ TEST(HostPtrManager, GivenHostPtrManagerFilledWithFragmentsWhenAskedForOverlpain
FragmentStorage fragment;
fragment.fragmentCpuPointer = bigPtr1;
fragment.fragmentSize = bigSize;
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
hostPtrManager.storeFragment(fragment);
fragment.fragmentCpuPointer = bigPtr2;
hostPtrManager.storeFragment(fragment);
@@ -743,7 +746,7 @@ TEST(HostPtrManager, GivenHostPtrManagerFilledWithFragmentsWhenAskedForOverlapin
FragmentStorage fragment;
fragment.fragmentCpuPointer = bigPtr1;
fragment.fragmentSize = bigSize1;
HostPtrManager hostPtrManager;
MockHostPtrManager hostPtrManager;
hostPtrManager.storeFragment(fragment);
fragment.fragmentCpuPointer = bigPtr2;
fragment.fragmentSize = bigSize2;
@@ -770,3 +773,38 @@ TEST(HostPtrManager, GivenHostPtrManagerFilledWithFragmentsWhenAskedForOverlapin
EXPECT_EQ(OverlapStatus::FRAGMENT_WITHIN_STORED_FRAGMENT, overlapStatus);
EXPECT_NE(nullptr, fragment3);
}
using HostPtrAllocationTest = Test<MemoryManagerWithCsrFixture>;
TEST_F(HostPtrAllocationTest, givenTwoAllocationsThatSharesOneFragmentWhenOneIsDestroyedThenFragmentRemains) {
void *cpuPtr1 = reinterpret_cast<void *>(0x100001);
void *cpuPtr2 = ptrOffset(cpuPtr1, MemoryConstants::pageSize);
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(2 * MemoryConstants::pageSize - 1, cpuPtr1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr2);
EXPECT_EQ(3u, hostPtrManager->getFragmentCount());
memoryManager->freeGraphicsMemory(graphicsAllocation1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
memoryManager->freeGraphicsMemory(graphicsAllocation2);
EXPECT_EQ(0u, hostPtrManager->getFragmentCount());
}
TEST_F(HostPtrAllocationTest, whenPrepareOsHandlesForAllocationThenPopulateAsManyFragmentsAsRequired) {
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
void *cpuPtr = reinterpret_cast<void *>(0x100001);
size_t allocationSize = MemoryConstants::pageSize / 2;
for (uint32_t expectedFragmentCount = 1; expectedFragmentCount <= 3; expectedFragmentCount++, allocationSize += MemoryConstants::pageSize) {
auto requirements = hostPtrManager->getAllocationRequirements(cpuPtr, allocationSize);
EXPECT_EQ(expectedFragmentCount, requirements.requiredFragmentsCount);
auto osStorage = hostPtrManager->prepareOsStorageForAllocation(*memoryManager, allocationSize, cpuPtr);
EXPECT_EQ(expectedFragmentCount, osStorage.fragmentCount);
EXPECT_EQ(expectedFragmentCount, hostPtrManager->getFragmentCount());
hostPtrManager->releaseHandleStorage(osStorage);
memoryManager->cleanOsHandles(osStorage);
EXPECT_EQ(0u, hostPtrManager->getFragmentCount());
}
}

View File

@@ -154,7 +154,7 @@ TEST_F(MemoryAllocatorTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToH
GraphicsAllocation gfxAllocation(cpuPtr, size);
memoryManager->addAllocationToHostPtrManager(&gfxAllocation);
auto fragment = memoryManager->hostPtrManager.getFragment(gfxAllocation.getUnderlyingBuffer());
auto fragment = memoryManager->getHostPtrManager()->getFragment(gfxAllocation.getUnderlyingBuffer());
EXPECT_NE(fragment, nullptr);
EXPECT_TRUE(fragment->driverAllocation);
EXPECT_EQ(fragment->refCount, 1);
@@ -165,22 +165,22 @@ TEST_F(MemoryAllocatorTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToH
FragmentStorage fragmentStorage = {};
fragmentStorage.fragmentCpuPointer = cpuPtr;
memoryManager->hostPtrManager.storeFragment(fragmentStorage);
fragment = memoryManager->hostPtrManager.getFragment(gfxAllocation.getUnderlyingBuffer());
memoryManager->getHostPtrManager()->storeFragment(fragmentStorage);
fragment = memoryManager->getHostPtrManager()->getFragment(gfxAllocation.getUnderlyingBuffer());
EXPECT_EQ(fragment->refCount, 2);
fragment->driverAllocation = false;
memoryManager->removeAllocationFromHostPtrManager(&gfxAllocation);
fragment = memoryManager->hostPtrManager.getFragment(gfxAllocation.getUnderlyingBuffer());
fragment = memoryManager->getHostPtrManager()->getFragment(gfxAllocation.getUnderlyingBuffer());
EXPECT_EQ(fragment->refCount, 2);
fragment->driverAllocation = true;
memoryManager->removeAllocationFromHostPtrManager(&gfxAllocation);
fragment = memoryManager->hostPtrManager.getFragment(gfxAllocation.getUnderlyingBuffer());
fragment = memoryManager->getHostPtrManager()->getFragment(gfxAllocation.getUnderlyingBuffer());
EXPECT_EQ(fragment->refCount, 1);
memoryManager->removeAllocationFromHostPtrManager(&gfxAllocation);
fragment = memoryManager->hostPtrManager.getFragment(gfxAllocation.getUnderlyingBuffer());
fragment = memoryManager->getHostPtrManager()->getFragment(gfxAllocation.getUnderlyingBuffer());
EXPECT_EQ(fragment, nullptr);
}
@@ -467,18 +467,19 @@ TEST_F(MemoryAllocatorTest, givenInternalAllocationWhenItIsPutOnReusableListWhen
TEST_F(MemoryAllocatorTest, AlignedHostPtrWithAlignedSizeWhenAskedForGraphicsAllocationReturnsNullStorageFromHostPtrManager) {
auto ptr = (void *)0x1000;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(4096, ptr);
MockMemoryManager mockMemoryManager(*executionEnvironment);
auto hostPtrManager = static_cast<MockHostPtrManager *>(mockMemoryManager.getHostPtrManager());
auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemory(4096, ptr);
EXPECT_NE(nullptr, graphicsAllocation);
auto &hostPtrManager = memoryManager->hostPtrManager;
EXPECT_EQ(1u, hostPtrManager.getFragmentCount());
auto fragmentData = hostPtrManager.getFragment(ptr);
EXPECT_EQ(1u, hostPtrManager->getFragmentCount());
auto fragmentData = hostPtrManager->getFragment(ptr);
ASSERT_NE(nullptr, fragmentData);
EXPECT_NE(nullptr, fragmentData->osInternalStorage);
memoryManager->freeGraphicsMemory(graphicsAllocation);
mockMemoryManager.freeGraphicsMemory(graphicsAllocation);
}
TEST_F(MemoryAllocatorTest, GivenAlignedHostPtrAndCacheAlignedSizeWhenAskedForL3AllowanceThenTrueIsReturned) {
@@ -533,7 +534,7 @@ TEST_F(MemoryAllocatorTest, NullOsHandleStorageAskedForPopulationReturnsFilledPo
EXPECT_NE(nullptr, storage.fragmentStorageData[0].osHandleStorage);
EXPECT_EQ(nullptr, storage.fragmentStorageData[1].osHandleStorage);
EXPECT_EQ(nullptr, storage.fragmentStorageData[2].osHandleStorage);
memoryManager->hostPtrManager.releaseHandleStorage(storage);
memoryManager->getHostPtrManager()->releaseHandleStorage(storage);
memoryManager->cleanOsHandles(storage);
}
@@ -541,20 +542,22 @@ TEST_F(MemoryAllocatorTest, GivenEmptyMemoryManagerAndMisalingedHostPtrWithHugeS
void *cpuPtr = (void *)0x1005;
auto size = MemoryConstants::pageSize * 10 - 1;
auto reqs = HostPtrManager::getAllocationRequirements(cpuPtr, size);
MockMemoryManager mockMemoryManager(*executionEnvironment);
auto hostPtrManager = static_cast<MockHostPtrManager *>(mockMemoryManager.getHostPtrManager());
auto reqs = MockHostPtrManager::getAllocationRequirements(cpuPtr, size);
ASSERT_EQ(3u, reqs.requiredFragmentsCount);
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, cpuPtr);
auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemory(size, cpuPtr);
for (int i = 0; i < maxFragmentsCount; i++) {
EXPECT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage);
EXPECT_EQ(reqs.AllocationFragments[i].allocationPtr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].cpuPtr);
EXPECT_EQ(reqs.AllocationFragments[i].allocationSize, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].fragmentSize);
}
EXPECT_EQ(3u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(3u, hostPtrManager->getFragmentCount());
EXPECT_EQ(Sharing::nonSharedResource, graphicsAllocation->peekSharedHandle());
memoryManager->freeGraphicsMemory(graphicsAllocation);
mockMemoryManager.freeGraphicsMemory(graphicsAllocation);
}
TEST_F(MemoryAllocatorTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) {
@@ -1350,11 +1353,12 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerWhenBiggerOverl
void *cpuPtr2 = (void *)0x101008;
void *cpuPtr3 = (void *)0x100000;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
EXPECT_EQ(2u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
EXPECT_EQ(4u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
GraphicsAllocation *graphicsAllocation3 = nullptr;
@@ -1386,29 +1390,30 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerReadyForCleanin
void *cpuPtr2 = (void *)0x101008;
void *cpuPtr3 = (void *)0x100000;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
EXPECT_EQ(2u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
EXPECT_EQ(4u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
EXPECT_NE(nullptr, graphicsAllocation2);
auto fragment1 = memoryManager->hostPtrManager.getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment1);
auto fragment2 = memoryManager->hostPtrManager.getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment2);
auto fragment3 = memoryManager->hostPtrManager.getFragment(alignDown(cpuPtr2, MemoryConstants::pageSize));
auto fragment3 = hostPtrManager->getFragment(alignDown(cpuPtr2, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment3);
auto fragment4 = memoryManager->hostPtrManager.getFragment(alignUp(cpuPtr2, MemoryConstants::pageSize));
auto fragment4 = hostPtrManager->getFragment(alignUp(cpuPtr2, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment4);
uint32_t taskCountReady = 1;
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(graphicsAllocation1), TEMPORARY_ALLOCATION, taskCountReady);
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(graphicsAllocation2), TEMPORARY_ALLOCATION, taskCountReady);
EXPECT_EQ(4u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
// All fragments ready for release
taskCount = taskCountReady;
@@ -1430,22 +1435,23 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithoutBiggerOver
void *cpuPtr1 = (void *)0x100004;
void *cpuPtr2 = (void *)0x101008;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
EXPECT_EQ(2u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
EXPECT_EQ(4u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
EXPECT_NE(nullptr, graphicsAllocation2);
auto fragment1 = memoryManager->hostPtrManager.getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment1);
auto fragment2 = memoryManager->hostPtrManager.getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment2);
auto fragment3 = memoryManager->hostPtrManager.getFragment(alignDown(cpuPtr2, MemoryConstants::pageSize));
auto fragment3 = hostPtrManager->getFragment(alignDown(cpuPtr2, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment3);
auto fragment4 = memoryManager->hostPtrManager.getFragment(alignUp(cpuPtr2, MemoryConstants::pageSize));
auto fragment4 = hostPtrManager->getFragment(alignUp(cpuPtr2, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment4);
AllocationRequirements requirements;
@@ -1462,7 +1468,7 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithoutBiggerOver
requirements.AllocationFragments[1].allocationSize = MemoryConstants::pageSize;
requirements.AllocationFragments[1].fragmentPosition = FragmentPosition::TRAILING;
RequirementsStatus status = memoryManager->hostPtrManager.checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
EXPECT_EQ(2u, checkedFragments.count);
@@ -1486,13 +1492,14 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlap
void *cpuPtr1 = (void *)0x100004;
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
EXPECT_EQ(2u, memoryManager->hostPtrManager.getFragmentCount());
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
auto fragment1 = memoryManager->hostPtrManager.getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment1);
auto fragment2 = memoryManager->hostPtrManager.getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment2);
uint32_t taskCountReady = 1;
@@ -1512,7 +1519,7 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlap
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
RequirementsStatus status = memoryManager->hostPtrManager.checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
EXPECT_EQ(1u, checkedFragments.count);
@@ -1529,14 +1536,15 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlap
void *cpuPtr1 = (void *)0x100004;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
EXPECT_EQ(2u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
auto fragment1 = memoryManager->hostPtrManager.getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment1);
auto fragment2 = memoryManager->hostPtrManager.getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment2);
uint32_t taskCountReady = 2;
@@ -1568,7 +1576,7 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlap
EXPECT_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Invoke(cleanAllocations)).WillOnce(::testing::Invoke(cleanAllocationsWithTaskCount));
RequirementsStatus status = memoryManager->hostPtrManager.checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
EXPECT_EQ(1u, checkedFragments.count);
@@ -1585,14 +1593,15 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlap
void *cpuPtr1 = (void *)0x100004;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
EXPECT_EQ(2u, memoryManager->hostPtrManager.getFragmentCount());
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
auto fragment1 = memoryManager->hostPtrManager.getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment1);
auto fragment2 = memoryManager->hostPtrManager.getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
EXPECT_NE(nullptr, fragment2);
uint32_t taskCountReady = 2;
@@ -1620,7 +1629,7 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlap
EXPECT_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).Times(2).WillRepeatedly(::testing::Invoke(cleanAllocations));
RequirementsStatus status = memoryManager->hostPtrManager.checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
EXPECT_EQ(RequirementsStatus::FATAL, status);
EXPECT_EQ(1u, checkedFragments.count);