Skip to content

Commit a30c70d

Browse files
Remove cleaning allocation lists methods from memory manager
Change-Id: I4a58a5373e7dc4cf8dc5d90390e84c4f23689139 Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent 7b1d19e commit a30c70d

16 files changed

+263
-288
lines changed

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ CommandStreamReceiver::~CommandStreamReceiver() {
5151
cleanupResources();
5252

5353
if (!allocationsForReuse.peekIsEmpty()) {
54-
getMemoryManager()->freeAllocationsList(-1, allocationsForReuse);
54+
internalAllocationStorage->freeAllocationsList(-1, allocationsForReuse);
5555
}
5656
if (!temporaryAllocations.peekIsEmpty()) {
57-
getMemoryManager()->freeAllocationsList(-1, temporaryAllocations);
57+
internalAllocationStorage->freeAllocationsList(-1, temporaryAllocations);
5858
}
5959
}
6060

@@ -115,7 +115,7 @@ void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requ
115115
if (allocationList.peekIsEmpty()) {
116116
return;
117117
}
118-
getMemoryManager()->freeAllocationsList(requiredTaskCount, allocationList);
118+
internalAllocationStorage->freeAllocationsList(requiredTaskCount, allocationList);
119119
}
120120

121121
MemoryManager *CommandStreamReceiver::getMemoryManager() const {

runtime/event/event.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "public/cl_ext_private.h"
99
#include "runtime/command_queue/command_queue.h"
1010
#include "runtime/command_stream/command_stream_receiver.h"
11-
#include "runtime/memory_manager/memory_manager.h"
11+
#include "runtime/memory_manager/internal_allocation_storage.h"
1212
#include "runtime/context/context.h"
1313
#include "runtime/device/device.h"
1414
#include "runtime/event/event.h"
@@ -310,8 +310,8 @@ inline bool Event::wait(bool blocking, bool useQuickKmdSleep) {
310310

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

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

316316
return true;
317317
}
@@ -346,7 +346,8 @@ void Event::updateExecutionStatus() {
346346
transitionExecutionStatus(CL_COMPLETE);
347347
executeCallbacks(CL_COMPLETE);
348348
unblockEventsBlockedByThis(CL_COMPLETE);
349-
cmdQueue->getDevice().getMemoryManager()->cleanAllocationList(this->taskCount, TEMPORARY_ALLOCATION);
349+
auto *allocationStorage = cmdQueue->getDevice().getCommandStreamReceiver().getInternalAllocationStorage();
350+
allocationStorage->cleanAllocationList(this->taskCount, TEMPORARY_ALLOCATION);
350351
return;
351352
}
352353

runtime/memory_manager/host_ptr_manager.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "runtime/command_stream/command_stream_receiver.h"
99
#include "runtime/memory_manager/host_ptr_manager.h"
10+
#include "runtime/memory_manager/internal_allocation_storage.h"
1011
#include "runtime/memory_manager/memory_manager.h"
1112

1213
using namespace OCLRT;
@@ -282,8 +283,9 @@ RequirementsStatus HostPtrManager::checkAllocationsForOverlapping(MemoryManager
282283
// clean temporary allocations
283284

284285
auto commandStreamReceiver = memoryManager.getCommandStreamReceiver(0);
286+
auto allocationStorage = commandStreamReceiver->getInternalAllocationStorage();
285287
uint32_t taskCount = *commandStreamReceiver->getTagAddress();
286-
memoryManager.cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
288+
allocationStorage->cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
287289

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

296298
taskCount = *commandStreamReceiver->getTagAddress();
297-
memoryManager.cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
299+
allocationStorage->cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
298300

299301
// check overlapping last time
300302
checkedFragments->fragments[i] = getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]);
@@ -306,4 +308,4 @@ RequirementsStatus HostPtrManager::checkAllocationsForOverlapping(MemoryManager
306308
}
307309
}
308310
return status;
309-
}
311+
}

runtime/memory_manager/internal_allocation_storage.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ class GraphicsAllocation;
1717

1818
class InternalAllocationStorage {
1919
public:
20+
MOCKABLE_VIRTUAL ~InternalAllocationStorage() = default;
2021
InternalAllocationStorage(CommandStreamReceiver &commandStreamReceiver);
21-
void cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage);
22+
MOCKABLE_VIRTUAL void cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage);
2223
void freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList);
2324
void storeAllocation(std::unique_ptr<GraphicsAllocation> gfxAllocation, uint32_t allocationUsage);
2425
void storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation> gfxAllocation, uint32_t allocationUsage, uint32_t taskCount);
2526
std::unique_ptr<GraphicsAllocation> obtainReusableAllocation(size_t requiredSize, bool isInternalAllocationRequired);
2627

27-
private:
28+
protected:
2829
std::recursive_mutex mutex;
2930
CommandStreamReceiver &commandStreamReceiver;
3031
};

runtime/memory_manager/memory_manager.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,6 @@ void MemoryManager::applyCommonCleanup() {
171171
}
172172
}
173173

