diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp index 7027ee3364..2e8d1a923b 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/inc/amd_hsa_code.hpp @@ -362,11 +362,11 @@ namespace code { class AmdHsaCodeManager { private: - typedef std::unordered_map> CodeMap; + typedef std::unordered_map> CodeMap; CodeMap codeMap; public: - const std::shared_ptr& FromHandle(hsa_code_object_t handle); + AmdHsaCode* FromHandle(hsa_code_object_t handle); bool Destroy(hsa_code_object_t handle); }; 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 291a4382a9..147ce1ba6d 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/hsa.cpp @@ -1804,7 +1804,7 @@ hsa_status_t hsa_code_object_serialize( IS_BAD_PTR(serialized_code_object); IS_BAD_PTR(serialized_code_object_size); - amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get(); + amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } @@ -1982,7 +1982,7 @@ hsa_status_t hsa_code_object_get_info( IS_OPEN(); IS_BAD_PTR(value); - amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get(); + amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } @@ -2039,7 +2039,7 @@ hsa_status_t hsa_code_object_get_symbol( IS_BAD_PTR(symbol_name); IS_BAD_PTR(symbol); - amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get(); + amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } @@ -2059,7 +2059,7 @@ hsa_status_t hsa_code_object_get_symbol_from_name( IS_BAD_PTR(symbol_name); IS_BAD_PTR(symbol); - amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get(); + amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } @@ -2097,7 +2097,7 @@ hsa_status_t hsa_code_object_iterate_symbols( IS_OPEN(); IS_BAD_PTR(callback); - amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object).get(); + amd::hsa::code::AmdHsaCode *code = GetCodeManager()->FromHandle(code_object); if (!code) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; } diff --git a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp index 500247b537..3f6d4feb36 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/libamdhsacode/amd_hsa_code.cpp @@ -1742,19 +1742,19 @@ namespace code { return false; } - const std::shared_ptr& AmdHsaCodeManager::FromHandle(hsa_code_object_t c) + AmdHsaCode* AmdHsaCodeManager::FromHandle(hsa_code_object_t c) { CodeMap::iterator i = codeMap.find(c.handle); if (i == codeMap.end()) { - std::shared_ptr code = std::make_shared(); + std::unique_ptr code = std::make_unique(); const void* buffer = reinterpret_cast(c.handle); if (!code->InitAsBuffer(buffer, 0)) { - return 0; + return nullptr; } - codeMap[c.handle] = code; - return code; + auto res = codeMap.emplace(c.handle, std::move(code)); + return res.first->second.get(); } - return i->second; + return i->second.get(); } bool AmdHsaCodeManager::Destroy(hsa_code_object_t c)