Simplify Memory Manager API [4/4]

- fill AllocationData in one place
- remove allocateGraphicsMemoryForSVM function
- refactor SVM manager tests

Change-Id: I6f4ecd70503da8031cced50ea98a54162fd8e5d3
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-12-17 11:49:17 +01:00
committed by sys_ocldev
parent b99cf6c3ff
commit c9e667d601
26 changed files with 249 additions and 354 deletions

View File

@@ -14,6 +14,7 @@
#include "runtime/memory_manager/internal_allocation_storage.h"
#include "runtime/memory_manager/memory_banks.h"
#include "unit_tests/command_stream/command_stream_fixture.h"
#include "unit_tests/mocks/mock_allocation_properties.h"
#include "unit_tests/tests_configuration.h"
#include <cstdint>
@@ -64,7 +65,7 @@ class AUBCommandStreamFixture : public CommandStreamFixture {
}
GraphicsAllocation *createResidentAllocationAndStoreItInCsr(const void *address, size_t size) {
GraphicsAllocation *graphicsAllocation = pCommandStreamReceiver->getMemoryManager()->allocateGraphicsMemory(size, address);
GraphicsAllocation *graphicsAllocation = pCommandStreamReceiver->getMemoryManager()->allocateGraphicsMemory(MockAllocationProperties{false, size}, address);
pCommandStreamReceiver->makeResidentHostPtrAllocation(graphicsAllocation);
pCommandStreamReceiver->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(graphicsAllocation), TEMPORARY_ALLOCATION);
return graphicsAllocation;

View File

@@ -13,7 +13,7 @@
namespace OCLRT {
GraphicsAllocation *AUBFixture::createHostPtrAllocationFromSvmPtr(void *svmPtr, size_t size) {
GraphicsAllocation *allocation = csr->getMemoryManager()->allocateGraphicsMemory(size, svmPtr);
GraphicsAllocation *allocation = csr->getMemoryManager()->allocateGraphicsMemory(MockAllocationProperties{false, size}, svmPtr);
csr->makeResidentHostPtrAllocation(allocation);
csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION);
allocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);

View File

