Skip to content

Commit 9a1adc3

Browse files
Remove scenarios with memory manager with null csr
Change-Id: Ie151bf3d16c5d994f154c8f9ac3db43702a4798c Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 2632b21 commit 9a1adc3

File tree

9 files changed

+38
-70
lines changed

9 files changed

+38
-70
lines changed

runtime/mem_obj/mem_obj.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,15 @@ void MemObj::releaseAllocatedMapPtr() {
287287
}
288288

289289
void MemObj::waitForCsrCompletion() {
290-
if (memoryManager->csr) {
290+
if (graphicsAllocation) {
291+
UNRECOVERABLE_IF(!memoryManager->csr);
291292
memoryManager->csr->waitForCompletionWithTimeout(false, TimeoutControls::maxTimeout, graphicsAllocation->taskCount);
292293
}
293294
}
294295

295296
void MemObj::destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy) {
296-
if (asyncDestroy && memoryManager->csr && allocation->taskCount != ObjectNotUsed) {
297+
if (asyncDestroy && allocation->taskCount != ObjectNotUsed) {
298+
UNRECOVERABLE_IF(!memoryManager->csr);
297299
auto currentTag = *memoryManager->csr->getTagAddress();
298300
if (currentTag < allocation->taskCount) {
299301
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), TEMPORARY_ALLOCATION);

runtime/memory_manager/memory_manager.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,8 @@ void MemoryManager::storeAllocation(std::unique_ptr<GraphicsAllocation> gfxAlloc
175175
uint32_t taskCount = gfxAllocation->taskCount;
176176

177177
if (allocationUsage == REUSABLE_ALLOCATION) {
178-
if (csr) {
179-
taskCount = csr->peekTaskCount();
180-
} else {
181-
taskCount = 0;
182-
}
178+
UNRECOVERABLE_IF(!csr);
179+
taskCount = csr->peekTaskCount();
183180
}
184181

185182
storeAllocation(std::move(gfxAllocation), allocationUsage, taskCount);
@@ -201,8 +198,9 @@ void MemoryManager::storeAllocation(std::unique_ptr<GraphicsAllocation> gfxAlloc
201198
}
202199

203200
std::unique_ptr<GraphicsAllocation> MemoryManager::obtainReusableAllocation(size_t requiredSize, bool internalAllocation) {
201+
UNRECOVERABLE_IF(!csr);
204202
std::lock_guard<decltype(mtx)> lock(mtx);
205-
auto allocation = allocationsForReuse.detachAllocation(requiredSize, csr ? csr->getTagAddress() : nullptr, internalAllocation);
203+
auto allocation = allocationsForReuse.detachAllocation(requiredSize, csr->getTagAddress(), internalAllocation);
206204
return allocation;
207205
}
208206

@@ -322,32 +320,27 @@ RequirementsStatus MemoryManager::checkAllocationsForOverlapping(AllocationRequi
322320
checkedFragments->fragments[i] = hostPtrManager.getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]);
323321
if (checkedFragments->status[i] == OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT) {
324322
// clean temporary allocations
325-
if (csr != nullptr) {
326-
uint32_t taskCount = *csr->getTagAddress();
323+
UNRECOVERABLE_IF(!csr);
324+
uint32_t taskCount = *csr->getTagAddress();
325+
cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
326+
327+
// check overlapping again
328+
checkedFragments->fragments[i] = hostPtrManager.getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]);
329+
330+
if (checkedFragments->status[i] == OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT) {
331+
// Wait for completion
332+
while (*csr->getTagAddress() < csr->peekLatestSentTaskCount()) {
333+
}
334+
335+
taskCount = *csr->getTagAddress();
327336
cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
328337

329-
// check overlapping again
338+
// check overlapping last time
330339
checkedFragments->fragments[i] = hostPtrManager.getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]);
331-
332340
if (checkedFragments->status[i] == OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT) {
333-
// Wait for completion
334-
while (*csr->getTagAddress() < csr->peekLatestSentTaskCount()) {
335-
}
336-
337-
taskCount = *csr->getTagAddress();
338-
cleanAllocationList(taskCount, TEMPORARY_ALLOCATION);
339-
340-
// check overlapping last time
341-
checkedFragments->fragments[i] = hostPtrManager.getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]);
342-
if (checkedFragments->status[i] == OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT) {
343-
status = RequirementsStatus::FATAL;
344-
break;
345-
}
341+
status = RequirementsStatus::FATAL;
342+
break;
346343
}
347-
} else {
348-
// This path is tested in ULTs
349-
status = RequirementsStatus::FATAL;
350-
break;
351344
}
352345
}
353346
}

unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,6 +2598,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes
25982598
mockCsr->initializeTagAllocation();
25992599
mockCsr->setPreemptionCsrAllocation(pDevice->getPreemptionAllocation());
26002600
mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
2601+
mockedMemoryManager->csr = mockCsr.get();
26012602

26022603
auto mockedSubmissionsAggregator = new mockSubmissionsAggregator();
26032604
mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator);

unit_tests/fixtures/memory_allocator_fixture.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,27 @@
88
#pragma once
99

1010
#include "unit_tests/fixtures/memory_management_fixture.h"
11+
#include "unit_tests/libult/create_command_stream.h"
1112
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
13+
#include "runtime/execution_environment/execution_environment.h"
1214

