Skip to content

Commit fa382d6

Browse files
[SYCL][PI][L0] Close and submit batch immediately when Queue is empty. (#3552)
This change causes executeCommandList to close a command list and immediately execute it when it has determined that the last command submitted to the queue has already been completed. Updates code to only consider whether the Queue is empty when doing dynamic batching. Fixed size batching will not consider this and give user the exact batching specified. This change-set also updates the dynamic batching unit test.
1 parent d4b66bd commit fa382d6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,23 @@ pi_result _pi_queue::executeCommandList(ze_command_list_handle_t ZeCommandList,
843843
ze_fence_handle_t ZeFence,
844844
pi_event Event, bool IsBlocking,
845845
bool OKToBatchCommand) {
846+
// If the current LastCommandEvent is the nullptr, then it means
847+
// either that no command has ever been issued to the queue
848+
// or it means that the LastCommandEvent has been signalled and
849+
// therefore that this Queue is idle.
850+
bool CurrentlyEmpty = this->LastCommandEvent == nullptr;
851+
846852
this->LastCommandEvent = Event;
847853

848-
if (OKToBatchCommand && this->isBatchingAllowed()) {
854+
// Batch if allowed to, but don't batch if we know there are no kernels
855+
// from this queue that are currently executing. This is intended to gets
856+
// kernels started as soon as possible when there are no kernels from this
857+
// queue awaiting execution, while allowing batching to occur when there
858+
// are kernels already executing. Also, if we are using fixed size batching,
859+
// as indicated by !UseDynamicBatching, then just ignore CurrentlyEmpty
860+
// as we want to strictly follow the batching the user specified.
861+
if (OKToBatchCommand && this->isBatchingAllowed() &&
862+
(!UseDynamicBatching || !CurrentlyEmpty)) {
849863
if (this->ZeOpenCommandList != nullptr &&
850864
this->ZeOpenCommandList != ZeCommandList)
851865
die("executeCommandList: ZeOpenCommandList should be equal to"

sycl/test/on-device/plugins/level_zero_dynamic_batch_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// CKALL: Test Pass
2929
// CKALL: Test Pass
3030
// CKALL: Test Pass
31-
// CKDYN: Lowering QueueBatchSize to 3
31+
// CKDYN: Lowering QueueBatchSize to 2
3232
// CKDYN-NOT: Lowering QueueBatchSize
3333
// CKALL: Test Pass
3434
// CKALL: Test Pass

0 commit comments

Comments
 (0)