Move tests to shared

Signed-off-by: Daniel Chabrowski <daniel.chabrowski@intel.com>
This commit is contained in:
Daniel Chabrowski
2022-06-09 17:53:05 +00:00
committed by Compute-Runtime-Automation
parent 1b7555a49d
commit 6e3d373ef6
49 changed files with 66 additions and 84 deletions

View File

@@ -12,8 +12,11 @@ target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter_mt_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gfx_partition_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/graphics_allocation_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/host_ptr_manager_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/internal_allocation_storage_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/local_memory_usage_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/memory_manager_allocate_in_device_pool_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/memory_manager_multi_device_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/memory_pool_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/multi_graphics_allocation_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/page_table_tests.cpp

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,321 @@
/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/memory_manager/internal_allocation_storage.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/test/common/fixtures/memory_allocator_fixture.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/libult/ult_command_stream_receiver.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/test_macros/test.h"
#include "shared/test/unit_test/utilities/containers_tests_helpers.h"
struct InternalAllocationStorageTest : public MemoryAllocatorFixture,
public ::testing::Test {
using MemoryAllocatorFixture::TearDown;
void SetUp() override {
MemoryAllocatorFixture::SetUp();
storage = csr->getInternalAllocationStorage();
}
InternalAllocationStorage *storage;
};
TEST_F(InternalAllocationStorageTest, givenDebugFlagThatDisablesAllocationReuseWhenStoreReusableAllocationIsCalledThenAllocationIsReleased) {
DebugManagerStateRestore stateRestorer;
DebugManager.flags.DisableResourceRecycling.set(true);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
EXPECT_NE(allocation, csr->getAllocationsForReuse().peekHead());
EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty());
}
TEST_F(InternalAllocationStorageTest, whenCleanAllocationListThenRemoveOnlyCompletedAllocations) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
auto allocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
allocation->updateTaskCount(10, csr->getOsContext().getContextId());
allocation2->updateTaskCount(5, csr->getOsContext().getContextId());
allocation3->updateTaskCount(15, csr->getOsContext().getContextId());
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION);
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation2), TEMPORARY_ALLOCATION);
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation3), TEMPORARY_ALLOCATION);
//head point to alloc 2, tail points to alloc3
EXPECT_TRUE(csr->getTemporaryAllocations().peekContains(*allocation));
EXPECT_TRUE(csr->getTemporaryAllocations().peekContains(*allocation2));
EXPECT_TRUE(csr->getTemporaryAllocations().peekContains(*allocation3));
EXPECT_EQ(-1, verifyDListOrder(csr->getTemporaryAllocations().peekHead(), allocation, allocation2, allocation3));
//now remove element form the middle
storage->cleanAllocationList(6, TEMPORARY_ALLOCATION);
EXPECT_TRUE(csr->getTemporaryAllocations().peekContains(*allocation));
EXPECT_FALSE(csr->getTemporaryAllocations().peekContains(*allocation2));
EXPECT_TRUE(csr->getTemporaryAllocations().peekContains(*allocation3));
EXPECT_EQ(-1, verifyDListOrder(csr->getTemporaryAllocations().peekHead(), allocation, allocation3));
//now remove head
storage->cleanAllocationList(11, TEMPORARY_ALLOCATION);
EXPECT_FALSE(csr->getTemporaryAllocations().peekContains(*allocation));
EXPECT_FALSE(csr->getTemporaryAllocations().peekContains(*allocation2));
EXPECT_TRUE(csr->getTemporaryAllocations().peekContains(*allocation3));
//now remove tail
storage->cleanAllocationList(16, TEMPORARY_ALLOCATION);
EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty());
}
TEST_F(InternalAllocationStorageTest, whenAllocationIsStoredAsReusableButIsStillUsedThenCannotBeObtained) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, MemoryConstants::pageSize, AllocationType::BUFFER, mockDeviceBitfield});
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION, 2u);
auto *hwTag = csr->getTagAddress();
*hwTag = 1u;
auto newAllocation = storage->obtainReusableAllocation(1, AllocationType::BUFFER);
EXPECT_EQ(nullptr, newAllocation);
storage->cleanAllocationList(2u, REUSABLE_ALLOCATION);
}
TEST_F(InternalAllocationStorageTest, whenAllocationIsStoredAsTemporaryAndIsStillUsedThenCanBeObtained) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, MemoryConstants::pageSize, AllocationType::BUFFER, mockDeviceBitfield});
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION, 2u);
auto *hwTag = csr->getTagAddress();
*hwTag = 1u;
auto newAllocation = storage->obtainTemporaryAllocationWithPtr(1, allocation->getUnderlyingBuffer(), AllocationType::BUFFER);
EXPECT_EQ(allocation, newAllocation.get());
EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty());
memoryManager->freeGraphicsMemory(newAllocation.release());
}
TEST_F(InternalAllocationStorageTest, givenTemporaryAllocationWhenAllocationIsObtainedThenItsTaskCountIsSetToNotReady) {
const uint32_t initialTaskCount = 37u;
const uint32_t contextId = csr->getOsContext().getContextId();
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, MemoryConstants::pageSize, AllocationType::BUFFER, mockDeviceBitfield});
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION, initialTaskCount);
ASSERT_EQ(initialTaskCount, allocation->getTaskCount(contextId));
auto newAllocation = storage->obtainTemporaryAllocationWithPtr(1, allocation->getUnderlyingBuffer(), AllocationType::BUFFER);
EXPECT_EQ(allocation, newAllocation.get());
EXPECT_EQ(CompletionStamp::notReady, allocation->getTaskCount(contextId));
memoryManager->freeGraphicsMemory(newAllocation.release());
}
TEST_F(InternalAllocationStorageTest, whenObtainAllocationFromEmptyReuseListThenReturnNullptr) {
auto allocation2 = storage->obtainReusableAllocation(1, AllocationType::BUFFER);
EXPECT_EQ(nullptr, allocation2);
}
TEST_F(InternalAllocationStorageTest, whenCompletedAllocationIsStoredAsReusableAndThenCanBeObtained) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, MemoryConstants::pageSize, AllocationType::BUFFER, mockDeviceBitfield});
EXPECT_NE(nullptr, allocation);
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION, 2u);
EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty());
auto *hwTag = csr->getTagAddress();
*hwTag = 2u;
auto reusedAllocation = storage->obtainReusableAllocation(1, AllocationType::BUFFER).release();
EXPECT_EQ(allocation, reusedAllocation);
EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty());
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(InternalAllocationStorageTest, whenNotUsedAllocationIsStoredAsReusableAndThenCanBeObtained) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, MemoryConstants::pageSize, AllocationType::BUFFER, mockDeviceBitfield});
EXPECT_NE(nullptr, allocation);
EXPECT_FALSE(allocation->isUsed());
EXPECT_EQ(0u, csr->peekTaskCount());
*csr->getTagAddress() = 0; // initial hw tag for dll
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
EXPECT_EQ(0u, allocation->getTaskCount(csr->getOsContext().getContextId()));
EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty());
auto reusedAllocation = storage->obtainReusableAllocation(1, AllocationType::BUFFER).release();
EXPECT_EQ(allocation, reusedAllocation);
EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty());
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(InternalAllocationStorageTest, whenObtainAllocationFromMidlleOfReusableListThenItIsDetachedFromLinkedList) {
auto &reusableAllocations = csr->getAllocationsForReuse();
EXPECT_TRUE(reusableAllocations.peekIsEmpty());
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, 1, AllocationType::BUFFER, mockDeviceBitfield});
auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, 10000, AllocationType::BUFFER, mockDeviceBitfield});
auto allocation3 = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, 1, AllocationType::BUFFER, mockDeviceBitfield});
EXPECT_TRUE(reusableAllocations.peekIsEmpty());
EXPECT_EQ(nullptr, allocation2->next);
EXPECT_EQ(nullptr, allocation2->prev);
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
EXPECT_TRUE(reusableAllocations.peekContains(*allocation));
EXPECT_FALSE(reusableAllocations.peekContains(*allocation2));
EXPECT_FALSE(reusableAllocations.peekContains(*allocation3));
EXPECT_EQ(nullptr, allocation2->next);
EXPECT_EQ(nullptr, allocation2->prev);
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation2), REUSABLE_ALLOCATION);
EXPECT_TRUE(reusableAllocations.peekContains(*allocation));
EXPECT_TRUE(reusableAllocations.peekContains(*allocation2));
EXPECT_FALSE(reusableAllocations.peekContains(*allocation3));
EXPECT_EQ(nullptr, allocation2->next);
EXPECT_EQ(allocation, allocation2->prev);
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation3), REUSABLE_ALLOCATION);
EXPECT_TRUE(reusableAllocations.peekContains(*allocation));
EXPECT_TRUE(reusableAllocations.peekContains(*allocation2));
EXPECT_TRUE(reusableAllocations.peekContains(*allocation3));
EXPECT_EQ(allocation3, allocation2->next);
EXPECT_EQ(allocation, allocation2->prev);
auto reusableAllocation = storage->obtainReusableAllocation(10000, AllocationType::BUFFER).release();
EXPECT_EQ(reusableAllocation, allocation2);
EXPECT_EQ(nullptr, allocation2->next);
EXPECT_EQ(nullptr, allocation2->prev);
EXPECT_EQ(nullptr, reusableAllocation->next);
EXPECT_EQ(nullptr, reusableAllocation->prev);
EXPECT_FALSE(reusableAllocations.peekContains(*reusableAllocation));
EXPECT_TRUE(reusableAllocations.peekContains(*allocation));
EXPECT_FALSE(reusableAllocations.peekContains(*allocation2));
EXPECT_TRUE(reusableAllocations.peekContains(*allocation3));
memoryManager->freeGraphicsMemory(allocation2);
allocation->updateTaskCount(0u, csr->getOsContext().getContextId());
allocation3->updateTaskCount(0u, csr->getOsContext().getContextId());
}
TEST_F(InternalAllocationStorageTest, givenAllocationWhenItIsPutOnReusableListWhenOtherAllocationTypeIsRequestedThenNullIsReturned) {
EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty());
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(AllocationProperties{0, MemoryConstants::pageSize, AllocationType::BUFFER, mockDeviceBitfield});
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty());
auto internalAllocation = storage->obtainReusableAllocation(1, AllocationType::INTERNAL_HEAP);
EXPECT_EQ(nullptr, internalAllocation);
}
class WaitAtDeletionAllocation : public MockGraphicsAllocation {
public:
WaitAtDeletionAllocation(void *buffer, size_t sizeIn)
: MockGraphicsAllocation(buffer, sizeIn) {
inDestructor = false;
}
std::mutex mutex;
std::atomic<bool> inDestructor;
~WaitAtDeletionAllocation() override {
inDestructor = true;
std::lock_guard<std::mutex> lock(mutex);
}
};
TEST_F(InternalAllocationStorageTest, givenAllocationListWhenTwoThreadsCleanConcurrentlyThenBothThreadsCanAccessTheList) {
auto allocation1 = new WaitAtDeletionAllocation(nullptr, 0);
allocation1->updateTaskCount(1, csr->getOsContext().getContextId());
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation1), TEMPORARY_ALLOCATION);
std::unique_lock<std::mutex> allocationDeletionLock(allocation1->mutex);
auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
allocation2->updateTaskCount(2, csr->getOsContext().getContextId());
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation2), TEMPORARY_ALLOCATION);
std::mutex mutex;
std::unique_lock<std::mutex> lock(mutex);
std::thread thread1([&] {
storage->cleanAllocationList(1, TEMPORARY_ALLOCATION);
});
std::thread thread2([&] {
std::lock_guard<std::mutex> lock(mutex);
storage->cleanAllocationList(2, TEMPORARY_ALLOCATION);
});
while (!allocation1->inDestructor)
;
lock.unlock();
allocationDeletionLock.unlock();
thread1.join();
thread2.join();
EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty());
}
HWTEST_F(InternalAllocationStorageTest, givenMultipleActivePartitionsWhenDetachingReusableAllocationThenCheckTaskCountFinishedOnAllTiles) {
auto ultCsr = reinterpret_cast<UltCommandStreamReceiver<FamilyType> *>(csr);
csr->setActivePartitions(2u);
ultCsr->postSyncWriteOffset = 32;
auto tagAddress = csr->getTagAddress();
*tagAddress = 0xFF;
tagAddress = ptrOffset(tagAddress, 32);
*tagAddress = 0x0;
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
EXPECT_EQ(allocation, csr->getAllocationsForReuse().peekHead());
EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty());
allocation->updateTaskCount(1u, csr->getOsContext().getContextId());
std::unique_ptr<GraphicsAllocation> allocationReusable = csr->getAllocationsForReuse().detachAllocation(0, nullptr, csr, AllocationType::INTERNAL_HOST_MEMORY);
EXPECT_EQ(nullptr, allocationReusable.get());
*tagAddress = 0x1;
allocationReusable = csr->getAllocationsForReuse().detachAllocation(0, nullptr, csr, AllocationType::INTERNAL_HOST_MEMORY);
EXPECT_EQ(allocation, allocationReusable.get());
memoryManager->freeGraphicsMemory(allocationReusable.release());
}
TEST_F(InternalAllocationStorageTest, givenInternalAllocationWhenTaskCountMetsExpectationAndItHasBeenAssignedThenAllocIsRemoved) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
uint32_t expectedTaskCount = 10u;
*csr->getTagAddress() = expectedTaskCount;
allocation->updateTaskCount(expectedTaskCount, csr->getOsContext().getContextId());
allocation->hostPtrTaskCountAssignment = 0;
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION);
storage->cleanAllocationList(expectedTaskCount, TEMPORARY_ALLOCATION);
EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty());
}
TEST_F(InternalAllocationStorageTest, givenInternalAllocationWhenTaskCountMetsExpectationAndItHasNotBeenAssignedThenAllocIsNotRemoved) {
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{csr->getRootDeviceIndex(), MemoryConstants::pageSize});
uint32_t expectedTaskCount = 10u;
*csr->getTagAddress() = expectedTaskCount;
allocation->updateTaskCount(expectedTaskCount, csr->getOsContext().getContextId());
allocation->hostPtrTaskCountAssignment = 1;
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION);
storage->cleanAllocationList(expectedTaskCount, TEMPORARY_ALLOCATION);
EXPECT_FALSE(csr->getTemporaryAllocations().peekIsEmpty());
allocation->hostPtrTaskCountAssignment = 0;
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/constants.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "shared/test/common/fixtures/memory_allocator_multi_device_fixture.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/test_macros/test.h"
using namespace NEO;
using MemoryManagerMultiDeviceTest = MemoryAllocatorMultiDeviceFixture<10>;
TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGraphicsMemoryIsCalledThenGraphicsAllocationHasTheSameRootDeviceIndex) {
std::vector<AllocationType> allocationTypes{AllocationType::BUFFER,
AllocationType::KERNEL_ISA};
for (auto allocationType : allocationTypes) {
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < getNumRootDevices(); ++rootDeviceIndex) {
AllocationProperties properties{rootDeviceIndex, true, MemoryConstants::pageSize, allocationType, false, false, mockDeviceBitfield};
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
ASSERT_NE(gfxAllocation, nullptr);
EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex());
memoryManager->freeGraphicsMemory(gfxAllocation);
gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, (void *)0x1234);
ASSERT_NE(gfxAllocation, nullptr);
EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex());
memoryManager->freeGraphicsMemory(gfxAllocation);
gfxAllocation = memoryManager->allocateGraphicsMemoryInPreferredPool(properties, nullptr);
ASSERT_NE(gfxAllocation, nullptr);
EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex());
memoryManager->freeGraphicsMemory(gfxAllocation);
gfxAllocation = memoryManager->allocateGraphicsMemoryInPreferredPool(properties, (void *)0x1234);
ASSERT_NE(gfxAllocation, nullptr);
EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex());
memoryManager->freeGraphicsMemory(gfxAllocation);
gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast<osHandle>(0u), properties, false, false);
ASSERT_NE(gfxAllocation, nullptr);
EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex());
memoryManager->freeGraphicsMemory(gfxAllocation);
gfxAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(static_cast<osHandle>(0u), properties, true, false);
ASSERT_NE(gfxAllocation, nullptr);
EXPECT_EQ(rootDeviceIndex, gfxAllocation->getRootDeviceIndex());
memoryManager->freeGraphicsMemory(gfxAllocation);
}
}
}
INSTANTIATE_TEST_CASE_P(MemoryManagerType, MemoryManagerMultiDeviceTest, ::testing::Bool());
TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGraphicsMemoryIsCalledThenGraphicsAllocationHasProperGpuAddress) {
RootDeviceIndicesContainer rootDeviceIndices;
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < getNumRootDevices(); ++rootDeviceIndex) {
rootDeviceIndices.push_back(rootDeviceIndex);
}
rootDeviceIndices.remove_duplicates();
auto maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
auto tagsMultiAllocation = new MultiGraphicsAllocation(maxRootDeviceIndex);
AllocationProperties unifiedMemoryProperties{rootDeviceIndices.at(0), MemoryConstants::pageSize, AllocationType::TAG_BUFFER, systemMemoryBitfield};
memoryManager->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, unifiedMemoryProperties, *tagsMultiAllocation);
EXPECT_NE(nullptr, tagsMultiAllocation);
auto graphicsAllocation0 = tagsMultiAllocation->getGraphicsAllocation(0);
for (auto graphicsAllocation : tagsMultiAllocation->getGraphicsAllocations()) {
EXPECT_EQ(graphicsAllocation->getUnderlyingBuffer(), graphicsAllocation0->getUnderlyingBuffer());
}
for (auto graphicsAllocation : tagsMultiAllocation->getGraphicsAllocations()) {
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
delete tagsMultiAllocation;
}
TEST_P(MemoryManagerMultiDeviceTest, givenRootDeviceIndexSpecifiedWhenAllocateGraphicsMemoryIsCalledThenAllocationPropertiesUsmFlagIsSetAccordingToAddressRange) {
RootDeviceIndicesContainer rootDeviceIndices;
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < getNumRootDevices(); ++rootDeviceIndex) {
rootDeviceIndices.push_back(rootDeviceIndex);
}
rootDeviceIndices.remove_duplicates();
auto maxRootDeviceIndex = *std::max_element(rootDeviceIndices.begin(), rootDeviceIndices.end(), std::less<uint32_t const>());
auto tagsMultiAllocation = new MultiGraphicsAllocation(maxRootDeviceIndex);
AllocationProperties unifiedMemoryProperties{rootDeviceIndices.at(0), MemoryConstants::pageSize, AllocationType::TAG_BUFFER, systemMemoryBitfield};
memoryManager->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, unifiedMemoryProperties, *tagsMultiAllocation);
EXPECT_NE(nullptr, tagsMultiAllocation);
for (auto rootDeviceIndex : rootDeviceIndices) {
if (memoryManager->isLimitedRange(rootDeviceIndex)) {
EXPECT_EQ(unifiedMemoryProperties.flags.isUSMHostAllocation, false);
} else {
EXPECT_EQ(unifiedMemoryProperties.flags.isUSMHostAllocation, true);
}
}
for (auto graphicsAllocation : tagsMultiAllocation->getGraphicsAllocations()) {
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
delete tagsMultiAllocation;
}