@@ -143,7 +143,7 @@ HWTEST_F(CommandStreamReceiverTest, givenPtrAndSizeThatMeetL3CriteriaWhenMakeRes
auto size = 0x2000u;
auto memoryManager = commandStreamReceiver->getMemoryManager();
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(size, hostPtr);
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, hostPtr);
ASSERT_NE(nullptr, graphicsAllocation);
commandStreamReceiver->makeResidentHostPtrAllocation(graphicsAllocation);
@@ -158,7 +158,7 @@ HWTEST_F(CommandStreamReceiverTest, givenPtrAndSizeThatDoNotMeetL3CriteriaWhenMa
auto size = 0x2001u;
auto memoryManager = commandStreamReceiver->getMemoryManager();
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(size, hostPtr);
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, hostPtr);
ASSERT_NE(nullptr, graphicsAllocation);
commandStreamReceiver->makeResidentHostPtrAllocation(graphicsAllocation);
@@ -176,8 +176,7 @@ TEST_F(CommandStreamReceiverTest, memoryManagerHasAccessToCSR) {
HWTEST_F(CommandStreamReceiverTest, whenStoreAllocationThenStoredAllocationHasTaskCountFromCsr) {
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
auto *memoryManager = csr.getMemoryManager();
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
EXPECT_FALSE(allocation->isUsed());

View File

@@ -74,7 +74,7 @@ TEST_F(TbxCommandStreamTests, DISABLED_makeResident) {
uint8_t buffer[0x10000];
size_t size = sizeof(buffer);
GraphicsAllocation *graphicsAllocation = mmTbx->allocateGraphicsMemory(size, buffer);
GraphicsAllocation *graphicsAllocation = mmTbx->allocateGraphicsMemory(MockAllocationProperties{false, size}, buffer);
pCommandStreamReceiver->makeResident(*graphicsAllocation);
pCommandStreamReceiver->makeNonResident(*graphicsAllocation);
mmTbx->freeGraphicsMemory(graphicsAllocation);
@@ -310,7 +310,7 @@ HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenWaitBeforeMakeNonResidentWhen
uint32_t tag = 0;
MockTbxCsr<FamilyType> tbxCsr(*platformDevices[0], *pDevice->executionEnvironment);
tbxCsr.setTagAllocation(pDevice->getMemoryManager()->allocateGraphicsMemory(sizeof(tag), &tag));
tbxCsr.setTagAllocation(pDevice->getMemoryManager()->allocateGraphicsMemory(MockAllocationProperties{false, sizeof(tag)}, &tag));
EXPECT_FALSE(tbxCsr.makeCoherentCalled);

View File

@@ -410,7 +410,7 @@ struct UpdateEventTest : public ::testing::Test {
TEST_F(UpdateEventTest, givenEventContainingCommandQueueWhenItsStatusIsUpdatedToCompletedThenTemporaryAllocationsAreDeleted) {
void *ptr = (void *)0x1000;
size_t size = 4096;
auto temporary = memoryManager->allocateGraphicsMemory(size, ptr);
auto temporary = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
temporary->updateTaskCount(3, commandQueue->getCommandStreamReceiver().getOsContext().getContextId());
commandQueue->getCommandStreamReceiver().getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(temporary), TEMPORARY_ALLOCATION);
Event event(commandQueue.get(), CL_COMMAND_NDRANGE_KERNEL, 3, 3);

View File

@@ -21,7 +21,7 @@ set(IGDRCL_SRCS_tests_memory_manager
${CMAKE_CURRENT_SOURCE_DIR}/page_table_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/physical_address_allocator_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/surface_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/svm_memory_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/svm_memory_manager_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_memory_manager})
add_subdirectories()

View File

@@ -9,6 +9,7 @@
#include "runtime/helpers/ptr_math.h"
#include "runtime/memory_manager/memory_constants.h"
#include "unit_tests/fixtures/memory_manager_fixture.h"
#include "unit_tests/mocks/mock_allocation_properties.h"
#include "unit_tests/mocks/mock_csr.h"
#include "unit_tests/mocks/mock_host_ptr_manager.h"
#include "unit_tests/mocks/mock_internal_allocation_storage.h"
@@ -785,10 +786,10 @@ TEST_F(HostPtrAllocationTest, givenTwoAllocationsThatSharesOneFragmentWhenOneIsD
void *cpuPtr2 = ptrOffset(cpuPtr1, MemoryConstants::pageSize);
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(2 * MemoryConstants::pageSize - 1, cpuPtr1);
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 2 * MemoryConstants::pageSize - 1}, cpuPtr1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr2);
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr2);
EXPECT_EQ(3u, hostPtrManager->getFragmentCount());
memoryManager->freeGraphicsMemory(graphicsAllocation1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
@@ -817,7 +818,7 @@ TEST_F(HostPtrAllocationTest, whenOverlappedFragmentIsBiggerThenStoredAndStoredF
void *cpuPtr1 = (void *)0x100004;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
@@ -865,7 +866,7 @@ TEST_F(HostPtrAllocationTest, whenOverlappedFragmentIsBiggerThenStoredAndStoredF
void *cpuPtr1 = (void *)0x100004;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
@@ -912,10 +913,10 @@ TEST_F(HostPtrAllocationTest, checkAllocationsForOverlappingWithoutBiggerOverlap
void *cpuPtr2 = (void *)0x101008;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize * 3}, cpuPtr2);
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
@@ -967,7 +968,7 @@ TEST_F(HostPtrAllocationTest, checkAllocationsForOverlappingWithBiggerOverlapUnt
void *cpuPtr1 = (void *)0x100004;
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1);
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());

View File

@@ -27,9 +27,8 @@ struct InternalAllocationStorageTest : public MemoryAllocatorFixture,
TEST_F(InternalAllocationStorageTest, givenDebugFlagThatDisablesAllocationReuseWhenStoreReusableAllocationIsCalledThenAllocationIsReleased) {
DebugManagerStateRestore stateRestorer;
DebugManager.flags.DisableResourceRecycling.set(true);
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
storage->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
EXPECT_NE(allocation, csr->getAllocationsForReuse().peekHead());
@@ -37,11 +36,10 @@ TEST_F(InternalAllocationStorageTest, givenDebugFlagThatDisablesAllocationReuseW
}
TEST_F(InternalAllocationStorageTest, whenCleanAllocationListThenRemoveOnlyCompletedAllocations) {
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation2 = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation3 = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
auto allocation2 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
auto allocation3 = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
allocation->updateTaskCount(10, csr->getOsContext().getContextId());
allocation2->updateTaskCount(5, csr->getOsContext().getContextId());
@@ -76,8 +74,7 @@ TEST_F(InternalAllocationStorageTest, whenCleanAllocationListThenRemoveOnlyCompl
}
TEST_F(InternalAllocationStorageTest, whenAllocationIsStoredAsReusableButIsStillUsedThenCannotBeObtained) {
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION, 2u);
@@ -95,8 +92,7 @@ TEST_F(InternalAllocationStorageTest, whenObtainAllocationFromEmptyReuseListThen
}
TEST_F(InternalAllocationStorageTest, whenCompletedAllocationIsStoredAsReusableAndThenCanBeObtained) {
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
EXPECT_NE(nullptr, allocation);
storage->storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION, 2u);
@@ -113,8 +109,8 @@ TEST_F(InternalAllocationStorageTest, whenCompletedAllocationIsStoredAsReusableA
}
TEST_F(InternalAllocationStorageTest, whenNotUsedAllocationIsStoredAsReusableAndThenCanBeObtained) {
void *host_ptr = (void *)0x1234;
auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr);
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
EXPECT_NE(nullptr, allocation);
EXPECT_FALSE(allocation->isUsed());
EXPECT_EQ(0u, csr->peekTaskCount());

View File

@@ -225,7 +225,7 @@ TEST_F(MemoryAllocatorTest, AlignedHostPtrWithAlignedSizeWhenAskedForGraphicsAll
auto ptr = (void *)0x1000;
MockMemoryManager mockMemoryManager(*executionEnvironment);
auto hostPtrManager = static_cast<MockHostPtrManager *>(mockMemoryManager.getHostPtrManager());
auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemory(4096, ptr);
auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemory(MockAllocationProperties{false, 4096}, ptr);
EXPECT_NE(nullptr, graphicsAllocation);
EXPECT_EQ(1u, hostPtrManager->getFragmentCount());
@@ -242,7 +242,7 @@ TEST_F(MemoryAllocatorTest, GivenAlignedHostPtrAndCacheAlignedSizeWhenAskedForL3
auto ptr = (void *)0x1000;
auto alignedSize = MemoryConstants::cacheLineSize;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(alignedSize, ptr);
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr);
EXPECT_TRUE(graphicsAllocation->isL3Capable());
@@ -253,7 +253,7 @@ TEST_F(MemoryAllocatorTest, GivenAlignedHostPtrAndNotCacheAlignedSizeWhenAskedFo
auto ptr = (void *)0x1000;
auto alignedSize = MemoryConstants::cacheLineSize - 1;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(alignedSize, ptr);
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr);
EXPECT_FALSE(graphicsAllocation->isL3Capable());
@@ -264,7 +264,7 @@ TEST_F(MemoryAllocatorTest, GivenMisAlignedHostPtrAndNotCacheAlignedSizeWhenAske
auto ptr = (void *)0x1001;
auto alignedSize = MemoryConstants::cacheLineSize - 1;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(alignedSize, ptr);
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr);
EXPECT_FALSE(graphicsAllocation->isL3Capable());
@@ -275,7 +275,7 @@ TEST_F(MemoryAllocatorTest, GivenHostPtrAlignedToCacheLineWhenAskedForL3Allowanc
auto ptr = (void *)0x1040;
auto alignedSize = MemoryConstants::cacheLineSize;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(alignedSize, ptr);
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, alignedSize}, ptr);
EXPECT_TRUE(graphicsAllocation->isL3Capable());
@@ -283,7 +283,6 @@ TEST_F(MemoryAllocatorTest, GivenHostPtrAlignedToCacheLineWhenAskedForL3Allowanc
}
TEST_F(MemoryAllocatorTest, NullOsHandleStorageAskedForPopulationReturnsFilledPointer) {
OsHandleStorage storage;
storage.fragmentStorageData[0].cpuPtr = (void *)0x1000;
memoryManager->populateOsHandles(storage);
@@ -304,7 +303,7 @@ TEST_F(MemoryAllocatorTest, GivenEmptyMemoryManagerAndMisalingedHostPtrWithHugeS
ASSERT_EQ(3u, reqs.requiredFragmentsCount);
auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemory(size, cpuPtr);
auto graphicsAllocation = mockMemoryManager.allocateGraphicsMemory(MockAllocationProperties{false, 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);
@@ -317,7 +316,6 @@ TEST_F(MemoryAllocatorTest, GivenEmptyMemoryManagerAndMisalingedHostPtrWithHugeS
}
TEST_F(MemoryAllocatorTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocationThenGraphicsAllocationIsCreated) {
OsHandleStorage handleStorage;
auto ptr = (void *)0x1000;
auto ptr2 = (void *)0x1001;
@@ -696,7 +694,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPt
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = MemoryConstants::pageSize;
auto allocation = memoryManager.allocateGraphicsMemory(size, ptr);
auto allocation = memoryManager.allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
ASSERT_NE(nullptr, allocation);
EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool());
@@ -731,32 +729,20 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW
memoryManager.freeGraphicsMemory(allocation);
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) {
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryThenMemoryPoolIsSystem64KBPages) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
auto size = 4096u;
auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, false);
auto svmAllocation = memoryManager.allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SVM});
EXPECT_NE(nullptr, svmAllocation);
EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool());
memoryManager.freeGraphicsMemory(svmAllocation);
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryThen4KBGraphicsAllocationIsReturned) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto size = 4096u;
auto isCoherent = true;
auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, isCoherent);
EXPECT_NE(nullptr, svmAllocation);
EXPECT_TRUE(svmAllocation->isCoherent());
auto svmAllocation = memoryManager.allocateGraphicsMemoryWithProperties({MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SVM});
EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool());
EXPECT_EQ(size, svmAllocation->getUnderlyingBufferSize());
uintptr_t address = reinterpret_cast<uintptr_t>(svmAllocation->getUnderlyingBuffer());
EXPECT_EQ(0u, (address & MemoryConstants::pageMask));
memoryManager.freeGraphicsMemory(svmAllocation);
}
@@ -780,24 +766,6 @@ TEST(OsAgnosticMemoryManager, givenDeviceWith64kbPagesDisbledWhenCreatingMemoryM
EXPECT_FALSE(device->getMemoryManager()->peek64kbPagesEnabled());
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThen64KBGraphicsAllocationIsReturned) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
auto size = 4096u;
auto isCoherent = true;
auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, isCoherent);
EXPECT_NE(nullptr, svmAllocation);
EXPECT_TRUE(svmAllocation->isCoherent());
EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool());
EXPECT_EQ(MemoryConstants::pageSize64k, svmAllocation->getUnderlyingBufferSize());
uintptr_t address = reinterpret_cast<uintptr_t>(svmAllocation->getUnderlyingBuffer());
EXPECT_EQ(0u, (address & MemoryConstants::page64kMask));
memoryManager.freeGraphicsMemory(svmAllocation);
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocationFromSharedObjectIsCalledThenGraphicsAllocationIsReturned) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
@@ -965,7 +933,7 @@ TEST_F(MemoryManagerWithAsyncDeleterTest, givenMemoryManagerWhenAllocateGraphics
char ptr[128];
EXPECT_EQ(0, deleter->drainCalled);
deleter->expectDrainBlockingValue(true);
auto allocation = memoryManager.MemoryManager::allocateGraphicsMemory(sizeof(char), (void *)&ptr);
auto allocation = memoryManager.MemoryManager::allocateGraphicsMemory(MockAllocationProperties{false, sizeof(char)}, (void *)&ptr);
EXPECT_TRUE(deleter->isQueueEmpty());
memoryManager.freeGraphicsMemoryImpl(allocation);
}
@@ -974,7 +942,7 @@ TEST_F(MemoryManagerWithAsyncDeleterTest, givenMemoryManagerWhenAllocateGraphics
memoryManager.setDeferredDeleter(nullptr);
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
char ptr[128];
auto allocation = memoryManager.MemoryManager::allocateGraphicsMemory(sizeof(char), (void *)&ptr);
auto allocation = memoryManager.MemoryManager::allocateGraphicsMemory(MockAllocationProperties{false, sizeof(char)}, (void *)&ptr);
memoryManager.freeGraphicsMemoryImpl(allocation);
}
@@ -1151,23 +1119,22 @@ TEST_F(MemoryAllocatorTest, GivenSizeWhenGmmIsCreatedThenSuccess) {
typedef Test<MemoryManagerWithCsrFixture> MemoryManagerWithCsrTest;
TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerWhenBiggerOverllapingAllcoationIsCreatedAndNothingToCleanThenAbortExecution) {
void *cpuPtr1 = (void *)0x100004;
void *cpuPtr2 = (void *)0x101008;
void *cpuPtr3 = (void *)0x100000;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize * 3}, cpuPtr2);
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
GraphicsAllocation *graphicsAllocation3 = nullptr;
bool catchMe = false;
try {
graphicsAllocation3 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 10, cpuPtr3);
graphicsAllocation3 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize * 10}, cpuPtr3);
} catch (...) {
catchMe = true;
}
@@ -1194,10 +1161,10 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerReadyForCleanin
void *cpuPtr3 = (void *)0x100000;
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
auto graphicsAllocation1 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, cpuPtr1);
EXPECT_EQ(2u, hostPtrManager->getFragmentCount());
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 3, cpuPtr2);
auto graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize * 3}, cpuPtr2);
EXPECT_EQ(4u, hostPtrManager->getFragmentCount());
EXPECT_NE(nullptr, graphicsAllocation1);
@@ -1223,7 +1190,7 @@ TEST_F(MemoryManagerWithCsrTest, GivenAllocationsInHostPtrManagerReadyForCleanin
taskCount = taskCountReady;
csr->latestSentTaskCount = taskCountReady;
auto graphicsAllocation3 = memoryManager->allocateGraphicsMemory(MemoryConstants::pageSize * 10, cpuPtr3);
auto graphicsAllocation3 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize * 10}, cpuPtr3);
EXPECT_NE(nullptr, graphicsAllocation3);

