From ef3cf8b6a06add393797996cc5a8d704d7000c25 Mon Sep 17 00:00:00 2001 From: Xiaozhu Meng Date: Fri, 21 Jan 2022 15:30:30 -0600 Subject: [PATCH 1/2] Ensure hsa_api_ is initialized with HSA public APIs by default and then hsa_api_ can be reset with provided table --- src/core/rocprofiler.cpp | 2 +- src/util/hsa_rsrc_factory.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/rocprofiler.cpp b/src/core/rocprofiler.cpp index b50bd51d..9b9cc5dd 100644 --- a/src/core/rocprofiler.cpp +++ b/src/core/rocprofiler.cpp @@ -111,7 +111,7 @@ decltype(hsa_executable_destroy)* hsa_executable_destroy_fn; ::HsaApiTable* kHsaApiTable; void SaveHsaApi(::HsaApiTable* table) { - util::HsaRsrcFactory::InitHsaApiTable(table); + util::HsaRsrcFactory::Instance().InitHsaApiTable(table); kHsaApiTable = table; hsa_queue_create_fn = table->core_->hsa_queue_create_fn; diff --git a/src/util/hsa_rsrc_factory.cpp b/src/util/hsa_rsrc_factory.cpp index 9d980312..d5fb5634 100644 --- a/src/util/hsa_rsrc_factory.cpp +++ b/src/util/hsa_rsrc_factory.cpp @@ -184,7 +184,6 @@ HsaRsrcFactory::~HsaRsrcFactory() { void HsaRsrcFactory::InitHsaApiTable(HsaApiTable* table) { std::lock_guard lck(mutex_); - if (hsa_api_.hsa_init == NULL) { if (table != NULL) { hsa_api_.hsa_init = table->core_->hsa_init_fn; hsa_api_.hsa_shut_down = table->core_->hsa_shut_down_fn; @@ -268,7 +267,6 @@ void HsaRsrcFactory::InitHsaApiTable(HsaApiTable* table) { hsa_api_.hsa_amd_profiling_get_async_copy_time = hsa_amd_profiling_get_async_copy_time; hsa_api_.hsa_amd_profiling_get_dispatch_time = hsa_amd_profiling_get_dispatch_time; } - } } hsa_status_t HsaRsrcFactory::LoadAqlProfileLib(aqlprofile_pfn_t* api) { From cfbbeaf3fa51566d11f7aaa0b69c26d46b874f7e Mon Sep 17 00:00:00 2001 From: Xiaozhu Meng Date: Fri, 21 Jan 2022 15:34:58 -0600 Subject: [PATCH 2/2] Do not allow setting hsa_api_ without getting the HsaRsrcFactory object first --- src/util/hsa_rsrc_factory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/hsa_rsrc_factory.h b/src/util/hsa_rsrc_factory.h index e6b19b5f..4baafdfd 100644 --- a/src/util/hsa_rsrc_factory.h +++ b/src/util/hsa_rsrc_factory.h @@ -414,7 +414,7 @@ class HsaRsrcFactory { static const char* GetKernelNameRef(uint64_t addr); // Initialize HSA API table - void static InitHsaApiTable(HsaApiTable* table); + void InitHsaApiTable(HsaApiTable* table); static const hsa_pfn_t* HsaApi() { return &hsa_api_; } // Return AqlProfile API table