diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index cf2650eb95..f950fd91f5 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -49,6 +49,13 @@ CommandStreamReceiver::~CommandStreamReceiver() { } } cleanupResources(); + + if (!allocationsForReuse.peekIsEmpty()) { + getMemoryManager()->freeAllocationsList(-1, allocationsForReuse); + } + if (!temporaryAllocations.peekIsEmpty()) { + getMemoryManager()->freeAllocationsList(-1, temporaryAllocations); + } } void CommandStreamReceiver::makeResident(GraphicsAllocation &gfxAllocation) { @@ -111,14 +118,17 @@ void CommandStreamReceiver::makeResidentHostPtrAllocation(GraphicsAllocation *gf } void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requiredTaskCount, uint32_t allocationType) { - auto address = getTagAddress(); if (address && requiredTaskCount != (unsigned int)-1) { while (*address < requiredTaskCount) ; } - getMemoryManager()->cleanAllocationList(requiredTaskCount, allocationType); + auto &allocationList = (allocationType == TEMPORARY_ALLOCATION) ? temporaryAllocations : allocationsForReuse; + if (allocationList.peekIsEmpty()) { + return; + } + getMemoryManager()->freeAllocationsList(requiredTaskCount, allocationList); } MemoryManager *CommandStreamReceiver::getMemoryManager() { diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index adbf6ea4d2..466f176d7e 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -15,8 +15,9 @@ #include "runtime/helpers/completion_stamp.h" #include "runtime/helpers/flat_batch_buffer_helper.h" #include "runtime/helpers/options.h" -#include "runtime/kernel/grf_config.h" #include "runtime/indirect_heap/indirect_heap.h" +#include "runtime/kernel/grf_config.h" +#include "runtime/memory_manager/allocations_list.h" #include #include @@ -149,6 +150,8 @@ class CommandStreamReceiver { size_t defaultSshSize; void setDeviceIndex(uint32_t deviceIndex) { this->deviceIndex = deviceIndex; } + AllocationsList &getTemporaryAllocations() { return temporaryAllocations; } + AllocationsList &getAllocationsForReuse() { return allocationsForReuse; } protected: void setDisableL3Cache(bool val) { @@ -211,6 +214,9 @@ class CommandStreamReceiver { std::unique_ptr kmdNotifyHelper; ExecutionEnvironment &executionEnvironment; uint32_t deviceIndex = 0u; + + AllocationsList temporaryAllocations; + AllocationsList allocationsForReuse; }; typedef CommandStreamReceiver *(*CommandStreamReceiverCreateFunc)(const HardwareInfo &hwInfoIn, bool withAubDump, ExecutionEnvironment &executionEnvironment); diff --git a/runtime/command_stream/experimental_command_buffer.cpp b/runtime/command_stream/experimental_command_buffer.cpp index 3aeeae466d..8ec39fa367 100644 --- a/runtime/command_stream/experimental_command_buffer.cpp +++ b/runtime/command_stream/experimental_command_buffer.cpp @@ -36,13 +36,13 @@ ExperimentalCommandBuffer::~ExperimentalCommandBuffer() { printDebugString(defaultPrint, stdout, "#%u: delta %llu start %llu stop %llu\n", i, delta, start, stop); timestamp += 2; } - MemoryManager *memManager = commandStreamReceiver->getMemoryManager(); - if (memManager) { - memManager->freeGraphicsMemory(timestamps); - memManager->freeGraphicsMemory(experimentalAllocation); + MemoryManager *memoryManager = commandStreamReceiver->getMemoryManager(); + if (memoryManager) { + memoryManager->freeGraphicsMemory(timestamps); + memoryManager->freeGraphicsMemory(experimentalAllocation); if (currentStream.get()) { - memManager->storeAllocation(std::unique_ptr(currentStream->getGraphicsAllocation()), REUSABLE_ALLOCATION); + memoryManager->freeGraphicsMemory(currentStream->getGraphicsAllocation()); currentStream->replaceGraphicsAllocation(nullptr); } } @@ -54,21 +54,21 @@ void ExperimentalCommandBuffer::getCS(size_t minRequiredSize) { } minRequiredSize += CSRequirements::minCommandQueueCommandStreamSize; if (currentStream->getAvailableSpace() < minRequiredSize) { - MemoryManager *memManager = commandStreamReceiver->getMemoryManager(); + MemoryManager *memoryManager = commandStreamReceiver->getMemoryManager(); // If not, allocate a new block. allocate full pages minRequiredSize = alignUp(minRequiredSize, MemoryConstants::pageSize); auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize; - GraphicsAllocation *allocation = memManager->obtainReusableAllocation(requiredSize, false).release(); + GraphicsAllocation *allocation = memoryManager->obtainReusableAllocation(requiredSize, false).release(); if (!allocation) { - allocation = memManager->allocateGraphicsMemory(requiredSize); + allocation = memoryManager->allocateGraphicsMemory(requiredSize); } allocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); // Deallocate the old block, if not null auto oldAllocation = currentStream->getGraphicsAllocation(); if (oldAllocation) { - memManager->storeAllocation(std::unique_ptr(oldAllocation), REUSABLE_ALLOCATION); + memoryManager->storeAllocation(std::unique_ptr(oldAllocation), REUSABLE_ALLOCATION); } currentStream->replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - CSRequirements::minCommandQueueCommandStreamSize); currentStream->replaceGraphicsAllocation(allocation); diff --git a/runtime/memory_manager/CMakeLists.txt b/runtime/memory_manager/CMakeLists.txt index 29fafcad78..62d44e4b79 100644 --- a/runtime/memory_manager/CMakeLists.txt +++ b/runtime/memory_manager/CMakeLists.txt @@ -8,6 +8,7 @@ set(RUNTIME_SRCS_MEMORY_MANAGER ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/address_mapper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/address_mapper.h + ${CMAKE_CURRENT_SOURCE_DIR}/allocations_list.h ${CMAKE_CURRENT_SOURCE_DIR}/deferrable_deletion.h ${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/deferred_deleter.h diff --git a/runtime/memory_manager/allocations_list.h b/runtime/memory_manager/allocations_list.h new file mode 100644 index 0000000000..89485a607d --- /dev/null +++ b/runtime/memory_manager/allocations_list.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "runtime/utilities/idlist.h" +#include + +namespace OCLRT { +class GraphicsAllocation; + +class AllocationsList : public IDList { + public: + std::unique_ptr detachAllocation(size_t requiredMinimalSize, volatile uint32_t *csrTagAddress, bool internalAllocationRequired); + + private: + GraphicsAllocation *detachAllocationImpl(GraphicsAllocation *, void *); +}; +} // namespace OCLRT diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 78fc94c71b..78ce4edbf3 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -64,8 +64,6 @@ MemoryManager::MemoryManager(bool enable64kbpages, bool enableLocalMemory, executionEnvironment(executionEnvironment){}; MemoryManager::~MemoryManager() { - freeAllocationsList(-1, graphicsAllocations); - freeAllocationsList(-1, allocationsForReuse); for (auto osContext : registeredOsContexts) { osContext->decRefInternal(); } @@ -192,15 +190,15 @@ void MemoryManager::storeAllocation(std::unique_ptr gfxAlloc return; } } - - auto &allocationsList = (allocationUsage == TEMPORARY_ALLOCATION) ? graphicsAllocations : allocationsForReuse; + auto csr = getCommandStreamReceiver(0); + auto &allocationsList = (allocationUsage == TEMPORARY_ALLOCATION) ? csr->getTemporaryAllocations() : csr->getAllocationsForReuse(); gfxAllocation->taskCount = taskCount; allocationsList.pushTailOne(*gfxAllocation.release()); } std::unique_ptr MemoryManager::obtainReusableAllocation(size_t requiredSize, bool internalAllocation) { std::lock_guard lock(mtx); - auto allocation = allocationsForReuse.detachAllocation(requiredSize, getCommandStreamReceiver(0)->getTagAddress(), internalAllocation); + auto allocation = getCommandStreamReceiver(0)->getAllocationsForReuse().detachAllocation(requiredSize, getCommandStreamReceiver(0)->getTagAddress(), internalAllocation); return allocation; } @@ -225,14 +223,12 @@ void MemoryManager::applyCommonCleanup() { if (timestampPacketAllocator) { timestampPacketAllocator->cleanUpResources(); } - - cleanAllocationList(-1, TEMPORARY_ALLOCATION); - cleanAllocationList(-1, REUSABLE_ALLOCATION); } bool MemoryManager::cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage) { std::lock_guard lock(mtx); - freeAllocationsList(waitTaskCount, (allocationUsage == TEMPORARY_ALLOCATION) ? graphicsAllocations : allocationsForReuse); + auto csr = getCommandStreamReceiver(0); + freeAllocationsList(waitTaskCount, (allocationUsage == TEMPORARY_ALLOCATION) ? csr->getTemporaryAllocations() : csr->getAllocationsForReuse()); return false; } diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 4bde18c214..512a30b821 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -17,6 +17,7 @@ #include namespace OCLRT { +class AllocationsList; class Device; class DeferredDeleter; class ExecutionEnvironment; @@ -103,14 +104,6 @@ struct AlignedMallocRestrictions { constexpr size_t paddingBufferSize = 2 * MemoryConstants::megaByte; -class AllocationsList : public IDList { - public: - std::unique_ptr detachAllocation(size_t requiredMinimalSize, volatile uint32_t *csrTagAddress, bool internalAllocationRequired); - - private: - GraphicsAllocation *detachAllocationImpl(GraphicsAllocation *, void *); -}; - class Gmm; struct ImageInfo; @@ -223,11 +216,6 @@ class MemoryManager { MOCKABLE_VIRTUAL std::unique_ptr obtainReusableAllocation(size_t requiredSize, bool isInternalAllocationRequired); - //intrusive list of allocation - AllocationsList graphicsAllocations; - - //intrusive list of allocation for re-use - AllocationsList allocationsForReuse; HostPtrManager hostPtrManager; virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) = 0; diff --git a/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp index 108489689c..6736aefab8 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp @@ -73,7 +73,7 @@ HWTEST_P(AUBReadBuffer, simple) { EXPECT_EQ(CL_SUCCESS, retVal); - allocation = pCommandStreamReceiver->getMemoryManager()->graphicsAllocations.peekHead(); + allocation = pCommandStreamReceiver->getTemporaryAllocations().peekHead(); while (allocation && allocation->getUnderlyingBuffer() != pDestMemory) { allocation = allocation->next; } diff --git a/unit_tests/aub_tests/command_queue/enqueue_write_copy_read_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_write_copy_read_buffer_aub_tests.cpp index 71b76dfe6a..967b4a300d 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_write_copy_read_buffer_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_write_copy_read_buffer_aub_tests.cpp @@ -113,7 +113,7 @@ void AubWriteCopyReadBuffer::runTest() { pCmdQ->flush(); - GraphicsAllocation *allocation = csr->getMemoryManager()->graphicsAllocations.peekHead(); + GraphicsAllocation *allocation = csr->getTemporaryAllocations().peekHead(); while (allocation && allocation->getUnderlyingBuffer() != hostPtrMemory) { allocation = allocation->next; } diff --git a/unit_tests/command_queue/command_queue_tests.cpp b/unit_tests/command_queue/command_queue_tests.cpp index 5e077705ee..6f91b2f7fd 100644 --- a/unit_tests/command_queue/command_queue_tests.cpp +++ b/unit_tests/command_queue/command_queue_tests.cpp @@ -329,26 +329,26 @@ TEST_F(CommandQueueCommandStreamTest, MemoryManagerWithReusableAllocationsWhenAs auto allocation = memoryManager->allocateGraphicsMemory(requiredSize); memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation)); + EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekContains(*allocation)); const auto &indirectHeap = cmdQ.getCS(100); EXPECT_EQ(indirectHeap.getGraphicsAllocation(), allocation); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); } TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenItIsDestroyedThenCommandStreamIsPutOnTheReusabeList) { auto cmdQ = new CommandQueue(context.get(), pDevice, 0); auto memoryManager = pDevice->getMemoryManager(); const auto &commandStream = cmdQ->getCS(100); auto graphicsAllocation = commandStream.getGraphicsAllocation(); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); //now destroy command queue, heap should go to reusable list delete cmdQ; - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*graphicsAllocation)); + EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekContains(*graphicsAllocation)); } TEST_F(CommandQueueCommandStreamTest, CommandQueueWhenAskedForNewCommandStreamStoresOldHeapForReuse) { @@ -357,19 +357,19 @@ TEST_F(CommandQueueCommandStreamTest, CommandQueueWhenAskedForNewCommandStreamSt auto memoryManager = pDevice->getMemoryManager(); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); const auto &indirectHeap = cmdQ.getCS(100); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); auto graphicsAllocation = indirectHeap.getGraphicsAllocation(); cmdQ.getCS(10000); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*graphicsAllocation)); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekContains(*graphicsAllocation)); } TEST_F(CommandQueueCommandStreamTest, givenCommandQueueWhenGetCSIsCalledThenCommandStreamAllocationTypeShouldBeSetToLinearStream) { @@ -495,8 +495,8 @@ TEST_P(CommandQueueIndirectHeapTest, MemoryManagerWithReusableAllocationsWhenAsk memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation)); + EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekContains(*allocation)); const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100); @@ -511,7 +511,7 @@ TEST_P(CommandQueueIndirectHeapTest, MemoryManagerWithReusableAllocationsWhenAsk EXPECT_EQ(allocationSize, indirectHeap.getMaxAvailableSpace()); } - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); } TEST_P(CommandQueueIndirectHeapTest, CommandQueueWhenAskedForNewHeapStoresOldHeapForReuse) { @@ -519,7 +519,7 @@ TEST_P(CommandQueueIndirectHeapTest, CommandQueueWhenAskedForNewHeapStoresOldHea CommandQueue cmdQ(context.get(), pDevice, props); auto memoryManager = pDevice->getMemoryManager(); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100); auto heapSize = indirectHeap.getAvailableSpace(); @@ -529,9 +529,9 @@ TEST_P(CommandQueueIndirectHeapTest, CommandQueueWhenAskedForNewHeapStoresOldHea // Request a larger heap than the first. cmdQ.getIndirectHeap(this->GetParam(), heapSize + 6000); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*graphicsAllocation)); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekContains(*graphicsAllocation)); } TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocationWhenAskedForNewHeapReturnsAcquiresNewAllocationWithoutStoring) { @@ -540,7 +540,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithoutHeapAllocationWhenA auto memoryManager = pDevice->getMemoryManager(); auto &csr = pDevice->getUltCommandStreamReceiver(); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100); auto heapSize = indirectHeap.getAvailableSpace(); @@ -561,11 +561,11 @@ TEST_P(CommandQueueIndirectHeapTest, givenCommandQueueWithResourceCachingActiveW auto cmdQ = new CommandQueue(context.get(), pDevice, 0); auto memoryManager = pDevice->getMemoryManager(); cmdQ->getIndirectHeap(this->GetParam(), 100); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); //now destroy command queue, heap should go to reusable list delete cmdQ; - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); } TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndirectHeapIsReleasedThenHeapAllocationAndHeapBufferIsSetToNullptr) { @@ -573,7 +573,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapAllocatedWhenIndir MockCommandQueue cmdQ(context.get(), pDevice, props); auto memoryManager = pDevice->getMemoryManager(); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); const auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), 100); auto heapSize = indirectHeap.getMaxAvailableSpace(); @@ -617,7 +617,7 @@ TEST_P(CommandQueueIndirectHeapTest, GivenCommandQueueWithHeapWhenGraphicAllocat cmdQ.releaseIndirectHeap(this->GetParam()); auto memoryManager = pDevice->getMemoryManager(); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getAllocationsForReuse().peekIsEmpty()); memoryManager->freeGraphicsMemory(allocation); } diff --git a/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp b/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp index ce24759a36..a7006f983f 100644 --- a/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp +++ b/unit_tests/command_queue/enqueue_fill_buffer_tests.cpp @@ -365,11 +365,11 @@ HWTEST_F(EnqueueFillBufferCmdTests, argumentTwoShouldMatchPatternPtr) { } HWTEST_F(EnqueueFillBufferCmdTests, patternShouldBeCopied) { - MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); - ASSERT_TRUE(mmgr->graphicsAllocations.peekIsEmpty()); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); + ASSERT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); EnqueueFillBufferHelper<>::enqueueFillBuffer(pCmdQ, buffer); - ASSERT_FALSE(mmgr->graphicsAllocations.peekIsEmpty()); - GraphicsAllocation *allocation = mmgr->graphicsAllocations.peekHead(); + ASSERT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); + GraphicsAllocation *allocation = csr.getTemporaryAllocations().peekHead(); while (allocation != nullptr) { if ((allocation->getUnderlyingBufferSize() >= sizeof(float)) && @@ -386,11 +386,11 @@ HWTEST_F(EnqueueFillBufferCmdTests, patternShouldBeCopied) { } HWTEST_F(EnqueueFillBufferCmdTests, patternShouldBeAligned) { - MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); - ASSERT_TRUE(mmgr->graphicsAllocations.peekIsEmpty()); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); + ASSERT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); EnqueueFillBufferHelper<>::enqueueFillBuffer(pCmdQ, buffer); - ASSERT_FALSE(mmgr->graphicsAllocations.peekIsEmpty()); - GraphicsAllocation *allocation = mmgr->graphicsAllocations.peekHead(); + ASSERT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); + GraphicsAllocation *allocation = csr.getTemporaryAllocations().peekHead(); while (allocation != nullptr) { if ((allocation->getUnderlyingBufferSize() >= sizeof(float)) && @@ -408,9 +408,9 @@ HWTEST_F(EnqueueFillBufferCmdTests, patternShouldBeAligned) { } HWTEST_F(EnqueueFillBufferCmdTests, patternOfSizeOneByteShouldGetPreparedForMiddleKernel) { - MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); - ASSERT_TRUE(mmgr->allocationsForReuse.peekIsEmpty()); - ASSERT_TRUE(mmgr->graphicsAllocations.peekIsEmpty()); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); + ASSERT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); + ASSERT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); auto dstBuffer = std::unique_ptr(BufferHelper<>::create()); const uint8_t pattern[1] = {0x55}; @@ -431,19 +431,19 @@ HWTEST_F(EnqueueFillBufferCmdTests, patternOfSizeOneByteShouldGetPreparedForMidd nullptr); ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_TRUE(mmgr->allocationsForReuse.peekIsEmpty()); - ASSERT_FALSE(mmgr->graphicsAllocations.peekIsEmpty()); + ASSERT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); + ASSERT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); - GraphicsAllocation *allocation = mmgr->graphicsAllocations.peekHead(); + GraphicsAllocation *allocation = csr.getTemporaryAllocations().peekHead(); ASSERT_NE(nullptr, allocation); EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), output, size)); } HWTEST_F(EnqueueFillBufferCmdTests, patternOfSizeTwoBytesShouldGetPreparedForMiddleKernel) { - MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); - ASSERT_TRUE(mmgr->allocationsForReuse.peekIsEmpty()); - ASSERT_TRUE(mmgr->graphicsAllocations.peekIsEmpty()); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); + ASSERT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); + ASSERT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); auto dstBuffer = std::unique_ptr(BufferHelper<>::create()); const uint8_t pattern[2] = {0x55, 0xAA}; @@ -464,18 +464,18 @@ HWTEST_F(EnqueueFillBufferCmdTests, patternOfSizeTwoBytesShouldGetPreparedForMid nullptr); ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_TRUE(mmgr->allocationsForReuse.peekIsEmpty()); - ASSERT_FALSE(mmgr->graphicsAllocations.peekIsEmpty()); + ASSERT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); + ASSERT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); - GraphicsAllocation *allocation = mmgr->graphicsAllocations.peekHead(); + GraphicsAllocation *allocation = csr.getTemporaryAllocations().peekHead(); ASSERT_NE(nullptr, allocation); EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), output, size)); } HWTEST_F(EnqueueFillBufferCmdTests, givenEnqueueFillBufferWhenPatternAllocationIsObtainedThenItsTypeShouldBeSetToFillPattern) { - MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); - ASSERT_TRUE(mmgr->graphicsAllocations.peekIsEmpty()); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); + ASSERT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); auto dstBuffer = std::unique_ptr(BufferHelper<>::create()); const uint8_t pattern[1] = {0x55}; @@ -495,9 +495,9 @@ HWTEST_F(EnqueueFillBufferCmdTests, givenEnqueueFillBufferWhenPatternAllocationI nullptr); ASSERT_EQ(CL_SUCCESS, retVal); - ASSERT_FALSE(mmgr->graphicsAllocations.peekIsEmpty()); + ASSERT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); - GraphicsAllocation *patternAllocation = mmgr->graphicsAllocations.peekHead(); + GraphicsAllocation *patternAllocation = csr.getTemporaryAllocations().peekHead(); ASSERT_NE(nullptr, patternAllocation); EXPECT_EQ(GraphicsAllocation::AllocationType::FILL_PATTERN, patternAllocation->getAllocationType()); diff --git a/unit_tests/command_queue/enqueue_kernel_tests.cpp b/unit_tests/command_queue/enqueue_kernel_tests.cpp index 1f2089533f..96f3742f14 100644 --- a/unit_tests/command_queue/enqueue_kernel_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_tests.cpp @@ -497,7 +497,7 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueScratchSpaceTests, GivenKernelRequiringScratc csr.getMemoryManager()->setForce32BitAllocations(false); - EXPECT_TRUE(csr.getMemoryManager()->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); SPatchMediaVFEState mediaVFEstate; auto scratchSize = GetParam().ScratchSize; @@ -621,7 +621,7 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueScratchSpaceTests, GivenKernelRequiringScratc EXPECT_EQ((uintptr_t)graphicsAllocation2->getUnderlyingBuffer(), GSBaddress + PreambleHelper::getScratchSpaceOffsetFor64bit()); } - EXPECT_TRUE(csr.getMemoryManager()->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); } INSTANTIATE_TEST_CASE_P(EnqueueKernel, diff --git a/unit_tests/command_queue/enqueue_read_image_tests.cpp b/unit_tests/command_queue/enqueue_read_image_tests.cpp index 80d13f8159..2c59217197 100644 --- a/unit_tests/command_queue/enqueue_read_image_tests.cpp +++ b/unit_tests/command_queue/enqueue_read_image_tests.cpp @@ -226,9 +226,9 @@ HWTEST_F(EnqueueReadImageTest, GivenImage1DarrayWhenReadImageIsCalledThenHostPtr EnqueueReadImageHelper<>::enqueueReadImage(pCmdQ, srcImage, CL_FALSE, origin, region); - auto memoryManager = pCmdQ->getDevice().getMemoryManager(); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); - auto temporaryAllocation = memoryManager->graphicsAllocations.peekHead(); + auto temporaryAllocation = csr.getTemporaryAllocations().peekHead(); ASSERT_NE(nullptr, temporaryAllocation); EXPECT_EQ(temporaryAllocation->getUnderlyingBufferSize(), imageSize); @@ -245,9 +245,9 @@ HWTEST_F(EnqueueReadImageTest, GivenImage2DarrayWhenReadImageIsCalledThenHostPtr EnqueueReadImageHelper<>::enqueueReadImage(pCmdQ, srcImage, CL_FALSE, origin, region); - auto memoryManager = pCmdQ->getDevice().getMemoryManager(); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); - auto temporaryAllocation = memoryManager->graphicsAllocations.peekHead(); + auto temporaryAllocation = csr.getTemporaryAllocations().peekHead(); ASSERT_NE(nullptr, temporaryAllocation); EXPECT_EQ(temporaryAllocation->getUnderlyingBufferSize(), imageSize); diff --git a/unit_tests/command_queue/enqueue_svm_tests.cpp b/unit_tests/command_queue/enqueue_svm_tests.cpp index e2ca8803c5..57e3f82b49 100644 --- a/unit_tests/command_queue/enqueue_svm_tests.cpp +++ b/unit_tests/command_queue/enqueue_svm_tests.cpp @@ -424,8 +424,8 @@ TEST_F(EnqueueSvmTest, enqueueSVMMemFillDoubleToReuseAllocation_Success) { } TEST_F(EnqueueSvmTest, givenEnqueueSVMMemFillWhenPatternAllocationIsObtainedThenItsTypeShouldBeSetToFillPattern) { - MemoryManager *mmgr = pCmdQ->getDevice().getMemoryManager(); - ASSERT_TRUE(mmgr->allocationsForReuse.peekIsEmpty()); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); + ASSERT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); const float pattern[1] = {1.2345f}; const size_t patternSize = sizeof(pattern); @@ -440,9 +440,9 @@ TEST_F(EnqueueSvmTest, givenEnqueueSVMMemFillWhenPatternAllocationIsObtainedThen nullptr); EXPECT_EQ(CL_SUCCESS, retVal); - ASSERT_FALSE(mmgr->allocationsForReuse.peekIsEmpty()); + ASSERT_FALSE(csr.getAllocationsForReuse().peekIsEmpty()); - GraphicsAllocation *patternAllocation = mmgr->allocationsForReuse.peekHead(); + GraphicsAllocation *patternAllocation = csr.getAllocationsForReuse().peekHead(); ASSERT_NE(nullptr, patternAllocation); EXPECT_EQ(GraphicsAllocation::AllocationType::FILL_PATTERN, patternAllocation->getAllocationType()); diff --git a/unit_tests/command_queue/enqueue_write_image_tests.cpp b/unit_tests/command_queue/enqueue_write_image_tests.cpp index 4aad846c1b..aad6c8d664 100644 --- a/unit_tests/command_queue/enqueue_write_image_tests.cpp +++ b/unit_tests/command_queue/enqueue_write_image_tests.cpp @@ -199,9 +199,9 @@ HWTEST_F(EnqueueWriteImageTest, GivenImage1DarrayWhenReadWriteImageIsCalledThenH EnqueueWriteImageHelper<>::enqueueWriteImage(pCmdQ, dstImage2, CL_FALSE, origin, region); - auto memoryManager = pCmdQ->getDevice().getMemoryManager(); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); - auto temporaryAllocation1 = memoryManager->graphicsAllocations.peekHead(); + auto temporaryAllocation1 = csr.getTemporaryAllocations().peekHead(); ASSERT_NE(nullptr, temporaryAllocation1); EXPECT_EQ(temporaryAllocation1->getUnderlyingBufferSize(), imageSize); @@ -223,9 +223,9 @@ HWTEST_F(EnqueueWriteImageTest, GivenImage2DarrayWhenReadWriteImageIsCalledThenH EnqueueWriteImageHelper<>::enqueueWriteImage(pCmdQ, dstImage2, CL_FALSE, origin, region); - auto memoryManager = pCmdQ->getDevice().getMemoryManager(); + auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); - auto temporaryAllocation1 = memoryManager->graphicsAllocations.peekHead(); + auto temporaryAllocation1 = csr.getTemporaryAllocations().peekHead(); ASSERT_NE(nullptr, temporaryAllocation1); EXPECT_EQ(temporaryAllocation1->getUnderlyingBufferSize(), imageSize); diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp index 9324eb2e9e..53fe5e76a2 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp @@ -1697,7 +1697,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, InForced32BitAllocationsModeStore3 auto newScratchAllocation = commandStreamReceiver->getScratchAllocation(); EXPECT_NE(scratchAllocation, newScratchAllocation); // Allocation changed - std::unique_ptr allocationTemporary = pDevice->getMemoryManager()->graphicsAllocations.detachAllocation(0, nullptr, true); + std::unique_ptr allocationTemporary = commandStreamReceiver->getTemporaryAllocations().detachAllocation(0, nullptr, true); EXPECT_EQ(scratchAllocation, allocationTemporary.get()); pDevice->getMemoryManager()->freeGraphicsMemory(allocationTemporary.release()); @@ -3135,16 +3135,16 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrWhenTemporaryAndReusableAl commandStreamReceiver.latestFlushedTaskCount = 9; commandStreamReceiver.cleanupResources(); - EXPECT_EQ(reusableToHold, memoryManager->allocationsForReuse.peekHead()); - EXPECT_EQ(reusableToHold, memoryManager->allocationsForReuse.peekTail()); + EXPECT_EQ(reusableToHold, commandStreamReceiver.getAllocationsForReuse().peekHead()); + EXPECT_EQ(reusableToHold, commandStreamReceiver.getAllocationsForReuse().peekTail()); - EXPECT_EQ(temporaryToHold, memoryManager->graphicsAllocations.peekHead()); - EXPECT_EQ(temporaryToHold, memoryManager->graphicsAllocations.peekTail()); + EXPECT_EQ(temporaryToHold, commandStreamReceiver.getTemporaryAllocations().peekHead()); + EXPECT_EQ(temporaryToHold, commandStreamReceiver.getTemporaryAllocations().peekTail()); commandStreamReceiver.latestFlushedTaskCount = 11; commandStreamReceiver.cleanupResources(); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(commandStreamReceiver.getAllocationsForReuse().peekIsEmpty()); + EXPECT_TRUE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty()); } HWTEST_F(CommandStreamReceiverFlushTaskTests, givenDispatchFlagsWithThrottleSetToLowWhenFlushTaskIsCalledThenThrottleIsSetInBatchBuffer) { diff --git a/unit_tests/event/user_events_tests.cpp b/unit_tests/event/user_events_tests.cpp index 83cc152f1a..bacc6da1ae 100644 --- a/unit_tests/event/user_events_tests.cpp +++ b/unit_tests/event/user_events_tests.cpp @@ -892,15 +892,14 @@ TEST_F(EventTests, enqueueReadImageBlockedOnUserEvent) { TEST_F(EventTests, waitForEventsDestroysTemporaryAllocations) { auto &csr = pCmdQ->getDevice().getCommandStreamReceiver(); - MemoryManager *memoryManager = csr.getMemoryManager(); //kill some temporary objects that fixture creates. csr.waitForTaskCountAndCleanAllocationList(-1, TEMPORARY_ALLOCATION); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); GraphicsAllocation *temporaryAllocation = csr.createAllocationAndHandleResidency((void *)0x1234, 200); - EXPECT_EQ(temporaryAllocation, memoryManager->graphicsAllocations.peekHead()); + EXPECT_EQ(temporaryAllocation, csr.getTemporaryAllocations().peekHead()); temporaryAllocation->taskCount = 10; @@ -910,7 +909,7 @@ TEST_F(EventTests, waitForEventsDestroysTemporaryAllocations) { event.waitForEvents(1, eventWaitList); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); } TEST_F(EventTest, UserEvent_Wait_NonBlocking) { diff --git a/unit_tests/fixtures/memory_allocator_fixture.h b/unit_tests/fixtures/memory_allocator_fixture.h index 86f8a32ad1..05e4bba74e 100644 --- a/unit_tests/fixtures/memory_allocator_fixture.h +++ b/unit_tests/fixtures/memory_allocator_fixture.h @@ -22,6 +22,8 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { executionEnvironment->initializeCommandStreamReceiver(*platformDevices, 0u); memoryManager = new OsAgnosticMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); + csr = memoryManager->getCommandStreamReceiver(0); + csr->setMemoryManager(memoryManager); } void TearDown() override { @@ -32,4 +34,5 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { protected: std::unique_ptr executionEnvironment; MemoryManager *memoryManager; + CommandStreamReceiver *csr; }; diff --git a/unit_tests/fixtures/memory_manager_fixture.cpp b/unit_tests/fixtures/memory_manager_fixture.cpp index d51eb27c95..a75e97372a 100644 --- a/unit_tests/fixtures/memory_manager_fixture.cpp +++ b/unit_tests/fixtures/memory_manager_fixture.cpp @@ -16,6 +16,8 @@ void MemoryManagerWithCsrFixture::SetUp() { csr = new MockCommandStreamReceiver(this->executionEnvironment); gmockMemoryManager = new NiceMock(executionEnvironment); memoryManager = gmockMemoryManager; + csr->setMemoryManager(memoryManager); + executionEnvironment.memoryManager.reset(memoryManager); ON_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerCleanAllocationList)); ON_CALL(*gmockMemoryManager, populateOsHandles(::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerPopulateOsHandles)); @@ -25,5 +27,4 @@ void MemoryManagerWithCsrFixture::SetUp() { } void MemoryManagerWithCsrFixture::TearDown() { - delete memoryManager; } diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index 6f19c5e366..d100ca9057 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -522,18 +522,18 @@ TEST_F(KernelPrivateSurfaceTest, givenKernelWithPrivateSurfaceThatIsInUseByGpuWh std::unique_ptr pKernel(new MockKernel(&program, *pKernelInfo, *pDevice)); pKernel->initialize(); - auto memoryManager = pDevice->getMemoryManager(); + auto &csr = pDevice->getCommandStreamReceiver(); auto privateSurface = pKernel->getPrivateSurface(); auto tagAddress = context.getDevice(0)->getTagAddress(); privateSurface->taskCount = *tagAddress + 1; - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); pKernel.reset(nullptr); - EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); - EXPECT_EQ(memoryManager->graphicsAllocations.peekHead(), privateSurface); + EXPECT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); + EXPECT_EQ(csr.getTemporaryAllocations().peekHead(), privateSurface); } TEST_F(KernelPrivateSurfaceTest, testPrivateSurfaceAllocationFailure) { diff --git a/unit_tests/kernel/substitute_kernel_heap_tests.cpp b/unit_tests/kernel/substitute_kernel_heap_tests.cpp index c0c50d5010..8201f79494 100644 --- a/unit_tests/kernel/substitute_kernel_heap_tests.cpp +++ b/unit_tests/kernel/substitute_kernel_heap_tests.cpp @@ -120,13 +120,13 @@ TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKe const size_t newHeapSize = initialHeapSize + 1; char newHeap[newHeapSize]; - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty()); kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize); auto secondAllocation = kernel.kernelInfo.kernelAllocation; - EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); - EXPECT_EQ(memoryManager->graphicsAllocations.peekHead(), firstAllocation); + EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty()); + EXPECT_EQ(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekHead(), firstAllocation); memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation); memoryManager->cleanAllocationList(firstAllocation->taskCount, TEMPORARY_ALLOCATION); } diff --git a/unit_tests/libult/ult_command_stream_receiver.h b/unit_tests/libult/ult_command_stream_receiver.h index 0c7457ac62..4d681998c3 100644 --- a/unit_tests/libult/ult_command_stream_receiver.h +++ b/unit_tests/libult/ult_command_stream_receiver.h @@ -51,6 +51,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { using BaseClass::CommandStreamReceiver::taskCount; using BaseClass::CommandStreamReceiver::taskLevel; using BaseClass::CommandStreamReceiver::timestampPacketWriteEnabled; + using BaseClass::CommandStreamReceiver::waitForTaskCountAndCleanAllocationList; UltCommandStreamReceiver(const UltCommandStreamReceiver &) = delete; UltCommandStreamReceiver &operator=(const UltCommandStreamReceiver &) = delete; @@ -139,7 +140,6 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { using BaseClass::CommandStreamReceiver::memoryManager; using BaseClass::CommandStreamReceiver::tagAddress; using BaseClass::CommandStreamReceiver::tagAllocation; - using BaseClass::CommandStreamReceiver::waitForTaskCountAndCleanAllocationList; GraphicsAllocation *tempPreemptionLocation = nullptr; }; diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 99d7c1a0fa..969e382b51 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -233,7 +233,31 @@ TEST_F(MemoryAllocatorTest, storeTemporaryAllocation) { auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr); allocation->taskCount = 1; memoryManager->storeAllocation(std::unique_ptr(allocation), TEMPORARY_ALLOCATION); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty() == false); + EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty() == false); +} + +TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenStoreOrCleanTempoaryAllocationsThenUseFirstCommandStreamReceiver) { + void *host_ptr = (void *)0x1234; + auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr); + allocation->taskCount = 1; + auto csr = memoryManager->getCommandStreamReceiver(0); + EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty()); + memoryManager->storeAllocation(std::unique_ptr(allocation), TEMPORARY_ALLOCATION); + EXPECT_FALSE(csr->getTemporaryAllocations().peekIsEmpty()); + memoryManager->cleanAllocationList(1, TEMPORARY_ALLOCATION); + EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty()); +} + +TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenStoreOrCleanReusableAllocationsThenUseFirstCommandStreamReceiver) { + void *host_ptr = (void *)0x1234; + auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr); + allocation->taskCount = 1; + auto csr = memoryManager->getCommandStreamReceiver(0); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); + memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); + EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty()); + memoryManager->cleanAllocationList(1, REUSABLE_ALLOCATION); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); } TEST_F(MemoryAllocatorTest, selectiveDestroy) { @@ -251,11 +275,11 @@ TEST_F(MemoryAllocatorTest, selectiveDestroy) { //check the same task count first, nothign should be killed memoryManager->cleanAllocationList(11, TEMPORARY_ALLOCATION); - EXPECT_EQ(allocation2, memoryManager->graphicsAllocations.peekHead()); + EXPECT_EQ(allocation2, csr->getTemporaryAllocations().peekHead()); memoryManager->cleanAllocationList(16, TEMPORARY_ALLOCATION); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty()); } TEST_F(MemoryAllocatorTest, intrusiveListsInjectionsAndRemoval) { @@ -276,27 +300,27 @@ TEST_F(MemoryAllocatorTest, intrusiveListsInjectionsAndRemoval) { memoryManager->storeAllocation(std::unique_ptr(allocation3), TEMPORARY_ALLOCATION); //head point to alloc 2, tail points to alloc3 - EXPECT_TRUE(memoryManager->graphicsAllocations.peekContains(*allocation)); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekContains(*allocation2)); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekContains(*allocation3)); - EXPECT_EQ(-1, verifyDListOrder(memoryManager->graphicsAllocations.peekHead(), allocation, allocation2, allocation3)); + 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 memoryManager->cleanAllocationList(6, TEMPORARY_ALLOCATION); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekContains(*allocation)); - EXPECT_FALSE(memoryManager->graphicsAllocations.peekContains(*allocation2)); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekContains(*allocation3)); - EXPECT_EQ(-1, verifyDListOrder(memoryManager->graphicsAllocations.peekHead(), allocation, allocation3)); + 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 memoryManager->cleanAllocationList(11, TEMPORARY_ALLOCATION); - EXPECT_FALSE(memoryManager->graphicsAllocations.peekContains(*allocation)); - EXPECT_FALSE(memoryManager->graphicsAllocations.peekContains(*allocation2)); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekContains(*allocation3)); + EXPECT_FALSE(csr->getTemporaryAllocations().peekContains(*allocation)); + EXPECT_FALSE(csr->getTemporaryAllocations().peekContains(*allocation2)); + EXPECT_TRUE(csr->getTemporaryAllocations().peekContains(*allocation3)); //now remove tail memoryManager->cleanAllocationList(16, TEMPORARY_ALLOCATION); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty()); } TEST_F(MemoryAllocatorTest, addAllocationToReuseList) { @@ -305,7 +329,7 @@ TEST_F(MemoryAllocatorTest, addAllocationToReuseList) { auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr); memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_EQ(allocation, memoryManager->allocationsForReuse.peekHead()); + EXPECT_EQ(allocation, csr->getAllocationsForReuse().peekHead()); } TEST_F(MemoryAllocatorTest, givenDebugFlagThatDisablesAllocationReuseWhenApiIsCalledThenAllocationIsReleased) { @@ -315,8 +339,8 @@ TEST_F(MemoryAllocatorTest, givenDebugFlagThatDisablesAllocationReuseWhenApiIsCa auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr); memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_NE(allocation, memoryManager->allocationsForReuse.peekHead()); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_NE(allocation, csr->getAllocationsForReuse().peekHead()); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); DebugManager.flags.DisableResourceRecycling.set(false); } @@ -327,8 +351,8 @@ TEST_F(MemoryAllocatorTest, givenDebugFlagThatDisablesAllocationReuseWhenStoreIs auto allocation = memoryManager->allocateGraphicsMemory(1, host_ptr); memoryManager->storeAllocation(std::unique_ptr(allocation), TEMPORARY_ALLOCATION); - EXPECT_EQ(allocation, memoryManager->graphicsAllocations.peekHead()); - EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_EQ(allocation, csr->getTemporaryAllocations().peekHead()); + EXPECT_FALSE(csr->getTemporaryAllocations().peekIsEmpty()); allocation->setGpuAddress(allocation->getGpuAddress()); DebugManager.flags.DisableResourceRecycling.set(false); @@ -354,86 +378,86 @@ TEST_F(MemoryAllocatorTest, obtainAllocationFromReusableList) { auto allocation2 = memoryManager->obtainReusableAllocation(1, false); EXPECT_EQ(allocation, allocation2.get()); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); memoryManager->freeGraphicsMemory(allocation2.release()); } TEST_F(MemoryAllocatorTest, obtainAllocationFromMidlleOfReusableList) { - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); auto allocation = memoryManager->allocateGraphicsMemory(1); auto allocation2 = memoryManager->allocateGraphicsMemory(10000); auto allocation3 = memoryManager->allocateGraphicsMemory(1); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation)); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekContains(*allocation2)); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekContains(*allocation3)); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation)); + EXPECT_FALSE(csr->getAllocationsForReuse().peekContains(*allocation2)); + EXPECT_FALSE(csr->getAllocationsForReuse().peekContains(*allocation3)); memoryManager->storeAllocation(std::unique_ptr(allocation2), REUSABLE_ALLOCATION); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation)); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation2)); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekContains(*allocation3)); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation)); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation2)); + EXPECT_FALSE(csr->getAllocationsForReuse().peekContains(*allocation3)); memoryManager->storeAllocation(std::unique_ptr(allocation3), REUSABLE_ALLOCATION); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation)); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation2)); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation3)); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation)); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation2)); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation3)); auto reusableAllocation = memoryManager->obtainReusableAllocation(10000, false); EXPECT_EQ(nullptr, reusableAllocation->next); EXPECT_EQ(nullptr, reusableAllocation->prev); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekContains(*reusableAllocation)); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation) || (allocation == reusableAllocation.get())); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation2) || (allocation2 == reusableAllocation.get())); - EXPECT_TRUE(memoryManager->allocationsForReuse.peekContains(*allocation3) || (allocation3 == reusableAllocation.get())); + EXPECT_FALSE(csr->getAllocationsForReuse().peekContains(*reusableAllocation)); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation) || (allocation == reusableAllocation.get())); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation2) || (allocation2 == reusableAllocation.get())); + EXPECT_TRUE(csr->getAllocationsForReuse().peekContains(*allocation3) || (allocation3 == reusableAllocation.get())); memoryManager->freeGraphicsMemory(reusableAllocation.release()); } TEST_F(MemoryAllocatorTest, givenNonInternalAllocationWhenItIsPutOnReusableListWhenInternalAllocationIsRequestedThenNullIsReturned) { - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); auto allocation = memoryManager->allocateGraphicsMemory(4096); memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty()); auto internalAllocation = memoryManager->obtainReusableAllocation(1, true); EXPECT_EQ(nullptr, internalAllocation); } TEST_F(MemoryAllocatorTest, givenInternalAllocationWhenItIsPutOnReusableListWhenNonInternalAllocationIsRequestedThenNullIsReturned) { - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); auto allocation = memoryManager->allocateGraphicsMemory(4096); allocation->is32BitAllocation = true; memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty()); auto internalAllocation = memoryManager->obtainReusableAllocation(1, false); EXPECT_EQ(nullptr, internalAllocation); } TEST_F(MemoryAllocatorTest, givenInternalAllocationWhenItIsPutOnReusableListWhenInternalAllocationIsRequestedThenItIsReturned) { - EXPECT_TRUE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_TRUE(csr->getAllocationsForReuse().peekIsEmpty()); auto allocation = memoryManager->allocateGraphicsMemory(4096); allocation->is32BitAllocation = true; memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); - EXPECT_FALSE(memoryManager->allocationsForReuse.peekIsEmpty()); + EXPECT_FALSE(csr->getAllocationsForReuse().peekIsEmpty()); auto internalAllocation = memoryManager->obtainReusableAllocation(1, true); EXPECT_EQ(allocation, internalAllocation.get()); @@ -1627,31 +1651,31 @@ TEST_F(MemoryManagerWithCsrTest, checkAllocationsForOverlappingWithBiggerOverlap TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasNotUsedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsDestroyedInPlace) { auto notUsedAllocation = memoryManager->allocateGraphicsMemory(4096); memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(notUsedAllocation); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty()); } TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsDestroyedInPlace) { auto usedAllocationButGpuCompleted = memoryManager->allocateGraphicsMemory(4096); - auto tagAddress = memoryManager->getCommandStreamReceiver(0)->getTagAddress(); + auto tagAddress = csr->getTagAddress(); ASSERT_NE(0u, *tagAddress); usedAllocationButGpuCompleted->taskCount = *tagAddress - 1; memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(usedAllocationButGpuCompleted); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr->getTemporaryAllocations().peekIsEmpty()); } TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsAddedToTemporaryAllocationList) { auto usedAllocationAndNotGpuCompleted = memoryManager->allocateGraphicsMemory(4096); - auto tagAddress = memoryManager->getCommandStreamReceiver(0)->getTagAddress(); + auto tagAddress = csr->getTagAddress(); usedAllocationAndNotGpuCompleted->taskCount = *tagAddress + 1; memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(usedAllocationAndNotGpuCompleted); - EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); - EXPECT_EQ(memoryManager->graphicsAllocations.peekHead(), usedAllocationAndNotGpuCompleted); + EXPECT_FALSE(csr->getTemporaryAllocations().peekIsEmpty()); + EXPECT_EQ(csr->getTemporaryAllocations().peekHead(), usedAllocationAndNotGpuCompleted); //change task count so cleanup will not clear alloc in use usedAllocationAndNotGpuCompleted->taskCount = ObjectNotUsed; diff --git a/unit_tests/memory_manager/surface_tests.cpp b/unit_tests/memory_manager/surface_tests.cpp index 1ea010f5bc..19822dbee8 100644 --- a/unit_tests/memory_manager/surface_tests.cpp +++ b/unit_tests/memory_manager/surface_tests.cpp @@ -58,8 +58,8 @@ HWTEST_TYPED_TEST(SurfaceTest, GivenSurfaceWhenInterfaceIsUsedThenSurfaceBehaves ExecutionEnvironment executionEnvironment; MockCsr *csr = new MockCsr(execStamp, executionEnvironment); - - auto memManager = csr->createMemoryManager(false, false); + executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr(csr)); + executionEnvironment.memoryManager.reset(csr->createMemoryManager(false, false)); Surface *surface = createSurface::Create(this->data, &this->buffer, @@ -79,8 +79,6 @@ HWTEST_TYPED_TEST(SurfaceTest, GivenSurfaceWhenInterfaceIsUsedThenSurfaceBehaves delete duplicatedSurface; delete surface; - delete csr; - delete memManager; } class CoherentMemObjSurface : public SurfaceTest { diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index 27510e2c34..b952d7b84a 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -54,7 +54,7 @@ bool MockDevice::hasDriverInfo() { return driverInfo.get() != nullptr; }; -void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) { +void MockDevice::injectMemoryManager(MemoryManager *memoryManager) { executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setMemoryManager(memoryManager); setMemoryManager(memoryManager); } diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index a04813a0e5..7c88dbc78c 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -17,7 +17,6 @@ namespace OCLRT { class OSTime; class MemoryManager; -class MockMemoryManager; extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo, ExecutionEnvironment &executionEnvironment); @@ -66,7 +65,7 @@ class MockDevice : public Device { } } - void injectMemoryManager(MockMemoryManager *); + void injectMemoryManager(MemoryManager *); void setPerfCounters(PerformanceCounters *perfCounters) { performanceCounters = std::unique_ptr(perfCounters); diff --git a/unit_tests/mocks/mock_memory_manager.cpp b/unit_tests/mocks/mock_memory_manager.cpp index b26e4ba908..655084623f 100644 --- a/unit_tests/mocks/mock_memory_manager.cpp +++ b/unit_tests/mocks/mock_memory_manager.cpp @@ -5,6 +5,7 @@ * */ +#include "runtime/command_stream/command_stream_receiver.h" #include "runtime/memory_manager/deferred_deleter.h" #include "runtime/gmm_helper/gmm.h" #include "runtime/helpers/surface_formats.h" @@ -34,11 +35,11 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(ImageInfo } bool MockMemoryManager::isAllocationListEmpty() { - return graphicsAllocations.peekIsEmpty(); + return getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty(); } GraphicsAllocation *MockMemoryManager::peekAllocationListHead() { - return graphicsAllocations.peekHead(); + return getCommandStreamReceiver(0)->getTemporaryAllocations().peekHead(); } GraphicsAllocation *MockMemoryManager::allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) { diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index e4b46821bc..c764cca5da 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -47,10 +47,9 @@ using namespace ::testing; class WddmCommandStreamFixture { public: - std::unique_ptr device; - std::unique_ptr memManager; - std::unique_ptr> csr; - MockWddmMemoryManager *mockWddmMM = nullptr; + std::unique_ptr device; + DeviceCommandStreamReceiver *csr; + MockWddmMemoryManager *memoryManager = nullptr; WddmMock *wddm = nullptr; DebugManagerStateRestore stateRestore; @@ -63,23 +62,17 @@ class WddmCommandStreamFixture { executionEnvironment->osInterface = std::make_unique(); executionEnvironment->osInterface->get()->setWddm(wddm); - csr = std::make_unique>(*platformDevices[0], *executionEnvironment); + csr = new WddmCommandStreamReceiver(*platformDevices[0], *executionEnvironment); + executionEnvironment->commandStreamReceivers.push_back(std::unique_ptr(csr)); - ASSERT_NE(nullptr, csr); + memoryManager = new MockWddmMemoryManager(wddm, *executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); - mockWddmMM = new MockWddmMemoryManager(wddm, *executionEnvironment); - memManager.reset(mockWddmMM); - memManager->registerOsContext(new OsContext(executionEnvironment->osInterface.get(), 0u)); - csr->setMemoryManager(memManager.get()); - - ASSERT_NE(nullptr, memManager); - device.reset(Device::create(platformDevices[0], executionEnvironment, 0u)); + device.reset(Device::create(platformDevices[0], executionEnvironment, 0u)); ASSERT_NE(nullptr, device); } virtual void TearDown() { - mockWddmMM = nullptr; - delete csr->getTagAddress(); } }; @@ -117,7 +110,7 @@ struct MockWddmCsr : public WddmCommandStreamReceiver { class WddmCommandStreamWithMockGdiFixture { public: MockWddmCsr *csr = nullptr; - MemoryManager *memManager = nullptr; + MemoryManager *memoryManager = nullptr; MockDevice *device = nullptr; WddmMock *wddm = nullptr; MockGdi *gdi = nullptr; @@ -137,20 +130,20 @@ class WddmCommandStreamWithMockGdiFixture { executionEnvironment->commandStreamReceivers.push_back(std::make_unique>(*platformDevices[0], *executionEnvironment)); this->csr = static_cast *>(executionEnvironment->commandStreamReceivers[0].get()); - memManager = csr->createMemoryManager(false, false); - ASSERT_NE(nullptr, memManager); - executionEnvironment->memoryManager.reset(memManager); + memoryManager = csr->createMemoryManager(false, false); + ASSERT_NE(nullptr, memoryManager); + executionEnvironment->memoryManager.reset(memoryManager); device = Device::create(platformDevices[0], executionEnvironment, 0u); ASSERT_NE(nullptr, device); this->csr->overrideRecorededCommandBuffer(*device); if (device->getPreemptionMode() == PreemptionMode::MidThread) { - preemptionAllocation = memManager->allocateGraphicsMemory(1024); + preemptionAllocation = memoryManager->allocateGraphicsMemory(1024); } } virtual void TearDown() { if (preemptionAllocation) { - memManager->freeGraphicsMemory(preemptionAllocation); + memoryManager->freeGraphicsMemory(preemptionAllocation); } wddm = nullptr; delete device; @@ -193,7 +186,7 @@ TEST_F(WddmCommandStreamTest, givenFlushStampWhenWaitCalledThenWaitForSpecifiedM } TEST_F(WddmCommandStreamTest, Flush) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -203,11 +196,11 @@ TEST_F(WddmCommandStreamTest, Flush) { EXPECT_TRUE(wddm->submitResult.success); EXPECT_EQ(flushStamp, device->getOsContext()->get()->getMonitoredFence().lastSubmittedFence); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, givenGraphicsAllocationWithDifferentGpuAddressThenCpuAddressWhenSubmitIsCalledThenGpuAddressIsUsed) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); auto cpuAddress = commandBuffer->getUnderlyingBuffer(); uint64_t mockGpuAddres = 1337; @@ -217,11 +210,11 @@ TEST_F(WddmCommandStreamTest, givenGraphicsAllocationWithDifferentGpuAddressThen BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto flushStamp = csr->flush(batchBuffer, EngineType::ENGINE_RCS, csr->getResidencyAllocations(), *device->getOsContext()); EXPECT_EQ(mockGpuAddres, wddm->submitResult.commandBufferSubmitted); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, FlushWithOffset) { auto offset = 128u; - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -231,11 +224,11 @@ TEST_F(WddmCommandStreamTest, FlushWithOffset) { EXPECT_TRUE(wddm->submitResult.success); EXPECT_EQ(wddm->submitResult.commandBufferSubmitted, commandBuffer->getGpuAddress() + offset); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledThenCoherencyRequiredFlagIsSetToFalse) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -247,7 +240,7 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledThenCoherencyRequiredFl EXPECT_FALSE(pHeader->RequiresCoherency); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOffWhenWorkloadIsSubmittedThenHeaderDoesntHavePreemptionFieldSet) { @@ -334,7 +327,7 @@ TEST(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStr } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToLowThenSetHeaderFieldsProperly) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -348,11 +341,11 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToLowThenS EXPECT_EQ(1, pHeader->UmdRequestedSubsliceCount); EXPECT_EQ(wddm->getGtSysInfo()->EUCount / wddm->getGtSysInfo()->SubSliceCount, pHeader->UmdRequestedEUCount); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToMediumThenSetHeaderFieldsProperly) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -366,11 +359,11 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToMediumTh EXPECT_EQ(0, pHeader->UmdRequestedSubsliceCount); EXPECT_EQ(wddm->getGtSysInfo()->EUCount / wddm->getGtSysInfo()->SubSliceCount, pHeader->UmdRequestedEUCount); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToHighThenSetHeaderFieldsProperly) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -384,16 +377,16 @@ TEST_F(WddmCommandStreamTest, givenWdmmWhenSubmitIsCalledAndThrottleIsToHighThen EXPECT_EQ((wddm->getGtSysInfo()->SubSliceCount <= maxRequestedSubsliceCount) ? wddm->getGtSysInfo()->SubSliceCount : 0, pHeader->UmdRequestedSubsliceCount); EXPECT_EQ(wddm->getGtSysInfo()->EUCount / wddm->getGtSysInfo()->SubSliceCount, pHeader->UmdRequestedEUCount); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafDisabledWhenFlushIsCalledWithAllocationsForResidencyThenNoneAllocationShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto linearStreamAllocation = memManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); ResidencyContainer allocationsForResidency = {linearStreamAllocation}; @@ -404,12 +397,12 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafDisabledWhenFlushIsCalledWithAll EXPECT_EQ(0u, wddm->kmDafLockResult.called); EXPECT_EQ(0u, wddm->kmDafLockResult.lockedAllocations.size()); - memManager->freeGraphicsMemory(commandBuffer); - memManager->freeGraphicsMemory(linearStreamAllocation); + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(linearStreamAllocation); } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithoutAllocationsForResidencyThenNoneAllocationShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -420,16 +413,16 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithoutA EXPECT_EQ(0u, wddm->kmDafLockResult.called); EXPECT_EQ(0u, wddm->kmDafLockResult.lockedAllocations.size()); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResidencyAllocationsInMemoryManagerThenLinearStreamAllocationsShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto linearStreamAllocation = memManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); @@ -444,17 +437,17 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResi EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); EXPECT_EQ(linearStreamAllocation, wddm->kmDafLockResult.lockedAllocations[0]); - memManager->freeGraphicsMemory(commandBuffer); - memManager->freeGraphicsMemory(linearStreamAllocation); + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(linearStreamAllocation); } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenLinearStreamAllocationsShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto linearStreamAllocation = memManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto linearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ASSERT_NE(nullptr, linearStreamAllocation); linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); ResidencyContainer allocationsForResidency = {linearStreamAllocation}; @@ -466,17 +459,17 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); EXPECT_EQ(linearStreamAllocation, wddm->kmDafLockResult.lockedAllocations[0]); - memManager->freeGraphicsMemory(commandBuffer); - memManager->freeGraphicsMemory(linearStreamAllocation); + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(linearStreamAllocation); } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenFillPatternAllocationsShouldBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto fillPatternAllocation = memManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto fillPatternAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ASSERT_NE(nullptr, fillPatternAllocation); fillPatternAllocation->setAllocationType(GraphicsAllocation::AllocationType::FILL_PATTERN); ResidencyContainer allocationsForResidency = {fillPatternAllocation}; @@ -488,17 +481,17 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size()); EXPECT_EQ(fillPatternAllocation, wddm->kmDafLockResult.lockedAllocations[0]); - memManager->freeGraphicsMemory(commandBuffer); - memManager->freeGraphicsMemory(fillPatternAllocation); + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(fillPatternAllocation); } TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllocationsForResidencyThenNonLinearStreamAllocationShouldNotBeKmDafLocked) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto nonLinearStreamAllocation = memManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + auto nonLinearStreamAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ASSERT_NE(nullptr, nonLinearStreamAllocation); ResidencyContainer allocationsForResidency = {nonLinearStreamAllocation}; @@ -508,14 +501,14 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo EXPECT_EQ(0u, wddm->kmDafLockResult.called); EXPECT_EQ(0u, wddm->kmDafLockResult.lockedAllocations.size()); - memManager->freeGraphicsMemory(commandBuffer); - memManager->freeGraphicsMemory(nonLinearStreamAllocation); + memoryManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(nonLinearStreamAllocation); } TEST_F(WddmCommandStreamTest, makeResident) { - WddmMemoryManager *wddmMM = reinterpret_cast(memManager.get()); + WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -525,13 +518,13 @@ TEST_F(WddmCommandStreamTest, makeResident) { EXPECT_EQ(1u, csr->getResidencyAllocations().size()); EXPECT_EQ(commandBuffer, csr->getResidencyAllocations()[0]); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, makeNonResidentPutsAllocationInEvictionAllocations) { - WddmMemoryManager *wddmMM = reinterpret_cast(memManager.get()); + WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -541,14 +534,14 @@ TEST_F(WddmCommandStreamTest, makeNonResidentPutsAllocationInEvictionAllocations EXPECT_EQ(1u, csr->getEvictionAllocations().size()); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamTest, processEvictionPlacesAllAllocationsOnTrimCandidateList) { - WddmMemoryManager *wddmMM = reinterpret_cast(memManager.get()); + WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *allocation = memManager->allocateGraphicsMemory(4096); - GraphicsAllocation *allocation2 = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemory(4096); + GraphicsAllocation *allocation2 = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, allocation); ASSERT_NE(nullptr, allocation2); @@ -559,16 +552,16 @@ TEST_F(WddmCommandStreamTest, processEvictionPlacesAllAllocationsOnTrimCandidate csr->processEviction(*device->getOsContext()); - EXPECT_EQ(2u, mockWddmMM->residencyControllers[0]->peekTrimCandidateList().size()); + EXPECT_EQ(2u, memoryManager->residencyControllers[0]->peekTrimCandidateList().size()); - memManager->freeGraphicsMemory(allocation); - memManager->freeGraphicsMemory(allocation2); + memoryManager->freeGraphicsMemory(allocation); + memoryManager->freeGraphicsMemory(allocation2); } TEST_F(WddmCommandStreamTest, processEvictionClearsEvictionAllocations) { - WddmMemoryManager *wddmMM = reinterpret_cast(memManager.get()); + WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); - GraphicsAllocation *allocation = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *allocation = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, allocation); csr->getEvictionAllocations().push_back(allocation); @@ -579,13 +572,13 @@ TEST_F(WddmCommandStreamTest, processEvictionClearsEvictionAllocations) { EXPECT_EQ(0u, csr->getEvictionAllocations().size()); - memManager->freeGraphicsMemory(allocation); + memoryManager->freeGraphicsMemory(allocation); } TEST_F(WddmCommandStreamTest, makeResidentNonResidentMemObj) { - GraphicsAllocation *gfxAllocation = memManager->allocateGraphicsMemory(256); + GraphicsAllocation *gfxAllocation = memoryManager->allocateGraphicsMemory(256); Buffer *buffer = new AlignedBuffer(gfxAllocation); - WddmMemoryManager *wddmMM = reinterpret_cast(memManager.get()); + WddmMemoryManager *wddmMM = reinterpret_cast(memoryManager); csr->makeResident(*buffer->getGraphicsAllocation()); EXPECT_EQ(0u, wddm->makeResidentResult.called); @@ -596,7 +589,7 @@ TEST_F(WddmCommandStreamTest, makeResidentNonResidentMemObj) { EXPECT_EQ(gfxAllocation, csr->getEvictionAllocations()[0]); delete buffer; - memManager->freeGraphicsMemory(gfxAllocation); + memoryManager->freeGraphicsMemory(gfxAllocation); } TEST_F(WddmCommandStreamTest, createAllocationAndMakeResident) { @@ -613,7 +606,7 @@ TEST_F(WddmCommandStreamTest, createAllocationAndMakeResident) { } TEST_F(WddmCommandStreamTest, givenHostPtrWhenPtrBelowRestrictionThenCreateAllocationAndMakeResident) { - void *hostPtr = reinterpret_cast(memManager->getAlignedMallocRestrictions()->minAddress - 0x1000); + void *hostPtr = reinterpret_cast(memoryManager->getAlignedMallocRestrictions()->minAddress - 0x1000); auto size = 0x2000u; WddmAllocation *gfxAllocation = static_cast(csr->createAllocationAndHandleResidency(hostPtr, size)); @@ -673,7 +666,7 @@ TEST_F(WddmCommandStreamTest, killCompletedAllocations) { } TEST_F(WddmCommandStreamMockGdiTest, FlushCallsWddmMakeResidentForResidencyAllocations) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -688,11 +681,11 @@ TEST_F(WddmCommandStreamMockGdiTest, FlushCallsWddmMakeResidentForResidencyAlloc EXPECT_NE(0u, gdi->getMakeResidentArg().NumAllocations); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } TEST_F(WddmCommandStreamMockGdiTest, makeResidentClearsResidencyAllocations) { - GraphicsAllocation *commandBuffer = memManager->allocateGraphicsMemory(4096); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -712,7 +705,7 @@ TEST_F(WddmCommandStreamMockGdiTest, makeResidentClearsResidencyAllocations) { EXPECT_EQ(0u, ((WddmAllocation *)commandBuffer)->getTrimCandidateListPosition()); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmittedThenFlushTaskIsProperlyCalled) { @@ -722,7 +715,7 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt if (device->getPreemptionMode() == PreemptionMode::MidThread) { csrSurfaceCount = 2; tmpAllocation = GlobalMockSipProgram::sipProgram->getAllocation(); - GlobalMockSipProgram::sipProgram->resetAllocation(memManager->allocateGraphicsMemory(1024)); + GlobalMockSipProgram::sipProgram->resetAllocation(memoryManager->allocateGraphicsMemory(1024)); } csr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); @@ -730,10 +723,10 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); csr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - auto commandBuffer = memManager->allocateGraphicsMemory(1024); - auto dshAlloc = memManager->allocateGraphicsMemory(1024); - auto iohAlloc = memManager->allocateGraphicsMemory(1024); - auto sshAlloc = memManager->allocateGraphicsMemory(1024); + auto commandBuffer = memoryManager->allocateGraphicsMemory(1024); + auto dshAlloc = memoryManager->allocateGraphicsMemory(1024); + auto iohAlloc = memoryManager->allocateGraphicsMemory(1024); + auto sshAlloc = memoryManager->allocateGraphicsMemory(1024); auto tagAllocation = csr->getTagAllocation(); csr->setPreemptionCsrAllocation(preemptionAllocation); @@ -791,12 +784,12 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)sshAlloc)->getTrimCandidateListPosition()); EXPECT_NE(trimListUnusedPosition, ((WddmAllocation *)csrCommandStream)->getTrimCandidateListPosition()); - memManager->freeGraphicsMemory(dshAlloc); - memManager->freeGraphicsMemory(iohAlloc); - memManager->freeGraphicsMemory(sshAlloc); - memManager->freeGraphicsMemory(commandBuffer); + memoryManager->freeGraphicsMemory(dshAlloc); + memoryManager->freeGraphicsMemory(iohAlloc); + memoryManager->freeGraphicsMemory(sshAlloc); + memoryManager->freeGraphicsMemory(commandBuffer); if (device->getPreemptionMode() == PreemptionMode::MidThread) { - memManager->freeGraphicsMemory(GlobalMockSipProgram::sipProgram->getAllocation()); + memoryManager->freeGraphicsMemory(GlobalMockSipProgram::sipProgram->getAllocation()); GlobalMockSipProgram::sipProgram->resetAllocation(tmpAllocation); } } @@ -929,11 +922,11 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment, 0u)); - auto memManager = executionEnvironment->memoryManager.get(); + auto memoryManager = executionEnvironment->memoryManager.get(); auto &csrCS = mockWddmCsr->getCS(); - auto graphicsAllocation = memManager->allocateGraphicsMemory(1024); + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(1024); IndirectHeap cs(graphicsAllocation); EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); @@ -954,7 +947,7 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra mockWddmCsr->flushTask(cs, 0u, cs, cs, cs, 0u, dispatchFlags, *device); mockWddmCsr->flushBatchedSubmissions(); - memManager->freeGraphicsMemory(graphicsAllocation); + memoryManager->freeGraphicsMemory(graphicsAllocation); } } @@ -970,11 +963,11 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment, 0u)); - auto memManager = executionEnvironment->memoryManager.get(); + auto memoryManager = executionEnvironment->memoryManager.get(); EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); - auto graphicsAllocation = memManager->allocateGraphicsMemory(1024); + auto graphicsAllocation = memoryManager->allocateGraphicsMemory(1024); IndirectHeap cs(graphicsAllocation); EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); @@ -985,5 +978,5 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn EXPECT_FALSE(mockWddmCsr->pageTableManagerInitialized); mockWddmCsr->flushBatchedSubmissions(); - memManager->freeGraphicsMemory(graphicsAllocation); + memoryManager->freeGraphicsMemory(graphicsAllocation); } diff --git a/unit_tests/program/program_data_tests.cpp b/unit_tests/program/program_data_tests.cpp index e865479acf..6fadff11d7 100644 --- a/unit_tests/program/program_data_tests.cpp +++ b/unit_tests/program/program_data_tests.cpp @@ -175,16 +175,16 @@ TEST_F(ProgramDataTest, givenConstantAllocationThatIsInUseByGpuWhenProgramIsBein buildAndDecodeProgramPatchList(); - auto tagAddress = pProgram->getDevice(0).getTagAddress(); + auto &csr = pPlatform->getDevice(0)->getCommandStreamReceiver(); + auto tagAddress = csr.getTagAddress(); auto constantSurface = pProgram->getConstantSurface(); constantSurface->taskCount = *tagAddress + 1; - auto memoryManager = pProgram->getDevice(0).getMemoryManager(); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); delete pProgram; pProgram = nullptr; - EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); - EXPECT_EQ(constantSurface, memoryManager->graphicsAllocations.peekHead()); + EXPECT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); + EXPECT_EQ(constantSurface, csr.getTemporaryAllocations().peekHead()); } TEST_F(ProgramDataTest, givenGlobalAllocationThatIsInUseByGpuWhenProgramIsBeingDestroyedThenItIsAddedToTemporaryAllocationList) { @@ -192,16 +192,16 @@ TEST_F(ProgramDataTest, givenGlobalAllocationThatIsInUseByGpuWhenProgramIsBeingD buildAndDecodeProgramPatchList(); - auto tagAddress = pProgram->getDevice(0).getTagAddress(); + auto &csr = pPlatform->getDevice(0)->getCommandStreamReceiver(); + auto tagAddress = csr.getTagAddress(); auto globalSurface = pProgram->getGlobalSurface(); globalSurface->taskCount = *tagAddress + 1; - auto memoryManager = pProgram->getDevice(0).getMemoryManager(); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); delete pProgram; pProgram = nullptr; - EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); - EXPECT_EQ(globalSurface, memoryManager->graphicsAllocations.peekHead()); + EXPECT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); + EXPECT_EQ(globalSurface, csr.getTemporaryAllocations().peekHead()); } TEST_F(ProgramDataTest, GivenDeviceForcing32BitMessagesWhenConstAllocationIsPresentInProgramBinariesThen32BitStorageIsAllocated) { diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index 165cbf6607..139bc61cef 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -659,15 +659,15 @@ TEST_P(ProgramFromBinaryTest, givenProgramWhenCleanKernelInfoIsCalledThenKernelA TEST_P(ProgramFromBinaryTest, givenProgramWhenCleanCurrentKernelInfoIsCalledButGpuIsNotYetDoneThenKernelAllocationIsPutOnDefferedFreeList) { cl_device_id device = pDevice; - auto memoryManager = pDevice->getMemoryManager(); - EXPECT_TRUE(memoryManager->graphicsAllocations.peekIsEmpty()); + auto &csr = pDevice->getCommandStreamReceiver(); + EXPECT_TRUE(csr.getTemporaryAllocations().peekIsEmpty()); pProgram->build(1, &device, nullptr, nullptr, nullptr, true); auto kernelAllocation = pProgram->getKernelInfo(size_t(0))->getGraphicsAllocation(); kernelAllocation->taskCount = 100; *pDevice->getTagAddress() = 0; pProgram->cleanCurrentKernelInfo(); - EXPECT_FALSE(memoryManager->graphicsAllocations.peekIsEmpty()); - EXPECT_EQ(memoryManager->graphicsAllocations.peekHead(), kernelAllocation); + EXPECT_FALSE(csr.getTemporaryAllocations().peekIsEmpty()); + EXPECT_EQ(csr.getTemporaryAllocations().peekHead(), kernelAllocation); } ////////////////////////////////////////////////////////////////////////////////