@@ -1404,15 +1404,29 @@ pi_result _pi_queue::getOrCreateCopyCommandQueue(
1404
1404
1405
1405
// Ze copy command queue is not available at 'Index'. So we create it below.
1406
1406
ZeStruct<ze_command_queue_desc_t > ZeCommandQueueDesc;
1407
- ZeCommandQueueDesc.ordinal = (Index == 0 ) ? Device->ZeMainCopyQueueGroupIndex
1408
- : Device->ZeLinkCopyQueueGroupIndex ;
1409
1407
// 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;
1416
1430
zePrint (" NOTE: Copy Engine ZeCommandQueueDesc.ordinal = %d, "
1417
1431
" ZeCommandQueueDesc.index = %d\n " ,
1418
1432
ZeCommandQueueDesc.ordinal , ZeCommandQueueDesc.index );
@@ -1448,13 +1462,18 @@ _pi_queue::getZeCopyCommandQueue(int *CopyQueueIndex,
1448
1462
LowerCopyQueueIndex = std::max (0 , LowerCopyQueueIndex);
1449
1463
UpperCopyQueueIndex = std::min (UpperCopyQueueIndex, n - 1 );
1450
1464
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.
1453
1467
if (n == 1 ) {
1454
1468
*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
+ }
1457
1475
zePrint (" Note: CopyQueueIndex = %d\n " , *CopyQueueIndex);
1476
+ zePrint (" Note: CopyQueueGroupIndex = %d\n " , *CopyQueueGroupIndex);
1458
1477
ze_command_queue_handle_t ZeCopyCommandQueue = nullptr ;
1459
1478
if (getOrCreateCopyCommandQueue (0 , ZeCopyCommandQueue))
1460
1479
return nullptr ;
0 commit comments