From 53cd59e689dd0d647713cfe357e703551ce3c22f Mon Sep 17 00:00:00 2001 From: Jay Cornwall Date: Mon, 22 Aug 2016 17:27:00 -0500 Subject: [PATCH] Propagate errors from hsaKmtOpenKFD back to hsa_init Errors are otherwise silently ignored and hsa_init completes successfully. Change-Id: Ib1b7dbd7a65d40f869cdbb2792fa97132873d3d7 [ROCm/ROCR-Runtime commit: 0c9f96cfa4254b9932c5a4e9bd22b621f404469b] --- .../runtime/hsa-runtime/core/inc/runtime.h | 8 ++--- .../runtime/hsa-runtime/core/runtime/hsa.cpp | 8 ++--- .../hsa-runtime/core/runtime/runtime.cpp | 33 ++++++++++++------- 3 files changed, 26 insertions(+), 23 deletions(-) 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() {