Skip to content

Commit 6276f1b

Browse files
adamfidelreble
andauthored
[SYCL][Graph][UR] Elide second barrier in finalizeCommandBuffer when possible (#20278)
Currently when finalizing an out-of-order command buffer, there are two barriers: 1. An initial barrier before all of the event resets for the sync points 2. A final barrier after all of the event resets for the sync points However, when there are no sync points, then the second barrier is unnecessary. This PR removes the second barrier when there are no sync points. --------- Co-authored-by: Pablo Reble <[email protected]>
1 parent 5c53e77 commit 6276f1b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

unified-runtime/source/adapters/level_zero/v2/command_buffer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,24 @@ ur_result_t ur_exp_command_buffer_handle_t_::finalizeCommandBuffer() {
131131
auto commandListLocked = commandListManager.lock();
132132
UR_ASSERT(!isFinalized, UR_RESULT_ERROR_INVALID_OPERATION);
133133

134+
size_t numEventResets = 0;
135+
134136
if (!isInOrder) {
135137
ZE2UR_CALL(zeCommandListAppendBarrier,
136138
(commandListLocked->getZeCommandList(), nullptr, 0, nullptr));
137139
for (size_t i = 0; i < usedSyncPoints.size(); ++i) {
138140
if (!usedSyncPoints[i]) {
139141
continue;
140142
}
143+
++numEventResets;
141144
ZE2UR_CALL(
142145
zeCommandListAppendEventReset,
143146
(commandListLocked->getZeCommandList(), syncPoints[i]->getZeEvent()));
144147
}
145-
ZE2UR_CALL(zeCommandListAppendBarrier,
146-
(commandListLocked->getZeCommandList(), nullptr, 0, nullptr));
148+
149+
if (numEventResets)
150+
ZE2UR_CALL(zeCommandListAppendBarrier,
151+
(commandListLocked->getZeCommandList(), nullptr, 0, nullptr));
147152
}
148153
// Close the command lists and have them ready for dispatch.
149154
ZE2UR_CALL(zeCommandListClose, (commandListLocked->getZeCommandList()));

0 commit comments

Comments
 (0)