Skip to content

Commit 2fd8540

Browse files
Add complete support for append memory ranges barrier in immediate command list
Related-To: NEO-6242 Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
1 parent 05cb489 commit 2fd8540

File tree

6 files changed

+102
-37
lines changed

6 files changed

+102
-37
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,6 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendMemoryRangesBarrier(uint
393393
applyMemoryRangesBarrier(numRanges, pRangeSizes, pRanges);
394394
appendSignalEventPostWalker(hSignalEvent, workloadPartition);
395395

396-
if (this->cmdListType == CommandListType::TYPE_IMMEDIATE) {
397-
const auto executionResult = executeCommandListImmediate(true);
398-
if (executionResult == ZE_RESULT_ERROR_DEVICE_LOST) {
399-
return ZE_RESULT_ERROR_DEVICE_LOST;
400-
}
401-
}
402-
403396
return ZE_RESULT_SUCCESS;
404397
}
405398

level_zero/core/source/cmdlist/cmdlist_hw_immediate.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ struct CommandListCoreFamilyImmediate : public CommandListCoreFamily<gfxCoreFami
106106
uint32_t numWaitEvents,
107107
ze_event_handle_t *phWaitEvents) override;
108108

109-
ze_result_t executeCommandListImmediateWithFlushTask(bool performMigration);
109+
ze_result_t appendMemoryRangesBarrier(uint32_t numRanges,
110+
const size_t *pRangeSizes,
111+
const void **pRanges,
112+
ze_event_handle_t hSignalEvent,
113+
uint32_t numWaitEvents,
114+
ze_event_handle_t *phWaitEvents) override;
115+
116+
MOCKABLE_VIRTUAL ze_result_t executeCommandListImmediateWithFlushTask(bool performMigration);
110117

111118
void checkAvailableSpace();
112119
void updateDispatchFlagsWithRequiredStreamState(NEO::DispatchFlags &dispatchFlags);

level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendImageCopyToMemo
369369
return flushImmediate(ret, true);
370370
}
371371

