Skip to content

Commit

Permalink
Remove cleaning allocation lists methods from memory manager
Browse files Browse the repository at this point in the history
Change-Id: I4a58a5373e7dc4cf8dc5d90390e84c4f23689139
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
  • Loading branch information
JablonskiMateusz authored and Compute-Runtime-Automation committed Oct 29, 2018
1 parent 7b1d19e commit a30c70d
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 288 deletions.
6 changes: 3 additions & 3 deletions runtime/command_stream/command_stream_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ CommandStreamReceiver::~CommandStreamReceiver() {
cleanupResources();

if (!allocationsForReuse.peekIsEmpty()) {
getMemoryManager()->freeAllocationsList(-1, allocationsForReuse);
internalAllocationStorage->freeAllocationsList(-1, allocationsForReuse);
}
if (!temporaryAllocations.peekIsEmpty()) {
getMemoryManager()->freeAllocationsList(-1, temporaryAllocations);
internalAllocationStorage->freeAllocationsList(-1, temporaryAllocations);
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requ
if (allocationList.peekIsEmpty()) {
return;
}
getMemoryManager()->freeAllocationsList(requiredTaskCount, allocationList);
internalAllocationStorage->freeAllocationsList(requiredTaskCount, allocationList);
}

MemoryManager *CommandStreamReceiver::getMemoryManager() const {
Expand Down
9 changes: 5 additions & 4 deletions runtime/event/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "public/cl_ext_private.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/memory_manager/internal_allocation_storage.h"
#include "runtime/context/context.h"
#include "runtime/device/device.h"
#include "runtime/event/event.h"
Expand Down Expand Up @@ -310,8 +310,8 @@ inline bool Event::wait(bool blocking, bool useQuickKmdSleep) {

DEBUG_BREAK_IF(this->taskLevel == Event::eventNotReady && this->executionStatus >= 0);

auto *memoryManager = cmdQueue->getDevice().getMemoryManager();
memoryManager->cleanAllocationList(this->taskCount, TEMPORARY_ALLOCATION);
auto *allocationStorage = cmdQueue->getDevice().getCommandStreamReceiver().getInternalAllocationStorage();
allocationStorage->cleanAllocationList(this->taskCount, TEMPORARY_ALLOCATION);

return true;
}
Expand Down Expand Up @@ -346,7 +346,8 @@ void Event::updateExecutionStatus() {
transitionExecutionStatus(CL_COMPLETE);
executeCallbacks(CL_COMPLETE);
unblockEventsBlockedByThis(CL_COMPLETE);
cmdQueue->getDevice().getMemoryManager()->cleanAllocationList(this->taskCount, TEMPORARY_ALLOCATION);
auto *allocationStorage = cmdQueue->getDevice().getCommandStreamReceiver().getInternalAllocationStorage();
allocationStorage->cleanAllocationList(this->taskCount, TEMPORARY_ALLOCATION);
return;
}

Expand Down
8 changes: 5 additions & 3 deletions runtime/memory_manager/host_ptr_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/memory_manager/host_ptr_manager.h"
#include "runtime/memory_manager/internal_allocation_storage.h"
#include "runtime/memory_manager/memory_manager.h"

using namespace OCLRT;
Expand Down Expand Up @@ -282,8 +283,9 @@ RequirementsStatus HostPtrManager::checkAllocationsForOverlapping(MemoryManager
// clean temporary allocations

auto commandStreamReceiver = memoryManager.getCommandStreamReceiver(0);
auto allocationStorage = commandStreamReceiver->getInternalAllocationStorage();
uint32_t taskCount = *commandStreamReceiver->getTagAddress();
memoryManager.cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
allocationStorage->cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);

// check overlapping again
checkedFragments->fragments[i] = getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]);
Expand All @@ -294,7 +296,7 @@ RequirementsStatus HostPtrManager::checkAllocationsForOverlapping(MemoryManager
;

taskCount = *commandStreamReceiver->getTagAddress();
memoryManager.cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
allocationStorage->cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);

// check overlapping last time
checkedFragments->fragments[i] = getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]);
Expand All @@ -306,4 +308,4 @@ RequirementsStatus HostPtrManager::checkAllocationsForOverlapping(MemoryManager
}
}
return status;
}
}
5 changes: 3 additions & 2 deletions runtime/memory_manager/internal_allocation_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class GraphicsAllocation;

class InternalAllocationStorage {
public:
MOCKABLE_VIRTUAL ~InternalAllocationStorage() = default;
InternalAllocationStorage(CommandStreamReceiver &commandStreamReceiver);
void cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage);
MOCKABLE_VIRTUAL void cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage);
void freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList);
void storeAllocation(std::unique_ptr<GraphicsAllocation> gfxAllocation, uint32_t allocationUsage);
void storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation> gfxAllocation, uint32_t allocationUsage, uint32_t taskCount);
std::unique_ptr<GraphicsAllocation> obtainReusableAllocation(size_t requiredSize, bool isInternalAllocationRequired);

private:
protected:
std::recursive_mutex mutex;
CommandStreamReceiver &commandStreamReceiver;
};
Expand Down
9 changes: 0 additions & 9 deletions runtime/memory_manager/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ void MemoryManager::applyCommonCleanup() {
}
}