174-
bool MemoryManager::cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage) {
175-
getCommandStreamReceiver(0)->getInternalAllocationStorage()->cleanAllocationList(waitTaskCount, allocationUsage);
176-
return false;
177-
}
178-
179-
void MemoryManager::freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList) {
180-
getCommandStreamReceiver(0)->getInternalAllocationStorage()->freeAllocationsList(waitTaskCount, allocationsList);
181-
}
182-
183174
TagAllocator<HwTimeStamps> *MemoryManager::getEventTsAllocator() {
184175
if (profilingTimeStampAllocator.get() == nullptr) {
185176
profilingTimeStampAllocator = std::make_unique<TagAllocator<HwTimeStamps>>(this, TagCount, MemoryConstants::cacheLineSize);

runtime/memory_manager/memory_manager.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ class MemoryManager {
200200

201201
virtual uint64_t getInternalHeapBaseAddress() = 0;
202202

203-
virtual bool cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage);
204-
205-
void freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList);
206-
207203
TagAllocator<HwTimeStamps> *getEventTsAllocator();
208204
TagAllocator<HwPerfCounter> *getEventPerfCountAllocator();
209205
TagAllocator<TimestampPacket> *getTimestampPacketAllocator();

unit_tests/command_queue/command_queue_hw_tests.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac
10531053
EXPECT_NE(memory, allocation->getUnderlyingBuffer());
10541054
EXPECT_THAT(allocation->getUnderlyingBuffer(), MemCompare(memory, size));
10551055

1056-
gmockMemoryManager->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
1056+
allocation->taskCount = device->getCommandStreamReceiver().peekLatestFlushedTaskCount();
10571057
mockCmdQ->release();
10581058
mockContext->release();
10591059
}
@@ -1091,7 +1091,6 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac
10911091
auto allocation = surface.getAllocation();
10921092
EXPECT_EQ(nullptr, allocation);
10931093

1094-
gmockMemoryManager->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
10951094
mockCmdQ->release();
10961095
mockContext->release();
10971096
}
@@ -1117,7 +1116,6 @@ struct ReducedAddrSpaceCommandQueueHwTest : public CommandQueueHwTest {
11171116

11181117
void TearDown() override {
11191118
CommandQueueHwTest::TearDown();
1120-
gmockMemoryManager->cleanAllocationList(-1, TEMPORARY_ALLOCATION);
11211119
mockContext->release();
11221120
}
11231121
};

unit_tests/fixtures/memory_manager_fixture.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@
1010
#include "unit_tests/mocks/mock_memory_manager.h"
1111

1212
using namespace OCLRT;
13-
using ::testing::NiceMock;
1413

1514
void MemoryManagerWithCsrFixture::SetUp() {
1615
csr = new MockCommandStreamReceiver(this->executionEnvironment);
17-
gmockMemoryManager = new NiceMock<GMockMemoryManager>(executionEnvironment);
18-
memoryManager = gmockMemoryManager;
16+
memoryManager = new MockMemoryManager(executionEnvironment);
1917
executionEnvironment.memoryManager.reset(memoryManager);
20-
21-
ON_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerCleanAllocationList));
22-
ON_CALL(*gmockMemoryManager, populateOsHandles(::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerPopulateOsHandles));
23-
2418
csr->tagAddress = &currentGpuTag;
2519
executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr<CommandStreamReceiver>(csr));
2620
}

unit_tests/fixtures/memory_manager_fixture.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66
*/
77

88
#pragma once
9-
#include "unit_tests/mocks/mock_csr.h"
9+
#include "runtime/execution_environment/execution_environment.h"
10+
#include "runtime/helpers/options.h"
1011

1112
using namespace OCLRT;
1213

14+
class MockCommandStreamReceiver;
1315
namespace OCLRT {
14-
class MemoryManager;
15-
class GMockMemoryManager;
16+
class MockMemoryManager;
1617
}; // namespace OCLRT
1718

1819
class MemoryManagerWithCsrFixture {
1920
public:
20-
MemoryManager *memoryManager;
21-
GMockMemoryManager *gmockMemoryManager;
21+
MockMemoryManager *memoryManager;
2222
ExecutionEnvironment executionEnvironment;
2323
MockCommandStreamReceiver *csr;
2424
uint32_t taskCount = 0;

unit_tests/kernel/substitute_kernel_heap_tests.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77

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

112114
const size_t initialHeapSize = 0x40;
113115
pHeader->KernelHeapSize = initialHeapSize;
@@ -120,13 +122,13 @@ TEST_F(KernelSubstituteTest, givenKernelWithUsedKernelAllocationWhenSubstituteKe
120122
const size_t newHeapSize = initialHeapSize + 1;
121123
char newHeap[newHeapSize];
122124

123-
EXPECT_TRUE(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty());
125+
EXPECT_TRUE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());
124126

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

128-
EXPECT_FALSE(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekIsEmpty());
129-
EXPECT_EQ(memoryManager->getCommandStreamReceiver(0)->getTemporaryAllocations().peekHead(), firstAllocation);
130+
EXPECT_FALSE(commandStreamReceiver.getTemporaryAllocations().peekIsEmpty());
131+
EXPECT_EQ(commandStreamReceiver.getTemporaryAllocations().peekHead(), firstAllocation);
130132
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(secondAllocation);
131-
memoryManager->cleanAllocationList(firstAllocation->taskCount, TEMPORARY_ALLOCATION);
133+
commandStreamReceiver.getInternalAllocationStorage()->cleanAllocationList(firstAllocation->taskCount, TEMPORARY_ALLOCATION);
132134
}

0 commit comments

Comments
 (0)