diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h index 6d45542150..c5a66a0517 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/runtime.h @@ -94,8 +94,7 @@ class Runtime { }; /// @brief Open connection to kernel driver and increment reference count. - /// @retval True if the connection to kernel driver is successfully opened. - static bool Acquire(); + static hsa_status_t Acquire(); /// @brief Checks if connection to kernel driver is opened. /// @retval True if the connection to kernel driver is opened. @@ -108,8 +107,7 @@ class Runtime { static Runtime* runtime_singleton_; /// @brief Decrement reference count and close connection to kernel driver. - /// @retval True if reference count is larger than 0. - bool Release(); + hsa_status_t Release(); /// @brief Insert agent into agent list ::agents_. /// @param [in] agent Pointer to the agent object. @@ -362,7 +360,7 @@ class Runtime { ~Runtime() {} /// @brief Open connection to kernel driver. - void Load(); + hsa_status_t Load(); /// @brief Close connection to kernel driver and cleanup resources. void Unload(); diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa.cpp index e6acd09ef9..054ff32cbc 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa.cpp @@ -195,15 +195,11 @@ namespace HSA { //---------------------------------------------------------------------------// // Init/Shutdown routines //---------------------------------------------------------------------------// -hsa_status_t hsa_init() { - if (core::Runtime::runtime_singleton_->Acquire()) return HSA_STATUS_SUCCESS; - return HSA_STATUS_ERROR_REFCOUNT_OVERFLOW; -} +hsa_status_t hsa_init() { return core::Runtime::runtime_singleton_->Acquire(); } hsa_status_t hsa_shut_down() { IS_OPEN(); - if (core::Runtime::runtime_singleton_->Release()) return HSA_STATUS_SUCCESS; - return HSA_STATUS_ERROR_NOT_INITIALIZED; + return core::Runtime::runtime_singleton_->Release(); } //---------------------------------------------------------------------------// diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index 9229cedb04..9adf5476bc 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -89,9 +89,9 @@ class RuntimeCleanup { static RuntimeCleanup cleanup_at_unload_; -bool Runtime::Acquire() { +hsa_status_t Runtime::Acquire() { // Check to see if HSA has been cleaned up (process exit) - if (!loaded) return false; + if (!loaded) return HSA_STATUS_ERROR_OUT_OF_RESOURCES; // Handle initialization races ScopedAcquire boot(&bootstrap_lock_); @@ -104,22 +104,26 @@ bool Runtime::Acquire() { ScopedAcquire lock(&runtime_singleton_->kernel_lock_); if (runtime_singleton_->ref_count_ == INT32_MAX) { - return false; + return HSA_STATUS_ERROR_REFCOUNT_OVERFLOW; } runtime_singleton_->ref_count_++; if (runtime_singleton_->ref_count_ == 1) { - runtime_singleton_->Load(); + hsa_status_t status = runtime_singleton_->Load(); + + if (status != HSA_STATUS_SUCCESS) { + return HSA_STATUS_ERROR_OUT_OF_RESOURCES; + } } - return true; + return HSA_STATUS_SUCCESS; } -bool Runtime::Release() { +hsa_status_t Runtime::Release() { ScopedAcquire lock(&kernel_lock_); if (ref_count_ == 0) { - return false; + return HSA_STATUS_ERROR_NOT_INITIALIZED; } if (ref_count_ == 1) { @@ -129,7 +133,7 @@ bool Runtime::Release() { ref_count_--; - return true; + return HSA_STATUS_SUCCESS; } bool Runtime::IsOpen() { @@ -808,13 +812,13 @@ Runtime::Runtime() #endif } -void Runtime::Load() { +hsa_status_t Runtime::Load() { flag_.Refresh(); g_use_interrupt_wait = flag_.enable_interrupt(); if (!amd::Load()) { - return; + return HSA_STATUS_ERROR_OUT_OF_RESOURCES; } loader_ = amd::hsa::loader::Loader::Create(&loader_context_); @@ -826,10 +830,15 @@ void Runtime::Load() { LoadTools(); for (core::Agent* agent : gpu_agents_) { - const hsa_status_t stat = + hsa_status_t status = reinterpret_cast(agent)->PostToolsInit(); - assert(HSA_STATUS_SUCCESS == stat); + + if (status != HSA_STATUS_SUCCESS) { + return status; + } } + + return HSA_STATUS_SUCCESS; } void Runtime::Unload() {