@@ -451,6 +451,17 @@ class RTLDeviceInfoTy {
451
451
HSALifetime HSA; // First field => constructed first and destructed last
452
452
std::vector<std::list<FuncOrGblEntryTy>> FuncGblEntries;
453
453
454
+ struct QueueDeleter {
455
+ void operator ()(hsa_queue_t *Q) {
456
+ if (Q) {
457
+ hsa_status_t Err = hsa_queue_destroy (Q);
458
+ if (Err != HSA_STATUS_SUCCESS) {
459
+ DP (" Error destroying hsa queue: %s\n " , get_error_string (Err));
460
+ }
461
+ }
462
+ }
463
+ };
464
+
454
465
public:
455
466
// load binary populates symbol tables and mutates various global state
456
467
// run uses those symbol tables
@@ -460,7 +471,8 @@ class RTLDeviceInfoTy {
460
471
461
472
// GPU devices
462
473
std::vector<hsa_agent_t > HSAAgents;
463
- std::vector<hsa_queue_t *> HSAQueues; // one per gpu
474
+ std::vector<std::unique_ptr<hsa_queue_t , QueueDeleter>>
475
+ HSAQueues; // one per gpu
464
476
465
477
// CPUs
466
478
std::vector<hsa_agent_t > CPUAgents;
@@ -773,10 +785,6 @@ class RTLDeviceInfoTy {
773
785
return ;
774
786
}
775
787
776
- for (int i = 0 ; i < NumberOfDevices; i++) {
777
- HSAQueues[i] = nullptr ;
778
- }
779
-
780
788
for (int i = 0 ; i < NumberOfDevices; i++) {
781
789
uint32_t queue_size = 0 ;
782
790
{
@@ -792,12 +800,16 @@ class RTLDeviceInfoTy {
792
800
}
793
801
}
794
802
795
- hsa_status_t rc = hsa_queue_create (
796
- HSAAgents[i], queue_size, HSA_QUEUE_TYPE_MULTI, callbackQueue, NULL ,
797
- UINT32_MAX, UINT32_MAX, &HSAQueues[i]);
798
- if (rc != HSA_STATUS_SUCCESS) {
799
- DP (" Failed to create HSA queue %d\n " , i);
800
- return ;
803
+ {
804
+ hsa_queue_t *Q = nullptr ;
805
+ hsa_status_t rc =
806
+ hsa_queue_create (HSAAgents[i], queue_size, HSA_QUEUE_TYPE_MULTI,
807
+ callbackQueue, NULL , UINT32_MAX, UINT32_MAX, &Q);
808
+ if (rc != HSA_STATUS_SUCCESS) {
809
+ DP (" Failed to create HSA queue %d\n " , i);
810
+ return ;
811
+ }
812
+ HSAQueues[i].reset (Q);
801
813
}
802
814
803
815
deviceStateStore[i] = {nullptr , 0 };
@@ -2149,7 +2161,7 @@ int32_t __tgt_rtl_run_target_team_region_locked(
2149
2161
2150
2162
// Run on the device.
2151
2163
{
2152
- hsa_queue_t *queue = DeviceInfo.HSAQueues [device_id];
2164
+ hsa_queue_t *queue = DeviceInfo.HSAQueues [device_id]. get () ;
2153
2165
if (!queue) {
2154
2166
return OFFLOAD_FAIL;
2155
2167
}
0 commit comments