From 1e100a33807309fb5ff98cdbf67a1837f7d00da7 Mon Sep 17 00:00:00 2001 From: Kevin B Smith Date: Thu, 15 Apr 2021 15:53:54 -0700 Subject: [PATCH 1/2] [SYCL][PI][L0]Close and submit batch immediately when Queue is empty. This change causes executeCommandList to close a command list and immediately execute it when it has determined that the last command submited to the queue has already been completed. --- sycl/plugins/level_zero/pi_level_zero.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index 2b5270afb0fb3..ba9bac24caf5b 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -843,9 +843,20 @@ pi_result _pi_queue::executeCommandList(ze_command_list_handle_t ZeCommandList, ze_fence_handle_t ZeFence, pi_event Event, bool IsBlocking, bool OKToBatchCommand) { + // If the current LastCommandEvent is the nullptr, then it means + // either that no command has ever been issued to the queue + // or it means that the LastCommandEvent has been signalled and + // therefore that this Queue is idle. + bool CurrentlyEmpty = this->LastCommandEvent == nullptr; + this->LastCommandEvent = Event; - if (OKToBatchCommand && this->isBatchingAllowed()) { + // Batch if allowed to, but don't batch if we know there are no kernels + // from this queue that are currently executing. This is intended to gets + // kernels started as soon as possible when there are no kernels from this + // queue awaiting execution, while allowing batching to occur when there + // are kernels already executing. + if (OKToBatchCommand && this->isBatchingAllowed() && !CurrentlyEmpty) { if (this->ZeOpenCommandList != nullptr && this->ZeOpenCommandList != ZeCommandList) die("executeCommandList: ZeOpenCommandList should be equal to" From e0f61ca60975b930566c5b5b276ac265502271f6 Mon Sep 17 00:00:00 2001 From: Kevin B Smith Date: Fri, 16 Apr 2021 14:02:45 -0700 Subject: [PATCH 2/2] Updates code to only consider whether the Queue is empty when doing dynamic batching. Fixed size atching will not consider this and give user the exact batching specified. This change-set also updates the dynamic batching unit test. --- sycl/plugins/level_zero/pi_level_zero.cpp | 7 +++++-- .../on-device/plugins/level_zero_dynamic_batch_test.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index ba9bac24caf5b..5469818626877 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -855,8 +855,11 @@ pi_result _pi_queue::executeCommandList(ze_command_list_handle_t ZeCommandList, // from this queue that are currently executing. This is intended to gets // kernels started as soon as possible when there are no kernels from this // queue awaiting execution, while allowing batching to occur when there - // are kernels already executing. - if (OKToBatchCommand && this->isBatchingAllowed() && !CurrentlyEmpty) { + // are kernels already executing. Also, if we are using fixed size batching, + // as indicated by !UseDynamicBatching, then just ignore CurrentlyEmpty + // as we want to strictly follow the batching the user specified. + if (OKToBatchCommand && this->isBatchingAllowed() && + (!UseDynamicBatching || !CurrentlyEmpty)) { if (this->ZeOpenCommandList != nullptr && this->ZeOpenCommandList != ZeCommandList) die("executeCommandList: ZeOpenCommandList should be equal to" diff --git a/sycl/test/on-device/plugins/level_zero_dynamic_batch_test.cpp b/sycl/test/on-device/plugins/level_zero_dynamic_batch_test.cpp index b89222e71dd0c..bc07034e05110 100644 --- a/sycl/test/on-device/plugins/level_zero_dynamic_batch_test.cpp +++ b/sycl/test/on-device/plugins/level_zero_dynamic_batch_test.cpp @@ -28,7 +28,7 @@ // CKALL: Test Pass // CKALL: Test Pass // CKALL: Test Pass -// CKDYN: Lowering QueueBatchSize to 3 +// CKDYN: Lowering QueueBatchSize to 2 // CKDYN-NOT: Lowering QueueBatchSize // CKALL: Test Pass // CKALL: Test Pass