bool MemoryManager::cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage) {
getCommandStreamReceiver(0)->getInternalAllocationStorage()->cleanAllocationList(waitTaskCount, allocationUsage);
return false;
}

void MemoryManager::freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList) {
getCommandStreamReceiver(0)->getInternalAllocationStorage()->freeAllocationsList(waitTaskCount, allocationsList);
}

TagAllocator<HwTimeStamps> *MemoryManager::getEventTsAllocator() {
if (profilingTimeStampAllocator.get() == nullptr) {
profilingTimeStampAllocator = std::make_unique<TagAllocator<HwTimeStamps>>(this, TagCount, MemoryConstants::cacheLineSize);
Expand Down
4 changes: 0 additions & 4 deletions runtime/memory_manager/memory_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ class MemoryManager {

virtual uint64_t getInternalHeapBaseAddress() = 0;

virtual bool cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage);

void freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList);

TagAllocator<HwTimeStamps> *getEventTsAllocator();
TagAllocator<HwPerfCounter> *getEventPerfCountAllocator();
TagAllocator<TimestampPacket> *getTimestampPacketAllocator();
Expand Down
4 changes: 1 addition & 3 deletions unit_tests/command_queue/command_queue_hw_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac
EXPECT_NE(memory, allocation->getUnderlyingBuffer());
EXPECT_THAT(allocation->getUnderlyingBuffer(), MemCompare(memory, size));

gmockMemoryManager->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
allocation->taskCount = device->getCommandStreamReceiver().peekLatestFlushedTaskCount();
mockCmdQ->release();
mockContext->release();
}
Expand Down Expand Up @@ -1091,7 +1091,6 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac
auto allocation = surface.getAllocation();
EXPECT_EQ(nullptr, allocation);

gmockMemoryManager->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
mockCmdQ->release();
mockContext->release();
}
Expand All @@ -1117,7 +1116,6 @@ struct ReducedAddrSpaceCommandQueueHwTest : public CommandQueueHwTest {

void TearDown() override {
CommandQueueHwTest::TearDown();
gmockMemoryManager->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
mockContext->release();
}
};
Expand Down
8 changes: 1 addition & 7 deletions unit_tests/fixtures/memory_manager_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@
#include "unit_tests/mocks/mock_memory_manager.h"

using namespace OCLRT;
using ::testing::NiceMock;

void MemoryManagerWithCsrFixture::SetUp() {
csr = new MockCommandStreamReceiver(this->executionEnvironment);
gmockMemoryManager = new NiceMock<GMockMemoryManager>(executionEnvironment);
memoryManager = gmockMemoryManager;
memoryManager = new MockMemoryManager(executionEnvironment);
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));

csr->tagAddress = &currentGpuTag;
executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr<CommandStreamReceiver>(csr));
}
Expand Down
10 changes: 5 additions & 5 deletions unit_tests/fixtures/memory_manager_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
*/

#pragma once
#include "unit_tests/mocks/mock_csr.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/options.h"

using namespace OCLRT;

class MockCommandStreamReceiver;
namespace OCLRT {
class MemoryManager;
class GMockMemoryManager;
class MockMemoryManager;
}; // namespace OCLRT

class MemoryManagerWithCsrFixture {
public:
MemoryManager *memoryManager;
GMockMemoryManager *gmockMemoryManager;
MockMemoryManager *memoryManager;
ExecutionEnvironment executionEnvironment;
MockCommandStreamReceiver *csr;
uint32_t taskCount = 0;
Expand Down
10 changes: 6 additions & 4 deletions unit_tests/kernel/substitute_kernel_heap_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
*/

#include "runtime/memory_manager/internal_allocation_storage.h"
#include "unit_tests/fixtures/device_fixture.h"
#include "unit_tests/mocks/mock_kernel.h"
#include "test.h"
Expand Down Expand Up @@ -108,6 +109,7 @@ TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKe
MockKernelWithInternals kernel(*pDevice);
auto pHeader = const_cast<SKernelBinaryHeaderCommon *>(kernel.kernelInfo.heapInfo.pKernelHeader);
auto memoryManager = pDevice->getMemoryManager();
auto &commandStreamReceiver = pDevice->getCommandStreamReceiver();

const size_t initialHeapSize = 0x40;
pHeader->KernelHeapSize = initialHeapSize;
Expand All @@ -120,13 +122,13 @@ TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKe
const size_t newHeapSize = initialHeapSize + 1;
char newHeap[newHeapSize];

EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty());
EXPECT_TRUE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());

kernel.mockKernel->substituteKernelHeap(newHeap, newHeapSize);
auto secondAllocation = kernel.kernelInfo.kernelAllocation;

EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty());
EXPECT_EQ(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekHead(), firstAllocation);
EXPECT_FALSE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());
EXPECT_EQ(commandStreamReceiver.getTemporaryAllocations().peekHead(), firstAllocation);
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
memoryManager->cleanAllocationList(firstAllocation->taskCount, TEMPORARY_ALLOCATION);
commandStreamReceiver.getInternalAllocationStorage()->cleanAllocationList(firstAllocation->taskCount, TEMPORARY_ALLOCATION);
}
Loading

0 comments on commit a30c70d

Please sign in to comment.