@@ -415,20 +415,6 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *CallStr,
415
415
if (!(condition)) \
416
416
return error;
417
417
418
- // Destroy all the command lists associated with this device.
419
- // This is required when destructing the _pi_device object.
420
- // During the piTearDown process, platforms and root devices are
421
- // destroyed automatically regardless of their reference counts.
422
- // So, this destructor should explicitly call zeCommandListDestroy
423
- // to avoid memory leaks.
424
- _pi_device::~_pi_device () {
425
- std::lock_guard<std::mutex> Lock (ZeCommandListCacheMutex);
426
- for (ze_command_list_handle_t &ZeCommandList : ZeCommandListCache) {
427
- if (ZeCommandList)
428
- ZE_CALL_NOCHECK (zeCommandListDestroy (ZeCommandList));
429
- }
430
- }
431
-
432
418
// This helper function increments the reference counter of the Queue
433
419
// without guarding with a lock.
434
420
// It is the caller's responsibility to make sure the lock is acquired
@@ -522,6 +508,12 @@ pi_result _pi_context::finalize() {
522
508
523
509
// Destroy the command list used for initializations
524
510
ZE_CALL (zeCommandListDestroy (ZeCommandListInit));
511
+
512
+ std::lock_guard<std::mutex> Lock (ZeCommandListCacheMutex);
513
+ for (ze_command_list_handle_t &ZeCommandList : ZeCommandListCache) {
514
+ if (ZeCommandList)
515
+ ZE_CALL (zeCommandListDestroy (ZeCommandList));
516
+ }
525
517
return PI_SUCCESS;
526
518
}
527
519
@@ -534,8 +526,8 @@ _pi_queue::resetCommandListFenceEntry(ze_command_list_handle_t ZeCommandList,
534
526
ZE_CALL (zeFenceReset (this ->ZeCommandListFenceMap [ZeCommandList]));
535
527
ZE_CALL (zeCommandListReset (ZeCommandList));
536
528
if (MakeAvailable) {
537
- std::lock_guard<std::mutex> lock (this ->Device ->ZeCommandListCacheMutex );
538
- this ->Device ->ZeCommandListCache .push_back (ZeCommandList);
529
+ std::lock_guard<std::mutex> lock (this ->Context ->ZeCommandListCacheMutex );
530
+ this ->Context ->ZeCommandListCache .push_back (ZeCommandList);
539
531
}
540
532
541
533
return PI_SUCCESS;
@@ -559,7 +551,7 @@ static const pi_uint32 ZeCommandListBatchSize = [] {
559
551
560
552
// Retrieve an available command list to be used in a PI call
561
553
// Caller must hold a lock on the Queue passed in.
562
- pi_result _pi_device ::getAvailableCommandList (
554
+ pi_result _pi_context ::getAvailableCommandList (
563
555
pi_queue Queue, ze_command_list_handle_t *ZeCommandList,
564
556
ze_fence_handle_t *ZeFence, bool AllowBatching) {
565
557
// First see if there is an command-list open for batching commands
@@ -595,10 +587,10 @@ pi_result _pi_device::getAvailableCommandList(
595
587
{
596
588
// Make sure to acquire the lock before checking the size, or there
597
589
// will be a race condition.
598
- std::lock_guard<std::mutex> lock (Queue->Device ->ZeCommandListCacheMutex );
590
+ std::lock_guard<std::mutex> lock (Queue->Context ->ZeCommandListCacheMutex );
599
591
600
- if (Queue->Device ->ZeCommandListCache .size () > 0 ) {
601
- *ZeCommandList = Queue->Device ->ZeCommandListCache .front ();
592
+ if (Queue->Context ->ZeCommandListCache .size () > 0 ) {
593
+ *ZeCommandList = Queue->Context ->ZeCommandListCache .front ();
602
594
auto it = Queue->ZeCommandListFenceMap .find (*ZeCommandList);
603
595
if (it != Queue->ZeCommandListFenceMap .end ()) {
604
596
*ZeFence = it->second ;
@@ -610,7 +602,7 @@ pi_result _pi_device::getAvailableCommandList(
610
602
ZE_CALL (zeFenceCreate (Queue->ZeCommandQueue , &ZeFenceDesc, ZeFence));
611
603
Queue->ZeCommandListFenceMap [*ZeCommandList] = *ZeFence;
612
604
}
613
- Queue->Device ->ZeCommandListCache .pop_front ();
605
+ Queue->Context ->ZeCommandListCache .pop_front ();
614
606
return PI_SUCCESS;
615
607
}
616
608
}
@@ -636,12 +628,14 @@ pi_result _pi_device::getAvailableCommandList(
636
628
// command lists we can create.
637
629
// Once created, this command list & fence are added to the command list fence
638
630
// map.
639
- if ((*ZeCommandList == nullptr ) && (this ->Platform ->ZeGlobalCommandListCount <
640
- this ->Platform ->ZeMaxCommandListCache )) {
641
- ZE_CALL (zeCommandListCreate (Queue->Context ->ZeContext , ZeDevice,
642
- &ZeCommandListDesc, ZeCommandList));
631
+ if ((*ZeCommandList == nullptr ) &&
632
+ (Queue->Device ->Platform ->ZeGlobalCommandListCount <
633
+ Queue->Device ->Platform ->ZeMaxCommandListCache )) {
634
+ ZE_CALL (zeCommandListCreate (Queue->Context ->ZeContext ,
635
+ Queue->Device ->ZeDevice , &ZeCommandListDesc,
636
+ ZeCommandList));
643
637
// Increments the total number of command lists created on this platform.
644
- this ->Platform ->ZeGlobalCommandListCount ++;
638
+ Queue-> Device ->Platform ->ZeGlobalCommandListCount ++;
645
639
ZE_CALL (zeFenceCreate (Queue->ZeCommandQueue , &ZeFenceDesc, ZeFence));
646
640
Queue->ZeCommandListFenceMap .insert (
647
641
std::pair<ze_command_list_handle_t , ze_fence_handle_t >(*ZeCommandList,
@@ -3594,8 +3588,8 @@ piEnqueueKernelLaunch(pi_queue Queue, pi_kernel Kernel, pi_uint32 WorkDim,
3594
3588
// Get a new command list to be used on this call
3595
3589
ze_command_list_handle_t ZeCommandList = nullptr ;
3596
3590
ze_fence_handle_t ZeFence = nullptr ;
3597
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
3598
- &ZeFence, true ))
3591
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
3592
+ &ZeFence, true ))
3599
3593
return Res;
3600
3594
3601
3595
ze_event_handle_t ZeEvent = nullptr ;
@@ -4111,8 +4105,8 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
4111
4105
// Get a new command list to be used on this call
4112
4106
ze_command_list_handle_t ZeCommandList = nullptr ;
4113
4107
ze_fence_handle_t ZeFence = nullptr ;
4114
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
4115
- &ZeFence))
4108
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
4109
+ &ZeFence))
4116
4110
return Res;
4117
4111
4118
4112
ze_event_handle_t ZeEvent = nullptr ;
@@ -4188,8 +4182,8 @@ enqueueMemCopyHelper(pi_command_type CommandType, pi_queue Queue, void *Dst,
4188
4182
// Get a new command list to be used on this call
4189
4183
ze_command_list_handle_t ZeCommandList = nullptr ;
4190
4184
ze_fence_handle_t ZeFence = nullptr ;
4191
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
4192
- &ZeFence))
4185
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
4186
+ &ZeFence))
4193
4187
return Res;
4194
4188
4195
4189
ze_event_handle_t ZeEvent = nullptr ;
@@ -4245,8 +4239,8 @@ static pi_result enqueueMemCopyRectHelper(
4245
4239
// Get a new command list to be used on this call
4246
4240
ze_command_list_handle_t ZeCommandList = nullptr ;
4247
4241
ze_fence_handle_t ZeFence = nullptr ;
4248
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
4249
- &ZeFence))
4242
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
4243
+ &ZeFence))
4250
4244
return Res;
4251
4245
4252
4246
ze_event_handle_t ZeEvent = nullptr ;
@@ -4412,8 +4406,8 @@ enqueueMemFillHelper(pi_command_type CommandType, pi_queue Queue, void *Ptr,
4412
4406
// Get a new command list to be used on this call
4413
4407
ze_command_list_handle_t ZeCommandList = nullptr ;
4414
4408
ze_fence_handle_t ZeFence = nullptr ;
4415
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
4416
- &ZeFence))
4409
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
4410
+ &ZeFence))
4417
4411
return Res;
4418
4412
4419
4413
ze_event_handle_t ZeEvent = nullptr ;
@@ -4538,8 +4532,8 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Buffer,
4538
4532
std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4539
4533
4540
4534
// For discrete devices we need a command list
4541
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
4542
- &ZeFence))
4535
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
4536
+ &ZeFence))
4543
4537
return Res;
4544
4538
4545
4539
// Set the commandlist in the event
@@ -4638,8 +4632,8 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem MemObj, void *MappedPtr,
4638
4632
// Lock automatically releases when this goes out of scope.
4639
4633
std::lock_guard<std::mutex> lock (Queue->PiQueueMutex );
4640
4634
4641
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
4642
- &ZeFence))
4635
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
4636
+ &ZeFence))
4643
4637
return Res;
4644
4638
4645
4639
// Set the commandlist in the event
@@ -4750,8 +4744,8 @@ enqueueMemImageCommandHelper(pi_command_type CommandType, pi_queue Queue,
4750
4744
// Get a new command list to be used on this call
4751
4745
ze_command_list_handle_t ZeCommandList = nullptr ;
4752
4746
ze_fence_handle_t ZeFence = nullptr ;
4753
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
4754
- &ZeFence))
4747
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
4748
+ &ZeFence))
4755
4749
return Res;
4756
4750
4757
4751
ze_event_handle_t ZeEvent = nullptr ;
@@ -5357,8 +5351,8 @@ pi_result piextUSMEnqueuePrefetch(pi_queue Queue, const void *Ptr, size_t Size,
5357
5351
// Get a new command list to be used on this call
5358
5352
ze_command_list_handle_t ZeCommandList = nullptr ;
5359
5353
ze_fence_handle_t ZeFence = nullptr ;
5360
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
5361
- &ZeFence))
5354
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
5355
+ &ZeFence))
5362
5356
return Res;
5363
5357
5364
5358
// TODO: do we need to create a unique command type for this?
@@ -5413,8 +5407,8 @@ pi_result piextUSMEnqueueMemAdvise(pi_queue Queue, const void *Ptr,
5413
5407
// Get a new command list to be used on this call
5414
5408
ze_command_list_handle_t ZeCommandList = nullptr ;
5415
5409
ze_fence_handle_t ZeFence = nullptr ;
5416
- if (auto Res = Queue->Device ->getAvailableCommandList (Queue, &ZeCommandList,
5417
- &ZeFence))
5410
+ if (auto Res = Queue->Context ->getAvailableCommandList (Queue, &ZeCommandList,
5411
+ &ZeFence))
5418
5412
return Res;
5419
5413
5420
5414
// TODO: do we need to create a unique command type for this?
0 commit comments