Skip to content

Commit 8f5dd3c

Browse files
Refactor immediate command list flushing
Related-To: NEO-6242 Signed-off-by: Zbigniew Zdanowicz <[email protected]>
1 parent 80b520b commit 8f5dd3c

File tree

5 files changed

+30
-111
lines changed

5 files changed

+30
-111
lines changed

level_zero/core/source/cmdlist/cmdlist_hw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ struct CommandListCoreFamily : CommandListImp {
249249
MOCKABLE_VIRTUAL AlignedAllocationData getAlignedAllocation(Device *device, const void *buffer, uint64_t bufferSize, bool hostCopyAllowed);
250250
ze_result_t addEventsToCmdList(uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents);
251251

252+
size_t cmdListCurrentStartOffset = 0;
252253
bool containsAnyKernel = false;
253254
};
254255

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::reset() {
119119
device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(alloc);
120120
}
121121
this->ownedPrivateAllocations.clear();
122+
cmdListCurrentStartOffset = 0;
122123
return ZE_RESULT_SUCCESS;
123124
}
124125

level_zero/core/source/cmdlist/cmdlist_hw_immediate.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2020-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -110,8 +110,7 @@ struct CommandListCoreFamilyImmediate : public CommandListCoreFamily<gfxCoreFami
110110

111111
void checkAvailableSpace();
112112

113-
protected:
114-
size_t cmdListBBEndOffset = 0;
113+
ze_result_t flushImmediate(ze_result_t inputRet, bool performMigration);
115114
};
116115

117116
template <PRODUCT_FAMILY gfxProductFamily>

level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl

Lines changed: 25 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ template <GFXCORE_FAMILY gfxCoreFamily>
1919
void CommandListCoreFamilyImmediate<gfxCoreFamily>::checkAvailableSpace() {
2020
if (this->commandContainer.getCommandStream()->getAvailableSpace() < maxImmediateCommandSize) {
2121
this->commandContainer.allocateNextCommandBuffer();
22-
cmdListBBEndOffset = 0;
22+
this->cmdListCurrentStartOffset = 0;
2323
}
2424
}
2525

@@ -61,7 +61,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::executeCommandListImm
6161
this->commandContainer.removeDuplicatesFromResidencyContainer();
6262

6363
auto commandStream = this->commandContainer.getCommandStream();
64-
size_t commandStreamStart = cmdListBBEndOffset;
64+
size_t commandStreamStart = this->cmdListCurrentStartOffset;
6565

6666
auto lockCSR = this->csr->obtainUniqueOwnership();
6767

@@ -99,7 +99,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::executeCommandListImm
9999
this->csr->getInternalAllocationStorage()->cleanAllocationList(completionStamp.taskCount, NEO::AllocationUsage::TEMPORARY_ALLOCATION);
100100
}
101101

102-
cmdListBBEndOffset = commandStream->getUsed();
102+
this->cmdListCurrentStartOffset = commandStream->getUsed();
103103

104104
this->commandContainer.getResidencyContainer().clear();
105105

@@ -116,14 +116,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendLaunchKernel(
116116
}
117117
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernel(hKernel, pThreadGroupDimensions,
118118
hSignalEvent, numWaitEvents, phWaitEvents);
119-
if (ret == ZE_RESULT_SUCCESS) {
120-
if (this->isFlushTaskSubmissionEnabled) {
121-
executeCommandListImmediateWithFlushTask(true);
122-
} else {
123-
executeCommandListImmediate(true);
124-
}
125-
}
126-
return ret;
119+
return flushImmediate(ret, true);
127120
}
128121

129122
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -136,14 +129,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendLaunchKernelInd
136129
}
137130
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernelIndirect(hKernel, pDispatchArgumentsBuffer,
138131
hSignalEvent, numWaitEvents, phWaitEvents);
139-
if (ret == ZE_RESULT_SUCCESS) {
140-
if (this->isFlushTaskSubmissionEnabled) {
141-
executeCommandListImmediateWithFlushTask(true);
142-
} else {
143-
executeCommandListImmediate(true);
144-
}
145-
}
146-
return ret;
132+
return flushImmediate(ret, true);
147133
}
148134