372+
template <GFXCORE_FAMILY gfxCoreFamily>
373+
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendMemoryRangesBarrier(uint32_t numRanges,
374+
const size_t *pRangeSizes,
375+
const void **pRanges,
376+
ze_event_handle_t hSignalEvent,
377+
uint32_t numWaitEvents,
378+
ze_event_handle_t *phWaitEvents) {
379+
if (this->isFlushTaskSubmissionEnabled) {
380+
checkAvailableSpace();
381+
}
382+
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendMemoryRangesBarrier(numRanges, pRangeSizes, pRanges, hSignalEvent, numWaitEvents, phWaitEvents);
383+
return flushImmediate(ret, true);
384+
}
385+
372386
template <GFXCORE_FAMILY gfxCoreFamily>
373387
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::flushImmediate(ze_result_t inputRet, bool performMigration) {
374388
if (inputRet == ZE_RESULT_SUCCESS) {

level_zero/core/test/unit_tests/gen12lp/test_cmdlist_gen12lp.cpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ struct CommandListAdjustStateComputeMode : public WhiteBox<::L0::CommandListProd
2929
using ::L0::CommandListProductFamily<productFamily>::applyMemoryRangesBarrier;
3030
};
3131

32-
template <PRODUCT_FAMILY productFamily>
33-
class MockCommandListHw : public WhiteBox<::L0::CommandListProductFamily<productFamily>> {
34-
public:
35-
MockCommandListHw() : WhiteBox<::L0::CommandListProductFamily<productFamily>>(1) {}
36-
using ::L0::CommandListProductFamily<productFamily>::applyMemoryRangesBarrier;
37-
38-
ze_result_t executeCommandListImmediate(bool performMigration) override {
39-
++executeCommandListImmediateCalledCount;
40-
return executeCommandListImmediateReturnValue;
41-
}
42-
43-
ze_result_t executeCommandListImmediateReturnValue{};
44-
int executeCommandListImmediateCalledCount{};
45-
};
46-
4732
HWTEST2_F(CommandListCreate, givenAllocationsWhenApplyRangesBarrierThenCheckWhetherL3ControlIsProgrammed, IsGen12LP) {
4833
using GfxFamily = typename NEO::GfxFamilyMapper<gfxCoreFamily>::GfxFamily;
4934
using L3_CONTROL = typename GfxFamily::L3_CONTROL;
@@ -100,19 +85,19 @@ HWTEST2_F(CommandListCreate, GivenImmediateListAndExecutionSuccessWhenAppendingM
10085
IsDG1) {
10186
ze_result_t result;
10287
uint32_t numRanges = 1;
103-
const size_t pRangeSizes = 1;
104-
const char *ranges[pRangeSizes];
105-
const void **pRanges = reinterpret_cast<const void **>(&ranges[0]);
88+
const size_t rangeSizes = 1;
89+
const char *rangesBuffer[rangeSizes];
90+
const void **ranges = reinterpret_cast<const void **>(&rangesBuffer[0]);
10691

107-
auto cmdList = new MockCommandListHw<productFamily>;
92+
auto cmdList = new MockCommandListImmediateHw<gfxCoreFamily>;
10893
cmdList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
10994
cmdList->initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
11095
cmdList->executeCommandListImmediateReturnValue = ZE_RESULT_SUCCESS;
11196

112-
result = cmdList->appendMemoryRangesBarrier(numRanges, &pRangeSizes,
113-
pRanges, nullptr, 0,
97+
result = cmdList->appendMemoryRangesBarrier(numRanges, &rangeSizes,
98+
ranges, nullptr, 0,
11499
nullptr);
115-
EXPECT_EQ(1, cmdList->executeCommandListImmediateCalledCount);
100+
EXPECT_EQ(1u, cmdList->executeCommandListImmediateCalledCount);
116101
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
117102

118103
cmdList->destroy();
@@ -122,19 +107,19 @@ HWTEST2_F(CommandListCreate, GivenImmediateListAndGpuFailureWhenAppendingMemoryB
122107
IsDG1) {
123108
ze_result_t result;
124109
uint32_t numRanges = 1;
125-
const size_t pRangeSizes = 1;
126-
const char *ranges[pRangeSizes];
127-
const void **pRanges = reinterpret_cast<const void **>(&ranges[0]);
110+
const size_t rangeSizes = 1;
111+
const char *rangesBuffer[rangeSizes];
112+
const void **ranges = reinterpret_cast<const void **>(&rangesBuffer[0]);
128113

129-
auto cmdList = new MockCommandListHw<productFamily>;
114+
auto cmdList = new MockCommandListImmediateHw<gfxCoreFamily>;
130115
cmdList->cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
131116
cmdList->initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
132117
cmdList->executeCommandListImmediateReturnValue = ZE_RESULT_ERROR_DEVICE_LOST;
133118

134-
result = cmdList->appendMemoryRangesBarrier(numRanges, &pRangeSizes,
135-
pRanges, nullptr, 0,
119+
result = cmdList->appendMemoryRangesBarrier(numRanges, &rangeSizes,
120+
ranges, nullptr, 0,
136121
nullptr);
137-
EXPECT_EQ(1, cmdList->executeCommandListImmediateCalledCount);
122+
EXPECT_EQ(1u, cmdList->executeCommandListImmediateCalledCount);
138123
EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, result);
139124

140125
cmdList->destroy();

level_zero/core/test/unit_tests/mocks/mock_cmdlist.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,5 +419,31 @@ class MockAppendMemoryCopy : public CommandListCoreFamily<gfxCoreFamily> {
419419
size_t dstBlitCopyRegionOffset = 0;
420420
};
421421

422+
template <GFXCORE_FAMILY gfxCoreFamily>
423+
class MockCommandListImmediateHw : public WhiteBox<::L0::CommandListCoreFamilyImmediate<gfxCoreFamily>> {
424+
public:
425+
using BaseClass = WhiteBox<::L0::CommandListCoreFamilyImmediate<gfxCoreFamily>>;
426+
MockCommandListImmediateHw() : BaseClass() {}
427+
using BaseClass::applyMemoryRangesBarrier;
428+
using BaseClass::isFlushTaskSubmissionEnabled;
429+
using BaseClass::isSyncModeQueue;
430+
431+
ze_result_t executeCommandListImmediate(bool performMigration) override {
432+
++executeCommandListImmediateCalledCount;
433+
return executeCommandListImmediateReturnValue;
434+
}
435+
436+
ze_result_t executeCommandListImmediateWithFlushTask(bool performMigration) override {
437+
++executeCommandListImmediateWithFlushTaskCalledCount;
438+
return executeCommandListImmediateWithFlushTaskReturnValue;
439+
}
440+
441+
ze_result_t executeCommandListImmediateReturnValue = ZE_RESULT_SUCCESS;
442+
uint32_t executeCommandListImmediateCalledCount = 0;
443+
444+
ze_result_t executeCommandListImmediateWithFlushTaskReturnValue = ZE_RESULT_SUCCESS;
445+
uint32_t executeCommandListImmediateWithFlushTaskCalledCount = 0;
446+
};
447+
422448
} // namespace ult
423449
} // namespace L0

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_6.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,45 @@ HWTEST2_F(CommandListTest, givenComputeCommandListWhenRequiredFlushOperationAndS
235235
EXPECT_EQ(usedBefore, usedAfter);
236236
}
237237

238+
HWTEST2_F(CommandListTest, givenImmediateCommandListWhenAppendMemoryRangesBarrierUsingFlushTaskThenExpectCorrectExecuteCall, IsAtLeastSkl) {
239+
ze_result_t result;
240+
uint32_t numRanges = 1;
241+
const size_t rangeSizes = 1;
242+
const char *rangesBuffer[rangeSizes];
243+
const void **ranges = reinterpret_cast<const void **>(&rangesBuffer[0]);
244+
245+
MockCommandListImmediateHw<gfxCoreFamily> cmdList;
246+
cmdList.isFlushTaskSubmissionEnabled = true;
247+
cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
248+
cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
249+
250+
result = cmdList.appendMemoryRangesBarrier(numRanges, &rangeSizes,
251+
ranges, nullptr, 0,
252+
nullptr);
253+
EXPECT_EQ(0u, cmdList.executeCommandListImmediateCalledCount);
254+
EXPECT_EQ(1u, cmdList.executeCommandListImmediateWithFlushTaskCalledCount);
255+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
256+
}
257+
258+
HWTEST2_F(CommandListTest, givenImmediateCommandListWhenAppendMemoryRangesBarrierNotUsingFlushTaskThenExpectCorrectExecuteCall, IsAtLeastSkl) {
259+
ze_result_t result;
260+
uint32_t numRanges = 1;
261+
const size_t rangeSizes = 1;
262+
const char *rangesBuffer[rangeSizes];
263+
const void **ranges = reinterpret_cast<const void **>(&rangesBuffer[0]);
264+
265+
MockCommandListImmediateHw<gfxCoreFamily> cmdList;
266+
cmdList.isFlushTaskSubmissionEnabled = false;
267+
cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
268+
cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u);
269+
270+
result = cmdList.appendMemoryRangesBarrier(numRanges, &rangeSizes,
271+
ranges, nullptr, 0,
272+
nullptr);
273+
EXPECT_EQ(1u, cmdList.executeCommandListImmediateCalledCount);
274+
EXPECT_EQ(0u, cmdList.executeCommandListImmediateWithFlushTaskCalledCount);
275+
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
276+
}
277+
238278
} // namespace ult
239279
} // namespace L0

0 commit comments

Comments
 (0)