-Moved coGlobals in hipModule class (takes care of multi module case)

-Used mutex scope for updating coGlobals
This commit is contained in:
Rahul Garg
2017-11-20 16:23:18 +05:30
parent 76f174b536
commit eff09fcd86
2 changed files with 17 additions and 15 deletions
+10 -8
View File
@@ -25,8 +25,9 @@ THE SOFTWARE.
#include <hc.hpp>
#include <hsa/hsa.h>
#include "hsa/hsa_ext_amd.h"
#include <unordered_map>
#include "hsa/hsa_ext_amd.h"
#include "hip/hip_runtime.h"
#include "hip_util.h"
#include "env.h"
@@ -373,13 +374,14 @@ public:
class ihipModule_t {
public:
hsa_executable_t executable;
hsa_code_object_t object;
std::string fileName;
void *ptr;
size_t size;
std::list<hipFunction_t> funcTrack;
ihipModule_t() : executable(), object(), fileName(), ptr(nullptr), size(0) {}
hsa_executable_t executable;
hsa_code_object_t object;
std::string fileName;
void *ptr;
size_t size;
std::list<hipFunction_t> funcTrack;
std::unordered_map<std::string, uintptr_t> coGlobals;
ihipModule_t() : executable(), object(), fileName(), ptr(nullptr), size(0) {}
};
+7 -7
View File
@@ -40,8 +40,6 @@ THE SOFTWARE.
#include "hip_hcc_internal.h"
#include "trace_helper.h"
//TODO Add support for multiple modules
static std::unordered_map<std::string, uintptr_t> coGlobals;
//TODO Use Pool APIs from HCC to get memory regions.
#include <cassert>
@@ -244,6 +242,7 @@ namespace
inline
void associate_code_object_symbols_with_host_allocation(
hipModule_t module,
const ELFIO::elfio& reader,
const ELFIO::elfio& self_reader,
ELFIO::section* code_object_dynsym,
@@ -264,9 +263,6 @@ namespace
symbol_section_accessor{self_reader, process_symtab}, x);
assert(tmp.first);
if (coGlobals.count(x) == 0) {
coGlobals.emplace(x, tmp.first);
}
void* p = nullptr;
hsa_amd_memory_lock(
reinterpret_cast<void*>(tmp.first), tmp.second, &agent, 1, &p);
@@ -280,6 +276,9 @@ namespace
lock_guard<std::mutex> lck{mtx};
globals.emplace_back(p, hsa_amd_memory_unlock);
if (module->coGlobals.count(x) == 0) {
module->coGlobals.emplace(x, tmp.first);
}
}
}
@@ -361,6 +360,7 @@ hipError_t hipModuleLoad(hipModule_t *module, const char *fname)
});
associate_code_object_symbols_with_host_allocation(
*module,
reader,
self_reader,
code_object_dynsym,
@@ -849,8 +849,8 @@ hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const
return ihipLogStatus(hipErrorNotInitialized);
}
else{
const auto it = coGlobals.find(name);
if (it == coGlobals.end()) return ihipLogStatus(hipErrorInvalidValue);
const auto it = hmod->coGlobals.find(name);
if (it == hmod->coGlobals.end()) return ihipLogStatus(hipErrorInvalidValue);
*texRef = reinterpret_cast<textureReference*>(it->second);
return ihipLogStatus(ret);
}