diff --git a/include/hip/hcc_detail/program_state.hpp b/include/hip/hcc_detail/program_state.hpp index 0e21b12f5f..65896e97a7 100644 --- a/include/hip/hcc_detail/program_state.hpp +++ b/include/hip/hcc_detail/program_state.hpp @@ -23,6 +23,7 @@ THE SOFTWARE. #pragma once #include +#include #include #include @@ -68,12 +69,15 @@ namespace hip_impl } }; + using RAII_global = std::unique_ptr; + const std::unordered_map< hsa_agent_t, std::vector>& executables(); const std::unordered_map< std::uintptr_t, std::vector>>& functions(); const std::unordered_map& function_names(); + std::unordered_map& globals(); hsa_executable_t load_executable( hsa_executable_t executable, hsa_agent_t agent, std::istream& file); diff --git a/src/hip_module.cpp b/src/hip_module.cpp index d8fa2db097..00ffd8b03b 100644 --- a/src/hip_module.cpp +++ b/src/hip_module.cpp @@ -725,9 +725,9 @@ hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const if(name == NULL || hmod == NULL){ ret = hipErrorNotInitialized; } else{ - const auto it = hmod->coGlobals.find(name); - if (it == hmod->coGlobals.end()) return ihipLogStatus(hipErrorInvalidValue); - *texRef = reinterpret_cast(it->second); + const auto it = hip_impl::globals().find(name); + if (it == hip_impl::globals().end()) return ihipLogStatus(hipErrorInvalidValue); + *texRef = reinterpret_cast(it->second.get()); ret = hipSuccess; } } diff --git a/src/program_state.cpp b/src/program_state.cpp index 79d692e06f..61c90556be 100644 --- a/src/program_state.cpp +++ b/src/program_state.cpp @@ -158,14 +158,7 @@ namespace symbol_section_accessor{reader, code_object_dynsym}); for (auto&& x : undefined_symbols) { - using RAII_global = - unique_ptr; - - static unordered_map globals; - static once_flag f; - call_once(f, [=]() { globals.reserve(symbol_addresses().size()); }); - - if (globals.find(x) != globals.cend()) return; + if (globals().find(x) != globals().cend()) return; const auto it1 = symbol_addresses().find(x); @@ -176,7 +169,7 @@ namespace static mutex mtx; lock_guard lck{mtx}; - if (globals.find(x) != globals.cend()) return; + if (globals().find(x) != globals().cend()) return; void* p = nullptr; hsa_amd_memory_lock( @@ -186,12 +179,10 @@ namespace 0, &p); - if (!p) { cerr << it1->first << endl; assert(false); } - hsa_executable_agent_global_variable_define( executable, agent, x.c_str(), p); - globals.emplace(x, RAII_global{p, hsa_amd_memory_unlock}); + globals().emplace(x, RAII_global{p, hsa_amd_memory_unlock}); } } @@ -534,6 +525,15 @@ namespace hip_impl return r; } + unordered_map& globals() + { + static unordered_map r; + static once_flag f; + call_once(f, []() { r.reserve(symbol_addresses().size()); }); + + return r; + } + hsa_executable_t load_executable( hsa_executable_t executable, hsa_agent_t agent, istream& file) {