149135
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -167,13 +153,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendBarrier(
167153
checkAvailableSpace();
168154
}
169155
ret = CommandListCoreFamily<gfxCoreFamily>::appendBarrier(hSignalEvent, numWaitEvents, phWaitEvents);
170-
if (ret == ZE_RESULT_SUCCESS) {
171-
if (this->isFlushTaskSubmissionEnabled) {
172-
executeCommandListImmediateWithFlushTask(true);
173-
} else {
174-
executeCommandListImmediate(true);
175-
}
176-
}
156+
return flushImmediate(ret, true);
177157
} else {
178158
ret = CommandListCoreFamilyImmediate<gfxCoreFamily>::appendWaitOnEvents(numWaitEvents, phWaitEvents);
179159
if (!hSignalEvent) {
@@ -204,14 +184,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendMemoryCopy(
204184
}
205185
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendMemoryCopy(dstptr, srcptr, size, hSignalEvent,
206186
numWaitEvents, phWaitEvents);
207-
if (ret == ZE_RESULT_SUCCESS) {
208-
if (this->isFlushTaskSubmissionEnabled) {
209-
executeCommandListImmediateWithFlushTask(true);
210-
} else {
211-
executeCommandListImmediate(true);
212-
}
213-
}
214-
return ret;
187+
return flushImmediate(ret, true);
215188
}
216189

217190
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -234,14 +207,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendMemoryCopyRegio
234207
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendMemoryCopyRegion(dstPtr, dstRegion, dstPitch, dstSlicePitch,
235208
srcPtr, srcRegion, srcPitch, srcSlicePitch,
236209
hSignalEvent, numWaitEvents, phWaitEvents);
237-
if (ret == ZE_RESULT_SUCCESS) {
238-
if (this->isFlushTaskSubmissionEnabled) {
239-
executeCommandListImmediateWithFlushTask(true);
240-
} else {
241-
executeCommandListImmediate(true);
242-
}
243-
}
244-
return ret;
210+
return flushImmediate(ret, true);
245211
}
246212

247213
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -255,14 +221,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendMemoryFill(void
255221
checkAvailableSpace();
256222
}
257223
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendMemoryFill(ptr, pattern, patternSize, size, hSignalEvent, numWaitEvents, phWaitEvents);
258-
if (ret == ZE_RESULT_SUCCESS) {
259-
if (this->isFlushTaskSubmissionEnabled) {
260-
executeCommandListImmediateWithFlushTask(true);
261-
} else {
262-
executeCommandListImmediate(true);
263-
}
264-
}
265-
return ret;
224+
return flushImmediate(ret, true);
266225
}
267226

268227
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -277,13 +236,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendSignalEvent(ze_
277236
checkAvailableSpace();
278237
}
279238
ret = CommandListCoreFamily<gfxCoreFamily>::appendSignalEvent(hSignalEvent);
280-
if (ret == ZE_RESULT_SUCCESS) {
281-
if (this->isFlushTaskSubmissionEnabled) {
282-
executeCommandListImmediateWithFlushTask(true);
283-
} else {
284-
executeCommandListImmediate(true);
285-
}
286-
}
239+
return flushImmediate(ret, true);
287240
} else {
288241
const auto &hwInfo = this->device->getHwInfo();
289242
NEO::PipeControlArgs args;
@@ -309,13 +262,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendEventReset(ze_e
309262
checkAvailableSpace();
310263
}
311264
ret = CommandListCoreFamily<gfxCoreFamily>::appendEventReset(hSignalEvent);
312-
if (ret == ZE_RESULT_SUCCESS) {
313-
if (this->isFlushTaskSubmissionEnabled) {
314-
executeCommandListImmediateWithFlushTask(true);
315-
} else {
316-
executeCommandListImmediate(true);
317-
}
318-
}
265+
return flushImmediate(ret, true);
319266
} else {
320267
const auto &hwInfo = this->device->getHwInfo();
321268
NEO::PipeControlArgs args;
@@ -339,14 +286,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendPageFaultCopy(N
339286
}
340287

341288
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendPageFaultCopy(dstAllocation, srcAllocation, size, flushHost);
342-
if (ret == ZE_RESULT_SUCCESS) {
343-
if (this->isFlushTaskSubmissionEnabled) {
344-
executeCommandListImmediateWithFlushTask(false);
345-
} else {
346-
executeCommandListImmediate(false);
347-
}
348-
}
349-
return ret;
289+
return flushImmediate(ret, false);
350290
}
351291

