mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-04 07:14:10 +08:00
Remove cleaning allocation lists methods from memory manager
Change-Id: I4a58a5373e7dc4cf8dc5d90390e84c4f23689139 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
7b1d19eaec
commit
a30c70d84b
@@ -11,6 +11,9 @@
|
||||
#include "unit_tests/fixtures/memory_manager_fixture.h"
|
||||
#include "unit_tests/gen_common/test.h"
|
||||
#include "unit_tests/mocks/mock_host_ptr_manager.h"
|
||||
#include "unit_tests/mocks/mock_internal_allocation_storage.h"
|
||||
#include "unit_tests/mocks/mock_memory_manager.h"
|
||||
#include "unit_tests/mocks/mock_csr.h"
|
||||
|
||||
using namespace OCLRT;
|
||||
|
||||
@@ -807,4 +810,201 @@ TEST_F(HostPtrAllocationTest, whenPrepareOsHandlesForAllocationThenPopulateAsMan
|
||||
memoryManager->cleanOsHandles(osStorage);
|
||||
EXPECT_EQ(0u, hostPtrManager->getFragmentCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(HostPtrAllocationTest, whenOverlappedFragmentIsBiggerThenStoredAndStoredFragmentIsDestroyedDuringSecondCleaningThenCheckForOverlappingReturnsSuccess) {
|
||||
|
||||
void *cpuPtr1 = (void *)0x100004;
|
||||
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
|
||||
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
|
||||
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
|
||||
uint32_t taskCountReady = 2;
|
||||
auto storage = new MockInternalAllocationStorage(*csr);
|
||||
csr->internalAllocationStorage.reset(storage);
|
||||
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(graphicsAllocation1), TEMPORARY_ALLOCATION, taskCountReady);
|
||||
storage->updateCompletionAfterCleaningList(taskCountReady);
|
||||
|
||||
// All fragments ready for release
|
||||
currentGpuTag = 1;
|
||||
csr->latestSentTaskCount = taskCountReady - 1;
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 1;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 10;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
|
||||
EXPECT_EQ(1u, checkedFragments.count);
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_OVERLAPING_WITH_ANY_OTHER, checkedFragments.status[0]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[0]);
|
||||
|
||||
for (uint32_t i = 1; i < maxFragmentsCount; i++) {
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_CHECKED, checkedFragments.status[i]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(HostPtrAllocationTest, whenOverlappedFragmentIsBiggerThenStoredAndStoredFragmentCannotBeDestroyedThenCheckForOverlappingReturnsError) {
|
||||
|
||||
void *cpuPtr1 = (void *)0x100004;
|
||||
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
|
||||
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
|
||||
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
|
||||
uint32_t taskCountReady = 2;
|
||||
auto storage = csr->getInternalAllocationStorage();
|
||||
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(graphicsAllocation1), TEMPORARY_ALLOCATION, taskCountReady);
|
||||
|
||||
// All fragments ready for release
|
||||
currentGpuTag = taskCountReady - 1;
|
||||
csr->latestSentTaskCount = taskCountReady - 1;
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 1;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 10;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::FATAL, status);
|
||||
EXPECT_EQ(1u, checkedFragments.count);
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT, checkedFragments.status[0]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[0]);
|
||||
|
||||
for (uint32_t i = 1; i < maxFragmentsCount; i++) {
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_CHECKED, checkedFragments.status[i]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(HostPtrAllocationTest, checkAllocationsForOverlappingWithoutBiggerOverlap) {
|
||||
|
||||
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, hostPtrManager->getFragmentCount());
|
||||
|
||||
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
|
||||
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
EXPECT_NE(nullptr, graphicsAllocation2);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
auto fragment3 = hostPtrManager->getFragment(alignDown(cpuPtr2, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment3);
|
||||
auto fragment4 = hostPtrManager->getFragment(alignUp(cpuPtr2, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment4);
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 2;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 2;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::LEADING;
|
||||
|
||||
requirements.AllocationFragments[1].allocationPtr = alignUp(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[1].allocationSize = MemoryConstants::pageSize;
|
||||
requirements.AllocationFragments[1].fragmentPosition = FragmentPosition::TRAILING;
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
|
||||
EXPECT_EQ(2u, checkedFragments.count);
|
||||
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_WITH_EXACT_SIZE_AS_STORED_FRAGMENT, checkedFragments.status[0]);
|
||||
EXPECT_EQ(alignDown(cpuPtr1, MemoryConstants::pageSize), checkedFragments.fragments[0]->fragmentCpuPointer);
|
||||
EXPECT_EQ(MemoryConstants::pageSize, checkedFragments.fragments[0]->fragmentSize);
|
||||
EXPECT_EQ(1, checkedFragments.fragments[0]->refCount);
|
||||
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_WITH_EXACT_SIZE_AS_STORED_FRAGMENT, checkedFragments.status[1]);
|
||||
EXPECT_EQ(alignUp(cpuPtr1, MemoryConstants::pageSize), checkedFragments.fragments[1]->fragmentCpuPointer);
|
||||
EXPECT_EQ(MemoryConstants::pageSize, checkedFragments.fragments[1]->fragmentSize);
|
||||
EXPECT_EQ(2, checkedFragments.fragments[1]->refCount);
|
||||
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation1);
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation2);
|
||||
}
|
||||
|
||||
TEST_F(HostPtrAllocationTest, checkAllocationsForOverlappingWithBiggerOverlapUntilFirstClean) {
|
||||
|
||||
void *cpuPtr1 = (void *)0x100004;
|
||||
|
||||
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
|
||||
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
|
||||
uint32_t taskCountReady = 1;
|
||||
auto storage = csr->getInternalAllocationStorage();
|
||||
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(graphicsAllocation1), TEMPORARY_ALLOCATION, taskCountReady);
|
||||
|
||||
// All fragments ready for release
|
||||
taskCount = taskCountReady;
|
||||
csr->latestSentTaskCount = taskCountReady;
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 1;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 10;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
|
||||
EXPECT_EQ(1u, checkedFragments.count);
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_OVERLAPING_WITH_ANY_OTHER, checkedFragments.status[0]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[0]);
|
||||
|
||||
for (uint32_t i = 1; i < maxFragmentsCount; i++) {
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_CHECKED, checkedFragments.status[i]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "unit_tests/helpers/memory_management.h"
|
||||
#include "unit_tests/helpers/variable_backup.h"
|
||||
#include "unit_tests/mocks/mock_context.h"
|
||||
#include "unit_tests/mocks/mock_csr.h"
|
||||
#include "unit_tests/mocks/mock_deferrable_deletion.h"
|
||||
#include "unit_tests/mocks/mock_deferred_deleter.h"
|
||||
#include "unit_tests/mocks/mock_device.h"
|
||||
@@ -228,31 +229,6 @@ TEST_F(MemoryAllocatorTest, allocateGraphicsMoreThanPageAligned) {
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenCleanTempoaryAllocationsThenUseFirstCommandStreamReceiver) {
|
||||
void *host_ptr = (void *)0x1234;
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
|
||||
allocation->taskCount = 1;
|
||||
auto csr = memoryManager->getCommandStreamReceiver(0);
|
||||
EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty());
|
||||
|
||||
csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION);
|
||||
EXPECT_FALSE(csr->getTemporaryAllocations().peekIsEmpty());
|
||||
memoryManager->cleanAllocationList(1, TEMPORARY_ALLOCATION);
|
||||
EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenCleanReusableAllocationsThenUseFirstCommandStreamReceiver) {
|
||||
void *host_ptr = (void *)0x1234;
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
|
||||
allocation->taskCount = 1;
|
||||
auto csr = memoryManager->getCommandStreamReceiver(0);
|
||||
EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty());
|
||||
csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
|
||||
EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty());
|
||||
memoryManager->cleanAllocationList(1, REUSABLE_ALLOCATION);
|
||||
EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty());
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, AlignedHostPtrWithAlignedSizeWhenAskedForGraphicsAllocationReturnsNullStorageFromHostPtrManager) {
|
||||
auto ptr = (void *)0x1000;
|
||||
MockMemoryManager mockMemoryManager(*executionEnvironment);
|
||||
@@ -1219,220 +1195,6 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerReadyForCleanin
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation3);
|
||||
}
|
||||
|
||||
TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithoutBiggerOverlap) {
|
||||
|
||||
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, hostPtrManager->getFragmentCount());
|
||||
|
||||
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
|
||||
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
EXPECT_NE(nullptr, graphicsAllocation2);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
auto fragment3 = hostPtrManager->getFragment(alignDown(cpuPtr2, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment3);
|
||||
auto fragment4 = hostPtrManager->getFragment(alignUp(cpuPtr2, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment4);
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 2;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 2;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::LEADING;
|
||||
|
||||
requirements.AllocationFragments[1].allocationPtr = alignUp(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[1].allocationSize = MemoryConstants::pageSize;
|
||||
requirements.AllocationFragments[1].fragmentPosition = FragmentPosition::TRAILING;
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
|
||||
EXPECT_EQ(2u, checkedFragments.count);
|
||||
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_WITH_EXACT_SIZE_AS_STORED_FRAGMENT, checkedFragments.status[0]);
|
||||
EXPECT_EQ(alignDown(cpuPtr1, MemoryConstants::pageSize), checkedFragments.fragments[0]->fragmentCpuPointer);
|
||||
EXPECT_EQ(MemoryConstants::pageSize, checkedFragments.fragments[0]->fragmentSize);
|
||||
EXPECT_EQ(1, checkedFragments.fragments[0]->refCount);
|
||||
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_WITH_EXACT_SIZE_AS_STORED_FRAGMENT, checkedFragments.status[1]);
|
||||
EXPECT_EQ(alignUp(cpuPtr1, MemoryConstants::pageSize), checkedFragments.fragments[1]->fragmentCpuPointer);
|
||||
EXPECT_EQ(MemoryConstants::pageSize, checkedFragments.fragments[1]->fragmentSize);
|
||||
EXPECT_EQ(2, checkedFragments.fragments[1]->refCount);
|
||||
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation1);
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation2);
|
||||
}
|
||||
|
||||
TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlapUntilFirstClean) {
|
||||
|
||||
void *cpuPtr1 = (void *)0x100004;
|
||||
|
||||
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
|
||||
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
|
||||
uint32_t taskCountReady = 1;
|
||||
auto storage = csr->getInternalAllocationStorage();
|
||||
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(graphicsAllocation1), TEMPORARY_ALLOCATION, taskCountReady);
|
||||
|
||||
// All fragments ready for release
|
||||
taskCount = taskCountReady;
|
||||
csr->latestSentTaskCount = taskCountReady;
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 1;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 10;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
|
||||
EXPECT_EQ(1u, checkedFragments.count);
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_OVERLAPING_WITH_ANY_OTHER, checkedFragments.status[0]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[0]);
|
||||
|
||||
for (uint32_t i = 1; i < maxFragmentsCount; i++) {
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_CHECKED, checkedFragments.status[i]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlapUntilWaitForCompletionAndSecondClean) {
|
||||
|
||||
void *cpuPtr1 = (void *)0x100004;
|
||||
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
|
||||
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
|
||||
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
|
||||
uint32_t taskCountReady = 2;
|
||||
auto storage = csr->getInternalAllocationStorage();
|
||||
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(graphicsAllocation1), TEMPORARY_ALLOCATION, taskCountReady);
|
||||
|
||||
// All fragments ready for release
|
||||
currentGpuTag = 1;
|
||||
csr->latestSentTaskCount = taskCountReady - 1;
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 1;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 10;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
|
||||
|
||||
GMockMemoryManager *memMngr = gmockMemoryManager;
|
||||
|
||||
auto cleanAllocations = [memMngr](uint32_t waitTaskCount, uint32_t allocationUsage) -> bool {
|
||||
return memMngr->MemoryManagerCleanAllocationList(waitTaskCount, allocationUsage);
|
||||
};
|
||||
|
||||
auto cleanAllocationsWithTaskCount = [taskCountReady, memMngr](uint32_t waitTaskCount, uint32_t allocationUsage) -> bool {
|
||||
return memMngr->MemoryManagerCleanAllocationList(taskCountReady, allocationUsage);
|
||||
};
|
||||
|
||||
EXPECT_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Invoke(cleanAllocations)).WillOnce(::testing::Invoke(cleanAllocationsWithTaskCount));
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::SUCCESS, status);
|
||||
EXPECT_EQ(1u, checkedFragments.count);
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_OVERLAPING_WITH_ANY_OTHER, checkedFragments.status[0]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[0]);
|
||||
|
||||
for (uint32_t i = 1; i < maxFragmentsCount; i++) {
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_CHECKED, checkedFragments.status[i]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlapForever) {
|
||||
|
||||
void *cpuPtr1 = (void *)0x100004;
|
||||
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
|
||||
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
|
||||
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
|
||||
|
||||
EXPECT_NE(nullptr, graphicsAllocation1);
|
||||
|
||||
auto fragment1 = hostPtrManager->getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment1);
|
||||
auto fragment2 = hostPtrManager->getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
|
||||
EXPECT_NE(nullptr, fragment2);
|
||||
|
||||
uint32_t taskCountReady = 2;
|
||||
auto storage = csr->getInternalAllocationStorage();
|
||||
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(graphicsAllocation1), TEMPORARY_ALLOCATION, taskCountReady);
|
||||
|
||||
// All fragments ready for release
|
||||
currentGpuTag = taskCountReady - 1;
|
||||
csr->latestSentTaskCount = taskCountReady - 1;
|
||||
|
||||
AllocationRequirements requirements;
|
||||
CheckedFragments checkedFragments;
|
||||
|
||||
requirements.requiredFragmentsCount = 1;
|
||||
requirements.totalRequiredSize = MemoryConstants::pageSize * 10;
|
||||
|
||||
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
|
||||
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
|
||||
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
|
||||
|
||||
GMockMemoryManager *memMngr = gmockMemoryManager;
|
||||
|
||||
auto cleanAllocations = [memMngr](uint32_t waitTaskCount, uint32_t allocationUsage) -> bool {
|
||||
return memMngr->MemoryManagerCleanAllocationList(waitTaskCount, allocationUsage);
|
||||
};
|
||||
|
||||
EXPECT_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).Times(2).WillRepeatedly(::testing::Invoke(cleanAllocations));
|
||||
|
||||
RequirementsStatus status = hostPtrManager->checkAllocationsForOverlapping(*memoryManager, &requirements, &checkedFragments);
|
||||
|
||||
EXPECT_EQ(RequirementsStatus::FATAL, status);
|
||||
EXPECT_EQ(1u, checkedFragments.count);
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT, checkedFragments.status[0]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[0]);
|
||||
|
||||
for (uint32_t i = 1; i < maxFragmentsCount; i++) {
|
||||
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_CHECKED, checkedFragments.status[i]);
|
||||
EXPECT_EQ(nullptr, checkedFragments.fragments[i]);
|
||||
}
|
||||
}
|
||||
TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasNotUsedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsDestroyedInPlace) {
|
||||
auto notUsedAllocation = memoryManager->allocateGraphicsMemory(4096);
|
||||
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(notUsedAllocation);
|
||||
|
||||
Reference in New Issue
Block a user