1315
using namespace OCLRT;
1416

1517
class MemoryAllocatorFixture : public MemoryManagementFixture {
16-
protected:
17-
MemoryManager *memoryManager;
18-
1918
public:
2019
void SetUp() override {
2120
MemoryManagementFixture::SetUp();
2221
memoryManager = new OsAgnosticMemoryManager(false, false);
22+
memoryManager->csr = createCommandStream(*platformDevices, executionEnvironment);
2323
}
2424

2525
void TearDown() override {
26+
delete memoryManager->csr;
2627
delete memoryManager;
2728
MemoryManagementFixture::TearDown();
2829
}
30+
31+
protected:
32+
ExecutionEnvironment executionEnvironment;
33+
MemoryManager *memoryManager;
2934
};

unit_tests/mem_obj/mem_obj_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAl
178178
MockContext context;
179179

180180
context.setMemoryManager(&memoryManager);
181+
memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver();
181182

182183
auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize);
183184
allocation->taskCount = 1;
@@ -230,6 +231,7 @@ TEST(MemObj, givenMemObjWhenItDoesntHaveGraphicsAllocationThenWaitForCsrCompleti
230231
MockContext context;
231232

232233
context.setMemoryManager(&memoryManager);
234+
memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver();
233235

234236
MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR,
235237
MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false);

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,44 +1204,6 @@ TEST(OsAgnosticMemoryManager, checkAllocationsForOverlappingWithNullCsrInMemoryM
12041204
EXPECT_EQ(1u, checkedFragments.count);
12051205
}
12061206

1207-
TEST(OsAgnosticMemoryManager, checkAllocationsForOverlappingWithNullCsrInMemoryManagerAndAllocationBiggerThanExisting) {
1208-
OsAgnosticMemoryManager memoryManager;
1209-
void *cpuPtr1 = (void *)0x100004;
1210-
1211-
auto graphicsAllocation1 = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize, cpuPtr1);
1212-
EXPECT_EQ(2u, memoryManager.hostPtrManager.getFragmentCount());
1213-
1214-
EXPECT_NE(nullptr, graphicsAllocation1);
1215-
1216-
auto fragment1 = memoryManager.hostPtrManager.getFragment(alignDown(cpuPtr1, MemoryConstants::pageSize));
1217-
EXPECT_NE(nullptr, fragment1);
1218-
auto fragment2 = memoryManager.hostPtrManager.getFragment(alignUp(cpuPtr1, MemoryConstants::pageSize));
1219-
EXPECT_NE(nullptr, fragment2);
1220-
1221-
AllocationRequirements requirements;
1222-
CheckedFragments checkedFragments;
1223-
1224-
requirements.requiredFragmentsCount = 1;
1225-
requirements.totalRequiredSize = MemoryConstants::pageSize * 10;
1226-
1227-
requirements.AllocationFragments[0].allocationPtr = alignDown(cpuPtr1, MemoryConstants::pageSize);
1228-
requirements.AllocationFragments[0].allocationSize = MemoryConstants::pageSize * 10;
1229-
requirements.AllocationFragments[0].fragmentPosition = FragmentPosition::NONE;
1230-
1231-
RequirementsStatus status = memoryManager.checkAllocationsForOverlapping(&requirements, &checkedFragments);
1232-
1233-
EXPECT_EQ(RequirementsStatus::FATAL, status);
1234-
EXPECT_EQ(1u, checkedFragments.count);
1235-
EXPECT_EQ(OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT, checkedFragments.status[0]);
1236-
1237-
for (uint32_t i = 1; i < max_fragments_count; i++) {
1238-
EXPECT_EQ(OverlapStatus::FRAGMENT_NOT_CHECKED, checkedFragments.status[i]);
1239-
EXPECT_EQ(nullptr, checkedFragments.fragments[i]);
1240-
}
1241-
1242-
memoryManager.freeGraphicsMemory(graphicsAllocation1);
1243-
}
1244-
12451207
TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsCalledThenGraphicsAllocationIsReturned) {
12461208
OsAgnosticMemoryManager memoryManager;
12471209
auto ptr = (void *)0x100000;

unit_tests/os_interface/linux/drm_command_stream_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class DrmCommandStreamFixture {
6060
EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_))
6161
.Times(1);
6262
mm = static_cast<DrmMemoryManager *>(csr->createMemoryManager(false, false));
63+
mm->csr = csr;
6364
::testing::Mock::VerifyAndClearExpectations(mock);
6465

6566
//assert we have memory manager

unit_tests/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFr
12291229

12301230
MockContext context;
12311231
context.setMemoryManager(memoryManager);
1232+
memoryManager->csr = &context.getDevice(0)->getCommandStreamReceiver();
12321233

12331234
cl_image_format imageFormat;
12341235
imageFormat.image_channel_data_type = CL_UNORM_INT8;

unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountNo
484484
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) {
485485
MockContext context;
486486
context.setMemoryManager(memoryManager.get());
487+
memoryManager->csr = &context.getDevice(0)->getCommandStreamReceiver();
487488

488489
cl_image_format imageFormat;
489490
imageFormat.image_channel_data_type = CL_UNORM_INT8;

0 commit comments

Comments
 (0)