Pass execution environment to memory manager

Change-Id: If43cf9d1353b4cbc02ea269fb9105c01cc4e0876
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-10-01 16:10:54 +02:00
committed by sys_ocldev
parent 84865512cd
commit b602cd2bb8
59 changed files with 479 additions and 399 deletions

View File

@@ -8,7 +8,8 @@
#include "unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl"
TEST(MemoryManagerTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Error;
AllocationData allocData;

View File

@@ -6,6 +6,7 @@
*/
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/execution_environment/execution_environment.h"
#include "gtest/gtest.h"
#include "test.h"
@@ -13,7 +14,8 @@
using namespace OCLRT;
TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
AllocationData allocData;
allocData.allFlags = 0;
@@ -27,7 +29,8 @@ TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePool
}
TEST(MemoryManagerTest, givenAllowed32BitAndFroce32BitWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.setForce32BitAllocations(true);
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;

View File

@@ -5,6 +5,7 @@
*
*/
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "unit_tests/mocks/mock_memory_manager.h"
@@ -118,7 +119,6 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, given64kbAllow
MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, allocType);
bool bufferCompressedType = (allocType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
EXPECT_TRUE(allocData.flags.allow64kbPages);
MockMemoryManager mockMemoryManager(true);
auto allocation = mockMemoryManager.allocateGraphicsMemory(allocData);
@@ -168,7 +168,8 @@ INSTANTIATE_TEST_CASE_P(Disallow32BitAnd64kbPagesTypes,
::testing::ValuesIn(allocationTypesWith32BitAnd64KbPagesNotAllowed));
TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedTypeIsAllocatedThen32BitAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.setForce32BitAllocations(true);
AllocationData allocData;
@@ -190,7 +191,8 @@ TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedType
}
TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemoryWihtoutAllow32BitFlagIsAllocatedThenNon32BitAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.setForce32BitAllocations(true);
AllocationData allocData;
@@ -207,7 +209,8 @@ TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemoryWihtoutAllow32B
}
TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagFor32BitAllowedTypeIsAllocatedThenNon32BitAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.setForce32BitAllocations(false);
AllocationData allocData;
@@ -223,7 +226,8 @@ TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagF
}
TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThen64kbAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager(true, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
AllocationData allocData;
AllocationFlags flags(true);
@@ -272,7 +276,8 @@ TEST(MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeHostMemory
}
TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThen32BitAllocationOver64kbIsChosen) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.setForce32BitAllocations(true);
AllocationData allocData;
@@ -292,7 +297,8 @@ TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMus
}
TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHostPtrForBufferThenExistingMemoryIsUsedForAllocation) {
OsAgnosticMemoryManager memoryManager(true, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
AllocationData allocData;
AllocationFlags flags(false);

View File

@@ -581,11 +581,12 @@ TEST_F(MemoryAllocatorTest, getEventPerfCountAllocator) {
}
TEST_F(MemoryAllocatorTest, givenTimestampPacketAllocatorWhenAskingForTagThenReturnValidObject) {
ExecutionEnvironment executionEnvironment;
class MyMockMemoryManager : public OsAgnosticMemoryManager {
public:
using OsAgnosticMemoryManager::timestampPacketAllocator;
MyMockMemoryManager() : OsAgnosticMemoryManager(false, false){};
} myMockMemoryManager;
MyMockMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){};
} myMockMemoryManager(executionEnvironment);
EXPECT_EQ(nullptr, myMockMemoryManager.timestampPacketAllocator.get());
@@ -790,25 +791,27 @@ TEST_F(MemoryAllocatorTest, given32BitDeviceWhenPrintfSurfaceIsCreatedThen32BitA
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenForce32BitAllocationsIsFalse) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
EXPECT_FALSE(memoryManager.peekForce32BitAllocations());
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenForce32bitallocationIsCalledWithTrueThenMemoryManagerForces32BitAlloactions) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.setForce32BitAllocations(true);
EXPECT_TRUE(memoryManager.peekForce32BitAllocations());
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemoryForImageIsCalledThenGraphicsAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
cl_image_desc imgDesc = {};
imgDesc.image_width = 512;
imgDesc.image_height = 1;
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
ExecutionEnvironment executionEnvironment;
executionEnvironment.initGmm(*platformDevices);
auto queryGmm = MockGmm::queryImgParams(imgInfo);
@@ -821,7 +824,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemor
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAllocationWhenMappingThenReturnFalse) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto gmm = new Gmm(nullptr, 123, false);
auto allocation = memoryManager.allocateGraphicsMemory(123);
@@ -836,7 +840,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAlloc
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) {
OsAgnosticMemoryManager memoryManager(false, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto size = 4096u;
auto allocation = memoryManager.allocateGraphicsMemory(size);
@@ -851,7 +856,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCall
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) {
OsAgnosticMemoryManager memoryManager(true, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
auto size = 4096u;
auto allocation = memoryManager.allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false);
@@ -863,13 +869,14 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryFailsThenNullptrIsReturned) {
class MockOsAgnosticManagerWithFailingAllocate : public OsAgnosticMemoryManager {
public:
MockOsAgnosticManagerWithFailingAllocate(bool enable64kbPages) : OsAgnosticMemoryManager(enable64kbPages, false) {}
MockOsAgnosticManagerWithFailingAllocate(bool enable64kbPages, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, false, executionEnvironment) {}
GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override {
return nullptr;
}
};
MockOsAgnosticManagerWithFailingAllocate memoryManager(true);
ExecutionEnvironment executionEnvironment;
MockOsAgnosticManagerWithFailingAllocate memoryManager(true, executionEnvironment);
auto size = 4096u;
auto allocation = memoryManager.allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false);
@@ -878,7 +885,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) {
OsAgnosticMemoryManager memoryManager(false, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = MemoryConstants::pageSize;
@@ -891,7 +899,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPt
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
OsAgnosticMemoryManager memoryManager(false, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = MemoryConstants::pageSize;
@@ -904,7 +913,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithoutPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
OsAgnosticMemoryManager memoryManager(false, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
void *ptr = nullptr;
auto size = MemoryConstants::pageSize;
@@ -916,7 +926,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) {
OsAgnosticMemoryManager memoryManager(true, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
auto size = 4096u;
auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, false);
@@ -926,7 +937,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager(false, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto size = 4096u;
auto isCoherent = true;
@@ -963,7 +975,8 @@ TEST(OsAgnosticMemoryManager, givenDeviceWith64kbPagesDisbledWhenCreatingMemoryM
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThen64KBGraphicsAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager(true, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
auto size = 4096u;
auto isCoherent = true;
@@ -980,7 +993,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocationFromSharedObjectIsCalledThenGraphicsAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
osHandle handle = 1;
auto size = 4096u;
auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, false);
@@ -994,13 +1008,15 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenCreateAllocationFromNtHandleIsCalledThenReturnNullptr) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto graphicsAllocation = memoryManager.createGraphicsAllocationFromNTHandle((void *)1);
EXPECT_EQ(nullptr, graphicsAllocation);
}
TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenLockUnlockCalledThenDoNothing) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto allocation = memoryManager.allocateGraphicsMemory(1);
ASSERT_NE(nullptr, allocation);
@@ -1012,7 +1028,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenLockUnlockCalledThenDoNothin
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationContainsOffsetWhenAddressIsObtainedThenOffsetIsAdded) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u);
@@ -1031,7 +1048,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationCon
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationIsPaddedThenNewGraphicsAllocationIsCreated) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u);
auto sizeWithPadding = 8192;
@@ -1049,7 +1067,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationIsP
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenTwoGraphicsAllocationArePaddedThenOnlyOnePaddingBufferIsUsed) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u);
auto sizeWithPadding = 8192;
@@ -1072,7 +1091,8 @@ TEST(OsAgnosticMemoryManager, pleaseDetectLeak) {
}
TEST(OsAgnosticMemoryManager, alignmentIsCorrect) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
const size_t alignment = 0;
auto ga = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize >> 1, alignment, false, false);
uintptr_t ptr = reinterpret_cast<uintptr_t>(ga->getUnderlyingBuffer());
@@ -1083,7 +1103,8 @@ TEST(OsAgnosticMemoryManager, alignmentIsCorrect) {
}
TEST(OsAgnosticMemoryManager, givenCommonMemoryManagerWhenIsAskedIfApplicationMemoryBudgetIsExhaustedThenFalseIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
EXPECT_FALSE(memoryManager.isMemoryBudgetExhausted());
}
@@ -1092,7 +1113,6 @@ class MemoryManagerWithAsyncDeleterTest : public ::testing::Test {
void SetUp() override {
memoryManager.overrideAsyncDeleterFlag(true);
}
MockMemoryManager memoryManager;
};
@@ -1147,7 +1167,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenIsAsyncDeleterEnabledCalledT
}
TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsFalse) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
}
@@ -1155,7 +1176,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncD
TEST(OsAgnosticMemoryManager, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) {
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(true);
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
@@ -1164,7 +1186,8 @@ TEST(OsAgnosticMemoryManager, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCre
TEST(OsAgnosticMemoryManager, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) {
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(false);
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
@@ -1173,7 +1196,8 @@ TEST(OsAgnosticMemoryManager, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCr
TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCreatedThenAlignedto64KbAllocationIsReturned) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.Enable64kbpages.set(true);
OsAgnosticMemoryManager memoryManager(true, false);
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment);
GraphicsAllocation *galloc = memoryManager.allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, 64 * 1024, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
EXPECT_NE(nullptr, galloc);
@@ -1190,7 +1214,8 @@ TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCre
}
TEST(OsAgnosticMemoryManager, checkAllocationsForOverlappingWithNullCsrInMemoryManager) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
AllocationRequirements requirements;
CheckedFragments checkedFragments;
@@ -1205,7 +1230,8 @@ TEST(OsAgnosticMemoryManager, checkAllocationsForOverlappingWithNullCsrInMemoryM
}
TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsCalledThenGraphicsAllocationIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto ptr = (void *)0x100000;
size_t allocationSize = 4096;
auto graphicsAllocation = memoryManager.allocate32BitGraphicsMemory(allocationSize, ptr, AllocationOrigin::INTERNAL_ALLOCATION);
@@ -1214,13 +1240,15 @@ TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsC
memoryManager.freeGraphicsMemory(graphicsAllocation);
}
TEST(OsAgnosticMemoryManager, givenDefaultOsAgnosticMemoryManagerWhenItIsQueriedForInternalHeapBaseThen32BitAllocatorBaseIsReturned) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto heapBase = memoryManager.allocator32Bit->getBase();
EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress());
}
TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledThenAllocationIsCreated) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto hostPtr = reinterpret_cast<void *>(0x5001);
auto allocation = memoryManager.allocateGraphicsMemoryForNonSvmHostPtr(13, hostPtr);
EXPECT_NE(nullptr, allocation);
@@ -1231,7 +1259,8 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenAllocateGraphicsMe
}
TEST(OsAgnosticMemoryManager, givenReducedGpuAddressSpaceWhenAllocateGraphicsMemoryForHostPtrIsCalledThenAllocationWithoutFragmentsIsCreated) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto hostPtr = reinterpret_cast<void *>(0x5001);
auto allocation = memoryManager.allocateGraphicsMemoryForHostPtr(13, hostPtr, false);
@@ -1242,7 +1271,8 @@ TEST(OsAgnosticMemoryManager, givenReducedGpuAddressSpaceWhenAllocateGraphicsMem
}
TEST(OsAgnosticMemoryManager, givenFullGpuAddressSpaceWhenAllocateGraphicsMemoryForHostPtrIsCalledThenAllocationWithFragmentsIsCreated) {
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
auto hostPtr = reinterpret_cast<void *>(0x5001);
auto allocation = memoryManager.allocateGraphicsMemoryForHostPtr(13, hostPtr, true);
@@ -1253,7 +1283,8 @@ TEST(OsAgnosticMemoryManager, givenFullGpuAddressSpaceWhenAllocateGraphicsMemory
}
TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
MockMemoryManager memoryManager(false, false, false);
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager(false, false, false, executionEnvironment);
uint64_t heap32Base = 0x80000000000ul;
if (is32bit) {
@@ -1263,7 +1294,8 @@ TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedWhenMemoryManagerIsCre
}
TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
MockMemoryManager memoryManager(false, true, false);
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager(false, true, false, executionEnvironment);
uint64_t heap32Base = 0x80000000000ul;
if (is32bit) {
@@ -1273,7 +1305,8 @@ TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryM
}
TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
MockMemoryManager memoryManager(false, false, true);
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager(false, false, true, executionEnvironment);
uint64_t heap32Base = 0x80000000000ul;
if (is32bit) {
@@ -1283,7 +1316,8 @@ TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryM
}
TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
MockMemoryManager memoryManager(false, true, true);
ExecutionEnvironment executionEnvironment;
MockMemoryManager memoryManager(false, true, true, executionEnvironment);
uint64_t heap32Base = 0x80000000000ul;
if (is32bit) {
@@ -1599,7 +1633,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasNotUsedWhencheckGpuUsageA
TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsDestroyedInPlace) {
auto usedAllocationButGpuCompleted = memoryManager->allocateGraphicsMemory(4096);
auto tagAddress = memoryManager->csr->getTagAddress();
auto tagAddress = memoryManager->getCommandStreamReceiver(0)->getTagAddress();
ASSERT_NE(0u, *tagAddress);
usedAllocationButGpuCompleted->taskCount = *tagAddress - 1;
@@ -1611,7 +1645,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhenche
TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsAddedToTemporaryAllocationList) {
auto usedAllocationAndNotGpuCompleted = memoryManager->allocateGraphicsMemory(4096);
auto tagAddress = memoryManager->csr->getTagAddress();
auto tagAddress = memoryManager->getCommandStreamReceiver(0)->getTagAddress();
usedAllocationAndNotGpuCompleted->taskCount = *tagAddress + 1;
@@ -1625,7 +1659,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhen
class MockAlignMallocMemoryManager : public MockMemoryManager {
public:
MockAlignMallocMemoryManager() : MockMemoryManager() {
MockAlignMallocMemoryManager() {
testMallocRestrictions.minAddress = 0;
alignMallocRestrictions = nullptr;
alignMallocCount = 0;
@@ -1677,7 +1711,7 @@ class MockAlignMallocMemoryManagerTest : public MemoryAllocatorTest {
void SetUp() override {
MemoryAllocatorTest::SetUp();
alignedMemoryManager = new (std::nothrow) MockAlignMallocMemoryManager();
alignedMemoryManager = new (std::nothrow) MockAlignMallocMemoryManager;
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
}
@@ -1786,7 +1820,8 @@ TEST(GraphicsAllocation, givenGraphicsAllocationCreatedWithDefaultConstructorThe
TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCountIncreases) {
auto osContext = new OsContext(nullptr, 0u);
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.registerOsContext(osContext);
EXPECT_EQ(1u, memoryManager.getOsContextCount());
EXPECT_EQ(1, osContext->getRefInternalCount());
@@ -1795,7 +1830,8 @@ TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCo
TEST(ResidencyDataTest, givenTwoOsContextsWhenTheyAreRegistredFromHigherToLowerThenProperSizeIsReturned) {
auto osContext2 = new OsContext(nullptr, 1u);
auto osContext = new OsContext(nullptr, 0u);
OsAgnosticMemoryManager memoryManager;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
memoryManager.registerOsContext(osContext2);
memoryManager.registerOsContext(osContext);
EXPECT_EQ(2u, memoryManager.getOsContextCount());

View File

@@ -28,9 +28,10 @@ TEST_F(SVMMemoryAllocatorTest, allocateSystem) {
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateNullFreeNull) {
OsAgnosticMemoryManager umm;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&umm);
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(0);
EXPECT_EQ(Ptr1, nullptr);
svmM.freeSVMAlloc(nullptr);
@@ -38,9 +39,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateNullFreeNull) {
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateFree) {
OsAgnosticMemoryManager umm;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&umm);
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(4096);
EXPECT_NE(Ptr1, nullptr);
@@ -52,9 +54,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateFree) {
TEST_F(SVMMemoryAllocatorTest, SVMAllocGetNoSVMAdrees) {
char array[100];
OsAgnosticMemoryManager umm;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&umm);
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)100;
GraphicsAllocation *GA1 = svmM.getSVMAlloc(Ptr1);
@@ -66,9 +69,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocGetNoSVMAdrees) {
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocGetBeforeAndInside) {
OsAgnosticMemoryManager umm;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&umm);
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(4096);
EXPECT_NE(Ptr1, nullptr);
@@ -86,9 +90,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocGetBeforeAndInside) {
}
TEST_F(SVMMemoryAllocatorTest, SVMAllocgetAfterSVM) {
OsAgnosticMemoryManager umm;
ExecutionEnvironment executionEnvironment;
OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment);
{
SVMAllocsManager svmM(&umm);
SVMAllocsManager svmM(&memoryManager);
char *Ptr1 = (char *)svmM.createSVMAlloc(4096);
EXPECT_NE(Ptr1, nullptr);
@@ -105,6 +110,7 @@ TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNul
using OsAgnosticMemoryManager::allocateGraphicsMemory;
public:
MockMemManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){};
GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override {
return nullptr;
}
@@ -120,10 +126,10 @@ TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNul
return SVMAllocs;
}
};
MockMemManager mm;
ExecutionEnvironment executionEnvironment;
MockMemManager memoryManager(executionEnvironment);
{
MockSVMAllocsManager svmM{&mm};
MockSVMAllocsManager svmM{&memoryManager};
void *svmPtr = svmM.createSVMAlloc(512);
EXPECT_EQ(nullptr, svmPtr);
@@ -134,15 +140,15 @@ TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNul
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedwhenAllocatingSvmMemoryThenDontPreferRenderCompression) {
class MyMemoryManager : public OsAgnosticMemoryManager {
public:
MyMemoryManager() { enable64kbpages = true; }
MyMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) { enable64kbpages = true; }
GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override {
preferRenderCompressedFlag = preferRenderCompressed;
return nullptr;
}
bool preferRenderCompressedFlag = true;
};
MyMemoryManager myMemoryManager;
ExecutionEnvironment executionEnvironment;
MyMemoryManager myMemoryManager(executionEnvironment);
myMemoryManager.allocateGraphicsMemoryForSVM(1, false);
EXPECT_FALSE(myMemoryManager.preferRenderCompressedFlag);
}