352292
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -365,13 +305,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendWaitOnEvents(ui
365305
checkAvailableSpace();
366306
}
367307
ret = CommandListCoreFamily<gfxCoreFamily>::appendWaitOnEvents(numEvents, phWaitEvents);
368-
if (ret == ZE_RESULT_SUCCESS) {
369-
if (this->isFlushTaskSubmissionEnabled) {
370-
executeCommandListImmediateWithFlushTask(true);
371-
} else {
372-
executeCommandListImmediate(true);
373-
}
374-
}
308+
return flushImmediate(ret, true);
375309
} else {
376310
bool dcFlushRequired = false;
377311
const auto &hwInfo = this->device->getHwInfo();
@@ -403,14 +337,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendWriteGlobalTime
403337
checkAvailableSpace();
404338
}
405339
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendWriteGlobalTimestamp(dstptr, hSignalEvent, numWaitEvents, phWaitEvents);
406-
if (ret == ZE_RESULT_SUCCESS) {
407-
if (this->isFlushTaskSubmissionEnabled) {
408-
executeCommandListImmediateWithFlushTask(true);
409-
} else {
410-
executeCommandListImmediate(true);
411-
}
412-
}
413-
return ret;
340+
return flushImmediate(ret, true);
414341
}
415342

416343
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -446,14 +373,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendImageCopyRegion
446373
}
447374
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendImageCopyRegion(hDstImage, hSrcImage, pDstRegion, pSrcRegion, hSignalEvent,
448375
numWaitEvents, phWaitEvents);
449-
if (ret == ZE_RESULT_SUCCESS) {
450-
if (this->isFlushTaskSubmissionEnabled) {
451-
executeCommandListImmediateWithFlushTask(true);
452-
} else {
453-
executeCommandListImmediate(true);
454-
}
455-
}
456-
return ret;
376+
return flushImmediate(ret, true);
457377
}
458378

459379
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -470,14 +390,7 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendImageCopyFromMe
470390
}
471391
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendImageCopyFromMemory(hDstImage, srcPtr, pDstRegion, hSignalEvent,
472392
numWaitEvents, phWaitEvents);
473-
if (ret == ZE_RESULT_SUCCESS) {
474-
if (this->isFlushTaskSubmissionEnabled) {
475-
executeCommandListImmediateWithFlushTask(true);
476-
} else {
477-
executeCommandListImmediate(true);
478-
}
479-
}
480-
return ret;
393+
return flushImmediate(ret, true);
481394
}
482395

483396
template <GFXCORE_FAMILY gfxCoreFamily>
@@ -494,14 +407,19 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendImageCopyToMemo
494407
}
495408
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendImageCopyToMemory(dstPtr, hSrcImage, pSrcRegion, hSignalEvent,
496409
numWaitEvents, phWaitEvents);
497-
if (ret == ZE_RESULT_SUCCESS) {
410+
return flushImmediate(ret, true);
411+
}
412+
413+
template <GFXCORE_FAMILY gfxCoreFamily>
414+
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::flushImmediate(ze_result_t inputRet, bool performMigration) {
415+
if (inputRet == ZE_RESULT_SUCCESS) {
498416
if (this->isFlushTaskSubmissionEnabled) {
499-
executeCommandListImmediateWithFlushTask(true);
417+
inputRet = executeCommandListImmediateWithFlushTask(performMigration);
500418
} else {
501-
executeCommandListImmediate(true);
419+
inputRet = executeCommandListImmediate(performMigration);
502420
}
503421
}
504-
return ret;
422+
return inputRet;
505423
}
506424

507425
} // namespace L0

shared/source/command_container/cmdcontainer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class CommandContainer : public NonCopyableOrMovableClass {
104104
}
105105
HeapContainer sshAllocations;
106106

107-
bool getFlushTaskUsedForImmediate() { return isFlushTaskUsedForImmediate; }
107+
bool getFlushTaskUsedForImmediate() const { return isFlushTaskUsedForImmediate; }
108108
void setFlushTaskUsedForImmediate(bool flushTaskUsedForImmediate) { isFlushTaskUsedForImmediate = flushTaskUsedForImmediate; }
109109

110110
protected:

0 commit comments

Comments
 (0)