mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
Cleanup host ptr manager
Change-Id: I0fc9df41a08255eef8072666c1c5c16806e0f7cf Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
e128cb7a7c
commit
129380c1a6
@@ -23,6 +23,7 @@
|
||||
#include "unit_tests/gen_common/gen_cmd_parse.h"
|
||||
#include "unit_tests/helpers/hw_parse.h"
|
||||
#include "unit_tests/mocks/mock_program.h"
|
||||
#include "unit_tests/mocks/mock_host_ptr_manager.h"
|
||||
#include "unit_tests/mocks/mock_submissions_aggregator.h"
|
||||
#include "unit_tests/os_interface/linux/device_command_stream_fixture.h"
|
||||
#include "test.h"
|
||||
@@ -1194,11 +1195,9 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentTwice) {
|
||||
TEST_F(DrmCommandStreamLeaksTest, makeResidentTwiceWhenFragmentStorage) {
|
||||
auto ptr = (void *)0x1001;
|
||||
auto size = MemoryConstants::pageSize * 10;
|
||||
auto reqs = HostPtrManager::getAllocationRequirements(ptr, size);
|
||||
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
|
||||
auto allocation = mm->allocateGraphicsMemory(size, ptr);
|
||||
auto &hostPtrManager = mm->hostPtrManager;
|
||||
|
||||
EXPECT_EQ(3u, hostPtrManager.getFragmentCount());
|
||||
ASSERT_EQ(3u, allocation->fragmentsStorage.fragmentCount);
|
||||
|
||||
csr->makeResident(*allocation);
|
||||
@@ -1238,9 +1237,6 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW
|
||||
|
||||
auto graphicsAllocation2 = mm->allocateGraphicsMemory(size2, offsetedPtr);
|
||||
|
||||
auto &hostPtrManager = mm->hostPtrManager;
|
||||
ASSERT_EQ(3u, hostPtrManager.getFragmentCount());
|
||||
|
||||
//graphicsAllocation2 reuses one fragment from graphicsAllocation
|
||||
EXPECT_EQ(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency, graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency);
|
||||
|
||||
@@ -1297,13 +1293,10 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationCreatedFromThreeFragmentsWhenMa
|
||||
auto ptr = (void *)0x1001;
|
||||
auto size = MemoryConstants::pageSize * 10;
|
||||
|
||||
auto reqs = HostPtrManager::getAllocationRequirements(ptr, size);
|
||||
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
|
||||
|
||||
auto allocation = mm->allocateGraphicsMemory(size, ptr);
|
||||
|
||||
auto &hostPtrManager = mm->hostPtrManager;
|
||||
|
||||
EXPECT_EQ(3u, hostPtrManager.getFragmentCount());
|
||||
ASSERT_EQ(3u, allocation->fragmentsStorage.fragmentCount);
|
||||
|
||||
csr->makeResident(*allocation);
|
||||
@@ -1334,13 +1327,10 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFrag
|
||||
auto size = MemoryConstants::pageSize;
|
||||
auto size2 = 100;
|
||||
|
||||
auto reqs = HostPtrManager::getAllocationRequirements(ptr, size);
|
||||
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
|
||||
|
||||
auto allocation = mm->allocateGraphicsMemory(size, ptr);
|
||||
|
||||
auto &hostPtrManager = mm->hostPtrManager;
|
||||
|
||||
EXPECT_EQ(2u, hostPtrManager.getFragmentCount());
|
||||
ASSERT_EQ(2u, allocation->fragmentsStorage.fragmentCount);
|
||||
ASSERT_EQ(2u, reqs.requiredFragmentsCount);
|
||||
|
||||
@@ -1367,12 +1357,9 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFrag
|
||||
mm->freeGraphicsMemory(allocation);
|
||||
csr->getResidencyAllocations().clear();
|
||||
|
||||
EXPECT_EQ(0u, hostPtrManager.getFragmentCount());
|
||||
|
||||
auto allocation2 = mm->allocateGraphicsMemory(size2, ptr);
|
||||
reqs = HostPtrManager::getAllocationRequirements(ptr, size2);
|
||||
reqs = MockHostPtrManager::getAllocationRequirements(ptr, size2);
|
||||
|
||||
EXPECT_EQ(1u, hostPtrManager.getFragmentCount());
|
||||
ASSERT_EQ(1u, allocation2->fragmentsStorage.fragmentCount);
|
||||
ASSERT_EQ(1u, reqs.requiredFragmentsCount);
|
||||
|
||||
@@ -1397,7 +1384,6 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFrag
|
||||
EXPECT_EQ(1u, allocation2->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->getRefCount());
|
||||
}
|
||||
mm->freeGraphicsMemory(allocation2);
|
||||
EXPECT_EQ(0u, hostPtrManager.getFragmentCount());
|
||||
}
|
||||
|
||||
TEST_F(DrmCommandStreamLeaksTest, GivenTwoAllocationsWhenBackingStorageIsTheSameThenMakeResidentShouldAddOnlyOneLocation) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "runtime/helpers/timestamp_packet.h"
|
||||
#include "runtime/mem_obj/buffer.h"
|
||||
#include "runtime/mem_obj/image.h"
|
||||
#include "runtime/memory_manager/host_ptr_manager.h"
|
||||
#include "runtime/os_interface/linux/allocator_helper.h"
|
||||
#include "runtime/os_interface/linux/drm_allocation.h"
|
||||
#include "runtime/os_interface/linux/drm_buffer_object.h"
|
||||
@@ -116,7 +117,7 @@ TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationTo
|
||||
|
||||
DrmAllocation gfxAllocation(nullptr, cpuPtr, size, MemoryPool::MemoryNull);
|
||||
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);
|
||||
@@ -129,22 +130,22 @@ TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationTo
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -658,11 +659,11 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked
|
||||
auto size = MemoryConstants::pageSize * 10;
|
||||
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, ptr);
|
||||
|
||||
auto &hostPtrManager = memoryManager->hostPtrManager;
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
|
||||
|
||||
ASSERT_EQ(3u, hostPtrManager.getFragmentCount());
|
||||
ASSERT_EQ(3u, hostPtrManager->getFragmentCount());
|
||||
|
||||
auto reqs = HostPtrManager::getAllocationRequirements(ptr, size);
|
||||
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
|
||||
|
||||
for (int i = 0; i < maxFragmentsCount; i++) {
|
||||
ASSERT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo);
|
||||
@@ -671,7 +672,7 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked
|
||||
EXPECT_FALSE(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekIsAllocated());
|
||||
}
|
||||
memoryManager->freeGraphicsMemory(graphicsAllocation);
|
||||
EXPECT_EQ(0u, hostPtrManager.getFragmentCount());
|
||||
EXPECT_EQ(0u, hostPtrManager->getFragmentCount());
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, testProfilingAllocatorCleanup) {
|
||||
@@ -2655,9 +2656,11 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
|
||||
|
||||
mock->testIoctls();
|
||||
|
||||
EXPECT_EQ(0u, testedMemoryManager->hostPtrManager.getFragmentCount());
|
||||
EXPECT_EQ(nullptr, testedMemoryManager->hostPtrManager.getFragment(handleStorage.fragmentStorageData[1].cpuPtr));
|
||||
EXPECT_EQ(nullptr, testedMemoryManager->hostPtrManager.getFragment(handleStorage.fragmentStorageData[2].cpuPtr));
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(testedMemoryManager->getHostPtrManager());
|
||||
|
||||
EXPECT_EQ(0u, hostPtrManager->getFragmentCount());
|
||||
EXPECT_EQ(nullptr, hostPtrManager->getFragment(handleStorage.fragmentStorageData[1].cpuPtr));
|
||||
EXPECT_EQ(nullptr, hostPtrManager->getFragment(handleStorage.fragmentStorageData[2].cpuPtr));
|
||||
|
||||
handleStorage.fragmentStorageData[0].freeTheFragment = false;
|
||||
handleStorage.fragmentStorageData[1].freeTheFragment = true;
|
||||
@@ -2684,8 +2687,9 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
|
||||
|
||||
mock->testIoctls();
|
||||
|
||||
EXPECT_EQ(1u, testedMemoryManager->hostPtrManager.getFragmentCount());
|
||||
EXPECT_NE(nullptr, testedMemoryManager->hostPtrManager.getFragment(handleStorage.fragmentStorageData[0].cpuPtr));
|
||||
auto hostPtrManager = static_cast<MockHostPtrManager *>(testedMemoryManager->getHostPtrManager());
|
||||
EXPECT_EQ(1u, hostPtrManager->getFragmentCount());
|
||||
EXPECT_NE(nullptr, hostPtrManager->getFragment(handleStorage.fragmentStorageData[0].cpuPtr));
|
||||
|
||||
handleStorage.fragmentStorageData[0].freeTheFragment = true;
|
||||
testedMemoryManager->cleanOsHandles(handleStorage);
|
||||
|
||||
Reference in New Issue
Block a user