Skip to content

Commit 478a576

Browse files
authored
[SYCL] Modify L0 plugin support for copy engines to address scenario when main copy engine is not available (#5395)
Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam@intel.com>
1 parent df83271 commit 478a576

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,15 +1404,29 @@ pi_result _pi_queue::getOrCreateCopyCommandQueue(
14041404

14051405
// Ze copy command queue is not available at 'Index'. So we create it below.
14061406
ZeStruct<ze_command_queue_desc_t> ZeCommandQueueDesc;
1407-
ZeCommandQueueDesc.ordinal = (Index == 0) ? Device->ZeMainCopyQueueGroupIndex
1408-
: Device->ZeLinkCopyQueueGroupIndex;
14091407
// There are two copy queues: main copy queues and link copy queues.
1410-
// ZeCommandQueueDesc.index is the index into the list of main (or link)
1411-
// copy queues. (Index == 0) means we are using the main copy queue and
1412-
// ZeCommandQueueDesc.index is set to 0. Otherwise, we use one of the link
1413-
// copy queues and ZeCommandQueueDesc.index is set to (Index - 1) as Index
1414-
// for link copy engines in the overall list starts from 1.
1415-
ZeCommandQueueDesc.index = (Index == 0) ? 0 : Index - 1;
1408+
// Index is the 'index' into the overall list of copy queues
1409+
// (one queue per copy engine).
1410+
// ZeCommandQueueDesc.ordinal specifies the copy group (main or link)
1411+
// ZeCommandQueueDesc.index specifies the copy queue/engine within a group
1412+
// Following are possible scenarios:
1413+
// 1. (Index == 0) and main copy engine is available:
1414+
// ZeCommandQueueDesc.ordinal = Device->ZeMainCopyQueueGroupIndex
1415+
// ZeCommandQueueDesc.index = 0
1416+
// 2. (Index == 0) and main copy engine is not available:
1417+
// ZeCommandQueueDesc.ordinal = Device->ZeLinkCopyQueueGroupIndex
1418+
// ZeCommandQueueDesc.index = 0
1419+
// 3. (Index != 0) and main copy engine is available:
1420+
// ZeCommandQueueDesc.ordinal = Device->ZeLinkCopyQueueGroupIndex
1421+
// ZeCommandQueueDesc.index = Index - 1
1422+
// 4. (Index != 0) and main copy engine is not available:
1423+
// ZeCommandQueueDesc.ordinal = Device->ZeLinkCopyQueueGroupIndex
1424+
// ZeCommandQueueDesc.index = Index
1425+
ZeCommandQueueDesc.ordinal = (Index == 0 && Device->hasMainCopyEngine())
1426+
? Device->ZeMainCopyQueueGroupIndex
1427+
: Device->ZeLinkCopyQueueGroupIndex;
1428+
ZeCommandQueueDesc.index =
1429+
(Index != 0 && Device->hasMainCopyEngine()) ? Index - 1 : Index;
14161430
zePrint("NOTE: Copy Engine ZeCommandQueueDesc.ordinal = %d, "
14171431
"ZeCommandQueueDesc.index = %d\n",
14181432
ZeCommandQueueDesc.ordinal, ZeCommandQueueDesc.index);
@@ -1448,13 +1462,18 @@ _pi_queue::getZeCopyCommandQueue(int *CopyQueueIndex,
14481462
LowerCopyQueueIndex = std::max(0, LowerCopyQueueIndex);
14491463
UpperCopyQueueIndex = std::min(UpperCopyQueueIndex, n - 1);
14501464

1451-
// If there is only one copy queue, it is the main copy queue, which is the
1452-
// first, and only entry in ZeCopyCommandQueues.
1465+
// If there is only one copy queue, it is the main copy queue (if available),
1466+
// or the first link copy queue in ZeCopyCommandQueues.
14531467
if (n == 1) {
14541468
*CopyQueueIndex = 0;
1455-
if (CopyQueueGroupIndex)
1456-
*CopyQueueGroupIndex = Device->ZeMainCopyQueueGroupIndex;
1469+
if (CopyQueueGroupIndex) {
1470+
if (Device->hasMainCopyEngine())
1471+
*CopyQueueGroupIndex = Device->ZeMainCopyQueueGroupIndex;
1472+
else
1473+
*CopyQueueGroupIndex = Device->ZeLinkCopyQueueGroupIndex;
1474+
}
14571475
zePrint("Note: CopyQueueIndex = %d\n", *CopyQueueIndex);
1476+
zePrint("Note: CopyQueueGroupIndex = %d\n", *CopyQueueGroupIndex);
14581477
ze_command_queue_handle_t ZeCopyCommandQueue = nullptr;
14591478
if (getOrCreateCopyCommandQueue(0, ZeCopyCommandQueue))
14601479
return nullptr;

0 commit comments

Comments
 (0)