View File

@@ -1,178 +0,0 @@
/*
* Copyright (C) 2017-2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/memory_manager/svm_memory_manager.h"
#include "runtime/utilities/tag_allocator.h"
#include "test.h"
#include "unit_tests/fixtures/memory_allocator_fixture.h"
#include "unit_tests/helpers/memory_management.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/utilities/containers_tests_helpers.h"
#include "gtest/gtest.h"
#include <future>
using namespace OCLRT;
typedef Test<MemoryAllocatorFixture> SVMMemoryAllocatorTest;
TEST_F(SVMMemoryAllocatorTest, allocateSystem) {
auto ptr = memoryManager->allocateSystemMemory(sizeof(char), 0);
EXPECT_NE(nullptr, ptr);
memoryManager->freeSystemMemory(ptr);
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateNullFreeNull) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(0, false, false);
EXPECT_EQ(Ptr1, nullptr);
svmM.freeSVMAlloc(nullptr);
}
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateFree) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(4096, false, false);
EXPECT_NE(Ptr1, nullptr);
svmM.freeSVMAlloc(Ptr1);
GraphicsAllocation *GA2 = svmM.getSVMAlloc(Ptr1);
EXPECT_EQ(GA2, nullptr);
}
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocGetNoSVMAdrees) {
char array[100];
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)100;
GraphicsAllocation *GA1 = svmM.getSVMAlloc(Ptr1);
EXPECT_EQ(GA1, nullptr);
GraphicsAllocation *GA2 = svmM.getSVMAlloc(array);
EXPECT_EQ(GA2, nullptr);
}
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocGetBeforeAndInside) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(4096, false, false);
EXPECT_NE(Ptr1, nullptr);
char *Ptr2 = Ptr1 - 4;
GraphicsAllocation *GA2 = svmM.getSVMAlloc(Ptr2);
EXPECT_EQ(GA2, nullptr);
char *Ptr3 = Ptr1 + 4;
GraphicsAllocation *GA3 = svmM.getSVMAlloc(Ptr3);
EXPECT_NE(GA3, nullptr);
EXPECT_EQ(GA3->getUnderlyingBuffer(), Ptr1);
svmM.freeSVMAlloc(Ptr1);
}
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocgetAfterSVM) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(4096, false, false);
EXPECT_NE(Ptr1, nullptr);
char *Ptr2 = Ptr1 + 4096 + 100;
GraphicsAllocation *GA2 = svmM.getSVMAlloc(Ptr2);
EXPECT_EQ(GA2, nullptr);
svmM.freeSVMAlloc(Ptr1);
}
}
TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNullAndDoesNotChangeAllocsMap) {
struct MockMemManager : public OsAgnosticMemoryManager {
using OsAgnosticMemoryManager::allocateGraphicsMemory;
public:
MockMemManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){};
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override {
return nullptr;
}
};
struct MockSVMAllocsManager : SVMAllocsManager {
MockSVMAllocsManager(MemoryManager *m)
: SVMAllocsManager(m) {
}
MapBasedAllocationTracker &GetSVMAllocs() {
return SVMAllocs;
}
};
ExecutionEnvironment executionEnvironment;
MockMemManager memoryManager(executionEnvironment);
{
MockSVMAllocsManager svmM{&memoryManager};
void *svmPtr = svmM.createSVMAlloc(512, false, false);
EXPECT_EQ(nullptr, svmPtr);
EXPECT_EQ(0U, svmM.GetSVMAllocs().getNumAllocs());
}
}
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedwhenAllocatingSvmMemoryThenDontPreferRenderCompression) {
class MyMemoryManager : public OsAgnosticMemoryManager {
public:
MyMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) { enable64kbpages = true; }
GraphicsAllocation *allocateGraphicsMemory64kb(AllocationData allocationData) override {
preferRenderCompressedFlag = allocationData.flags.preferRenderCompressed;
return nullptr;
}
bool preferRenderCompressedFlag = true;
};
ExecutionEnvironment executionEnvironment;
MyMemoryManager myMemoryManager(executionEnvironment);
myMemoryManager.allocateGraphicsMemoryForSVM(1, false);
EXPECT_FALSE(myMemoryManager.preferRenderCompressedFlag);
}
TEST_F(SVMMemoryAllocatorTest, whenReadOnlyFlagIsPresentThenReturnTrue) {
EXPECT_TRUE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_READ_ONLY));
EXPECT_TRUE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_HOST_READ_ONLY));
EXPECT_TRUE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_READ_ONLY));
}
TEST_F(SVMMemoryAllocatorTest, whenNoReadOnlyFlagIsPresentThenReturnFalse) {
EXPECT_FALSE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_READ_WRITE));
EXPECT_FALSE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_WRITE_ONLY));
}
TEST_F(SVMMemoryAllocatorTest, whenReadOnlySvmAllocationCreatedThenGraphicsAllocationHasWriteableFlagFalse) {
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
SVMAllocsManager svmM(&memoryManager);
void *svm = svmM.createSVMAlloc(4096, false, true);
EXPECT_NE(nullptr, svm);
GraphicsAllocation *svmAllocation = svmM.getSVMAlloc(svm);
EXPECT_NE(nullptr, svmAllocation);
EXPECT_FALSE(svmAllocation->isMemObjectsAllocationWithWritableFlags());
svmM.freeSVMAlloc(svm);
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (C) 2017-2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "unit_tests/mocks/mock_memory_manager.h"
#include "unit_tests/mocks/mock_svm_manager.h"
#include "gtest/gtest.h"
using namespace OCLRT;
struct SVMMemoryAllocatorTest : ::testing::Test {
SVMMemoryAllocatorTest() : memoryManager(false, false, executionEnvironment), svmManager(&memoryManager) {}
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager;
MockSVMAllocsManager svmManager;
};
TEST_F(SVMMemoryAllocatorTest, whenCreateZeroSizedSVMAllocationThenReturnNullptr) {
auto ptr = svmManager.createSVMAlloc(0, false, false);
EXPECT_EQ(0u, svmManager.SVMAllocs.getNumAllocs());
EXPECT_EQ(ptr, nullptr);
}
TEST_F(SVMMemoryAllocatorTest, whenSVMAllocationIsFreedThenCannotBeGotAgain) {
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, false, false);
EXPECT_NE(nullptr, ptr);
EXPECT_NE(nullptr, svmManager.getSVMAlloc(ptr));
EXPECT_NE(nullptr, svmManager.getSVMAlloc(ptr));
EXPECT_EQ(1u, svmManager.SVMAllocs.getNumAllocs());
EXPECT_FALSE(svmManager.getSVMAlloc(ptr)->isCoherent());
svmManager.freeSVMAlloc(ptr);
EXPECT_EQ(nullptr, svmManager.getSVMAlloc(ptr));
EXPECT_EQ(0u, svmManager.SVMAllocs.getNumAllocs());
}
TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromReturnedPointerAreaThenReturnSameAllocation) {
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, false, false);
EXPECT_NE(ptr, nullptr);
GraphicsAllocation *graphicsAllocation = svmManager.getSVMAlloc(ptr);
EXPECT_NE(nullptr, graphicsAllocation);
auto ptrInRange = ptrOffset(ptr, MemoryConstants::pageSize - 4);
GraphicsAllocation *graphicsAllocationInRange = svmManager.getSVMAlloc(ptrInRange);
EXPECT_NE(nullptr, graphicsAllocationInRange);
EXPECT_EQ(graphicsAllocation, graphicsAllocationInRange);
svmManager.freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenGetSVMAllocationFromOutsideOfReturnedPointerAreaThenDontReturnThisAllocation) {
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, false, false);
EXPECT_NE(ptr, nullptr);
GraphicsAllocation *graphicsAllocation = svmManager.getSVMAlloc(ptr);
EXPECT_NE(nullptr, graphicsAllocation);
auto ptrBefore = ptrOffset(ptr, -4);
GraphicsAllocation *graphicsAllocationBefore = svmManager.getSVMAlloc(ptrBefore);
EXPECT_EQ(nullptr, graphicsAllocationBefore);
auto ptrAfter = ptrOffset(ptr, MemoryConstants::pageSize);
GraphicsAllocation *graphicsAllocationAfter = svmManager.getSVMAlloc(ptrAfter);
EXPECT_EQ(nullptr, graphicsAllocationAfter);
svmManager.freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenCouldNotAllocateInMemoryManagerThenReturnsNullAndDoesNotChangeAllocsMap) {
FailMemoryManager failMemoryManager(executionEnvironment);
svmManager.memoryManager = &failMemoryManager;
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, false, false);
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(0u, svmManager.SVMAllocs.getNumAllocs());
svmManager.freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedWhenAllocatingSvmMemoryThenDontPreferRenderCompression) {
MockMemoryManager memoryManager64Kb(true, false, executionEnvironment);
svmManager.memoryManager = &memoryManager64Kb;
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, false, false);
EXPECT_FALSE(memoryManager64Kb.preferRenderCompressedFlagPassed);
svmManager.freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedwhenAllocatingSvmMemoryThenAllocationIsIn64kbPagePool) {
MockMemoryManager memoryManager64Kb(true, false, executionEnvironment);
svmManager.memoryManager = &memoryManager64Kb;
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, false, false);
EXPECT_EQ(MemoryPool::System64KBPages, svmManager.getSVMAlloc(ptr)->getMemoryPool());
svmManager.freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, given64kbDisallowedWhenAllocatingSvmMemoryThenAllocationIsIn4kbPagePool) {
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, false, false);
EXPECT_EQ(MemoryPool::System4KBPages, svmManager.getSVMAlloc(ptr)->getMemoryPool());
svmManager.freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenCoherentFlagIsPassedThenAllocationIsCoherent) {
auto ptr = svmManager.createSVMAlloc(MemoryConstants::pageSize, true, false);
EXPECT_TRUE(svmManager.getSVMAlloc(ptr)->isCoherent());
svmManager.freeSVMAlloc(ptr);
}
TEST_F(SVMMemoryAllocatorTest, whenReadOnlyFlagIsPresentThenReturnTrue) {
EXPECT_TRUE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_READ_ONLY));
EXPECT_TRUE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_HOST_READ_ONLY));
EXPECT_TRUE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_READ_ONLY));
}
TEST_F(SVMMemoryAllocatorTest, whenNoReadOnlyFlagIsPresentThenReturnFalse) {
EXPECT_FALSE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_READ_WRITE));
EXPECT_FALSE(SVMAllocsManager::memFlagIsReadOnly(CL_MEM_WRITE_ONLY));
}
TEST_F(SVMMemoryAllocatorTest, whenReadOnlySvmAllocationCreatedThenGraphicsAllocationHasWriteableFlagFalse) {
void *svm = svmManager.createSVMAlloc(4096, false, true);
EXPECT_NE(nullptr, svm);
GraphicsAllocation *svmAllocation = svmManager.getSVMAlloc(svm);
EXPECT_NE(nullptr, svmAllocation);
EXPECT_FALSE(svmAllocation->isMemObjectsAllocationWithWritableFlags());
svmManager.freeSVMAlloc(svm);
}

View File

@@ -63,6 +63,7 @@ set(IGDRCL_SRCS_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/mock_sip.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_source_level_debugger.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_submissions_aggregator.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_svm_manager.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_tbx_stream.h
)

View File

@@ -115,7 +115,7 @@ class FailMemoryManager : public MockMemoryManager {
GraphicsAllocation *allocateGraphicsMemory64kb(AllocationData allocationData) override {
return nullptr;
};
GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override {
GraphicsAllocation *allocateGraphicsMemory(const AllocationProperties &properties, const void *ptr) override {
return nullptr;
};
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override {

View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) 2018 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/memory_manager/svm_memory_manager.h"
namespace OCLRT {
struct MockSVMAllocsManager : SVMAllocsManager {
using SVMAllocsManager::memoryManager;
using SVMAllocsManager::SVMAllocs;
using SVMAllocsManager::SVMAllocsManager;
};
} // namespace OCLRT

View File

@@ -1022,7 +1022,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentTwiceWhenFragmentStorage) {
auto ptr = (void *)0x1001;
auto size = MemoryConstants::pageSize * 10;
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
auto allocation = mm->allocateGraphicsMemory(size, ptr);
auto allocation = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
ASSERT_EQ(3u, allocation->fragmentsStorage.fragmentCount);
@@ -1056,12 +1056,12 @@ TEST_F(DrmCommandStreamLeaksTest, givenFragmentedAllocationsWithResuedFragmentsW
//3 fragments
auto ptr = (void *)0x1001;
auto size = MemoryConstants::pageSize * 10;
auto graphicsAllocation = mm->allocateGraphicsMemory(size, ptr);
auto graphicsAllocation = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
auto offsetedPtr = (void *)((uintptr_t)ptr + size);
auto size2 = MemoryConstants::pageSize - 1;
auto graphicsAllocation2 = mm->allocateGraphicsMemory(size2, offsetedPtr);
auto graphicsAllocation2 = mm->allocateGraphicsMemory(MockAllocationProperties{false, size2}, offsetedPtr);
//graphicsAllocation2 reuses one fragment from graphicsAllocation
EXPECT_EQ(graphicsAllocation->fragmentsStorage.fragmentStorageData[2].residency, graphicsAllocation2->fragmentsStorage.fragmentStorageData[0].residency);
@@ -1123,7 +1123,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationCreatedFromThreeFragmentsWhenMa
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
auto allocation = mm->allocateGraphicsMemory(size, ptr);
auto allocation = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
ASSERT_EQ(3u, allocation->fragmentsStorage.fragmentCount);
@@ -1153,11 +1153,11 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationCreatedFromThreeFragmentsWhenMa
TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFragmentsWhenAllocationIsMadeResidentThenAllFragmentsAreMadeResident) {
auto ptr = (void *)0x1001;
auto size = MemoryConstants::pageSize;
auto size2 = 100;
auto size2 = 100u;
auto reqs = MockHostPtrManager::getAllocationRequirements(ptr, size);
auto allocation = mm->allocateGraphicsMemory(size, ptr);
auto allocation = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
ASSERT_EQ(2u, allocation->fragmentsStorage.fragmentCount);
ASSERT_EQ(2u, reqs.requiredFragmentsCount);
@@ -1185,7 +1185,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenAllocationsContainingDifferentCountOfFrag
mm->freeGraphicsMemory(allocation);
csr->getResidencyAllocations().clear();
auto allocation2 = mm->allocateGraphicsMemory(size2, ptr);
auto allocation2 = mm->allocateGraphicsMemory(MockAllocationProperties{false, size2}, ptr);
reqs = MockHostPtrManager::getAllocationRequirements(ptr, size2);
ASSERT_EQ(1u, allocation2->fragmentsStorage.fragmentCount);
@@ -1219,8 +1219,8 @@ TEST_F(DrmCommandStreamLeaksTest, GivenTwoAllocationsWhenBackingStorageIsTheSame
auto size = MemoryConstants::pageSize;
auto ptr2 = (void *)0x1000;
auto allocation = mm->allocateGraphicsMemory(size, ptr);
auto allocation2 = mm->allocateGraphicsMemory(size, ptr2);
auto allocation = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
auto allocation2 = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr2);
csr->makeResident(*allocation);
csr->makeResident(*allocation2);
@@ -1242,8 +1242,8 @@ TEST_F(DrmCommandStreamLeaksTest, GivenTwoAllocationsWhenBackingStorageIsDiffere
auto size = MemoryConstants::pageSize;
auto ptr2 = (void *)0x3000;
auto allocation = mm->allocateGraphicsMemory(size, ptr);
auto allocation2 = mm->allocateGraphicsMemory(size, ptr2);
auto allocation = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
auto allocation2 = mm->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr2);
csr->makeResident(*allocation);
csr->makeResident(*allocation2);

View File

@@ -440,7 +440,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr) {
void *ptr = ::alignedMalloc(1024, 4096);
ASSERT_NE(nullptr, ptr);
auto alloc = memoryManager->allocateGraphicsMemory(1024, ptr);
auto alloc = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 1024}, ptr));
ASSERT_NE(nullptr, alloc);
EXPECT_NE(nullptr, alloc->getUnderlyingBuffer());
EXPECT_EQ(ptr, alloc->getUnderlyingBuffer());
@@ -461,7 +461,9 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_Nullptr) {
void *ptr = nullptr;
auto alloc = memoryManager->allocateGraphicsMemory(1024, ptr);
allocationData.hostPtr = nullptr;
allocationData.size = MemoryConstants::pageSize;
auto alloc = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemoryWithHostPtr(allocationData));
ASSERT_NE(nullptr, alloc);
EXPECT_EQ(ptr, alloc->getUnderlyingBuffer());
@@ -484,7 +486,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_MisAligned) {
void *ptr = ptrOffset(ptrT, 128);
auto alloc = memoryManager->allocateGraphicsMemory(1024, ptr);
auto alloc = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 1024}, ptr));
ASSERT_NE(nullptr, alloc);
EXPECT_NE(nullptr, alloc->getUnderlyingBuffer());
EXPECT_EQ(ptr, alloc->getUnderlyingBuffer());
@@ -505,7 +507,7 @@ TEST_F(DrmMemoryManagerTest, Allocate_HostPtr_UserptrFail) {
void *ptrT = ::alignedMalloc(1024, 4096);
ASSERT_NE(nullptr, ptrT);
auto alloc = memoryManager->allocateGraphicsMemory(1024, ptrT);
auto alloc = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 1024}, ptrT);
EXPECT_EQ(nullptr, alloc);
::alignedFree(ptrT);
@@ -694,7 +696,7 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked
auto ptr = reinterpret_cast<void *>(0x1001);
auto size = MemoryConstants::pageSize * 10;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, ptr);
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
@@ -2441,7 +2443,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenMemoryManagerWhenAlloc
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size, ptr);
auto allocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
ASSERT_NE(nullptr, allocation);
EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool());
memoryManager->freeGraphicsMemory(allocation);
@@ -2464,17 +2466,6 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrI
memoryManager->freeGraphicsMemory(allocation);
}
TEST(DrmMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
EXPECT_NE(nullptr, svmAllocation);
EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool());
memoryManager->freeGraphicsMemory(svmAllocation);
}
TEST(DrmMemoryManager, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) {
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
@@ -2496,17 +2487,6 @@ TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAlloca
memoryManager->freeGraphicsMemory(allocation);
}
TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) {
ExecutionEnvironment executionEnvironment;
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
EXPECT_NE(nullptr, svmAllocation);
EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool());
memoryManager->freeGraphicsMemory(svmAllocation);
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEnabledValidateHostMemoryWhenPinBBAllocationFailsThenUnrecoverableIsCalled) {
this->mock->ioctl_res = -1;
this->mock->ioctl_expected.gemUserptr = 1;
@@ -2617,7 +2597,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE
size_t size = 10 * 1024 * 1024;
void *ptr = ::alignedMalloc(size, 4096);
auto alloc = memoryManager->allocateGraphicsMemory(size, ptr);
auto alloc = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr));
ASSERT_NE(nullptr, alloc);
EXPECT_NE(nullptr, alloc->getBO());

View File

@@ -580,7 +580,7 @@ TEST_F(WddmCommandStreamTest, givenGraphicsAllocationWhenMakeResidentThenAllocat
void *hostPtr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1234);
auto size = 1234u;
auto gfxAllocation = memoryManager->allocateGraphicsMemory(size, hostPtr);
auto gfxAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, hostPtr);
ASSERT_NE(nullptr, gfxAllocation);
@@ -596,7 +596,7 @@ TEST_F(WddmCommandStreamTest, givenHostPtrWhenPtrBelowRestrictionThenCreateAlloc
void *hostPtr = reinterpret_cast<void *>(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000);
auto size = 0x2000u;
auto gfxAllocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(size, hostPtr));
auto gfxAllocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, hostPtr));
void *expectedReserve = reinterpret_cast<void *>(wddm->virtualAllocAddress);
@@ -616,8 +616,8 @@ TEST_F(WddmCommandStreamTest, givenTwoTemporaryAllocationsWhenCleanTemporaryAllo
void *host_ptr2 = (void *)0x2212341;
auto size = 17262u;
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(size, host_ptr);
GraphicsAllocation *graphicsAllocation2 = memoryManager->allocateGraphicsMemory(size, host_ptr2);
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, host_ptr);
GraphicsAllocation *graphicsAllocation2 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, host_ptr2);
csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(graphicsAllocation), TEMPORARY_ALLOCATION);
csr->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(graphicsAllocation2), TEMPORARY_ALLOCATION);

View File

@@ -137,7 +137,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size, ptr);
auto allocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
ASSERT_NE(nullptr, allocation);
EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool());
for (size_t i = 0; i < allocation->fragmentsStorage.fragmentCount; i++) {
@@ -160,22 +160,22 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMThen4KBGraphicsAllocationIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::SVM});
EXPECT_NE(nullptr, svmAllocation);
EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool());
EXPECT_TRUE(svmAllocation->gmm->useSystemMemoryPool);
memoryManager->freeGraphicsMemory(svmAllocation);
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) {
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(true, false, wddm, executionEnvironment));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
auto svmAllocation = memoryManager->allocateGraphicsMemoryWithProperties({size, GraphicsAllocation::AllocationType::SVM});
EXPECT_NE(nullptr, svmAllocation);
EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool());
memoryManager->freeGraphicsMemory(svmAllocation);
@@ -272,7 +272,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtr) {
void *ptr = alignedMalloc(3 * 4096, 4096);
ASSERT_NE(nullptr, ptr);
auto *gpuAllocation = memoryManager->allocateGraphicsMemory(0x1000, ptr);
auto *gpuAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, ptr);
// Should be same cpu ptr and gpu ptr
EXPECT_EQ(ptr, gpuAllocation->getUnderlyingBuffer());
@@ -583,7 +583,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) {
size_t baseOffset = 1024;
// misalligned buffer spanning accross 3 pages
auto *gpuAllocation = memoryManager->allocateGraphicsMemory(2 * 4096, (char *)ptr + baseOffset);
auto *gpuAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, (char *)ptr + baseOffset);
// Should be same cpu ptr and gpu ptr
EXPECT_EQ((char *)ptr + baseOffset, gpuAllocation->getUnderlyingBuffer());
@@ -601,7 +601,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) {
// offseted by one page, still in boundary
void *offsetedPtr = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) + 4096);
auto *gpuAllocation2 = memoryManager->allocateGraphicsMemory(0x1000, offsetedPtr);
auto *gpuAllocation2 = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, offsetedPtr);
// Should be same cpu ptr and gpu ptr
EXPECT_EQ(offsetedPtr, gpuAllocation2->getUnderlyingBuffer());
@@ -633,7 +633,7 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemCheckGmm) {
bool success = false;
// three pages
void *ptr = alignedMalloc(3 * 4096, 4096);
auto *gpuAllocation = memoryManager->allocateGraphicsMemory(3 * 4096, ptr);
auto *gpuAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 3 * MemoryConstants::pageSize}, ptr);
// Should be same cpu ptr and gpu ptr
ASSERT_NE(nullptr, gpuAllocation);
EXPECT_EQ(ptr, gpuAllocation->getUnderlyingBuffer());
@@ -789,7 +789,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCpuMemNotMeetRestriction
void *cpuPtr = reinterpret_cast<void *>(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000);
size_t size = 0x1000;
WddmAllocation *allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(size, cpuPtr));
WddmAllocation *allocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, cpuPtr));
void *expectReserve = reinterpret_cast<void *>(wddm->virtualAllocAddress);
@@ -921,7 +921,7 @@ TEST_F(BufferWithWddmMemory, NullOsHandleStorageAskedForPopulationReturnsFilledP
TEST_F(BufferWithWddmMemory, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAskedForGraphicsAllcoationThenItContainsAllFragmentsWithProperGpuAdrresses) {
auto ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1001);
auto size = MemoryConstants::pageSize * 10;
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(size, ptr);
auto graphicsAllocation = memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, size}, ptr);
auto hostPtrManager = static_cast<MockHostPtrManager *>(memoryManager->getHostPtrManager());
@@ -1129,7 +1129,7 @@ TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledW
EXPECT_TRUE(wddm->init(PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0])));
MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment);
auto wddmAlloc = (WddmAllocation *)memoryManager.allocateGraphicsMemory(4096u, reinterpret_cast<void *>(0x1000));
auto wddmAlloc = (WddmAllocation *)memoryManager.allocateGraphicsMemory(MockAllocationProperties{false, MemoryConstants::pageSize}, reinterpret_cast<void *>(0x1000));
EXPECT_TRUE(memoryManager.validateAllocationMock(wddmAlloc));

View File

@@ -12,6 +12,7 @@
#include "runtime/os_interface/os_interface.h"
#include "runtime/os_interface/windows/os_interface.h"
#include "runtime/os_interface/windows/wddm_residency_controller.h"
#include "unit_tests/mocks/mock_allocation_properties.h"
#include "unit_tests/mocks/mock_wddm.h"
#include "unit_tests/os_interface/windows/mock_gdi_interface.h"
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
@@ -498,7 +499,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation
// 3-fragment Allocation
void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1500);
auto allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(8196, ptr));
auto allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptr));
// whole allocation unused since previous trim
allocationTriple->getResidencyData().updateCompletionData(0, osContextId);
@@ -737,7 +738,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, trimToBudgetEvictsDon
allocation2.getResidencyData().resident[osContextId] = true;
void *ptrTriple = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) + 0x500);
WddmAllocation *allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(8196, ptrTriple));
WddmAllocation *allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptrTriple));
allocationTriple->getResidencyData().updateCompletionData(1, osContextId);
allocationTriple->getResidencyData().resident[osContextId] = true;
@@ -877,7 +878,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidency
MockWddmAllocation allocation1, allocation2;
void *ptr = reinterpret_cast<void *>(wddm->virtualAllocAddress + 0x1500);
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr);
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptr);
ResidencyContainer residencyPack{&allocation1, allocationTriple, &allocation2};
residencyController->makeResidentResidencyAllocations(residencyPack);
@@ -894,7 +895,7 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidency
TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, makeResidentResidencyAllocationsSetsLastFencePLusOneForTripleAllocations) {
MockWddmAllocation allocation1, allocation2;
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, reinterpret_cast<void *>(0x1500));
WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, reinterpret_cast<void *>(0x1500));
residencyController->getMonitoredFence().currentFenceValue = 20;
@@ -930,7 +931,7 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin
TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenDontMarkTripleAllocationsAsResident) {
MockWddmAllocation allocation1, allocation2;
void *ptr = reinterpret_cast<void *>(wddm->getWddmMinAddress() + 0x1500);
WddmAllocation *allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(8196, ptr));
WddmAllocation *allocationTriple = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemory(MockAllocationProperties{false, 2 * MemoryConstants::pageSize}, ptr));
ASSERT_NE(nullptr, allocationTriple);
auto makeResidentWithOutBytesToTrim = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = 4 * 4096; return false; };