diff --git a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp b/openmp/libomptarget/plugins/amdgpu/impl/system.cpp --- a/openmp/libomptarget/plugins/amdgpu/impl/system.cpp +++ b/openmp/libomptarget/plugins/amdgpu/impl/system.cpp @@ -356,12 +356,8 @@ DEBUG_PRINT("Initializing HSA..."); hsa_status_t err = hsa_init(); if (err != HSA_STATUS_SUCCESS) { - printf("[%s:%d] %s failed: %s\n", __FILE__, __LINE__, - "Initializing the hsa runtime", get_error_string(err)); return err; } - if (err != HSA_STATUS_SUCCESS) - return err; err = init_compute_and_memory(); if (err != HSA_STATUS_SUCCESS) diff --git a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp --- a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp +++ b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp @@ -436,13 +436,14 @@ /// Class containing all the device information class RTLDeviceInfoTy { std::vector> FuncGblEntries; + bool HSAInitializeSucceeded = false; public: // load binary populates symbol tables and mutates various global state // run uses those symbol tables std::shared_timed_mutex load_run_lock; - int NumberOfDevices; + int NumberOfDevices = 0; // GPU devices std::vector HSAAgents; @@ -688,7 +689,9 @@ DP("Start initializing HSA-ATMI\n"); hsa_status_t err = core::atl_init_gpu_context(); - if (err != HSA_STATUS_SUCCESS) { + if (err == HSA_STATUS_SUCCESS) { + HSAInitializeSucceeded = true; + } else { DP("Error when initializing HSA-ATMI\n"); return; } @@ -791,6 +794,10 @@ ~RTLDeviceInfoTy() { DP("Finalizing the HSA-ATMI DeviceInfo.\n"); + if (!HSAInitializeSucceeded) { + // Then none of these can have been set up and they can't be torn down + return; + } // Run destructors on types that use HSA before // atmi_finalize removes access to it deviceStateStore.clear();