Merge pull request #958 from aaronenyeshi/cxxabi-mismatch-workaround

CXX11 ABI Mismatch Workaround

[ROCm/clr commit: 23170f6af8]
This commit is contained in:
Maneesh Gupta
2019-03-15 06:15:46 +05:30
committed by GitHub
4 changed files with 85 additions and 63 deletions
@@ -33,7 +33,48 @@ THE SOFTWARE.
#include <vector>
namespace hip_impl {
hsa_isa_t triple_to_hsa_isa(const std::string& triple);
inline
std::string transmogrify_triple(const std::string& triple)
{
static constexpr const char old_prefix[]{"hcc-amdgcn--amdhsa-gfx"};
static constexpr const char new_prefix[]{"hcc-amdgcn-amd-amdhsa--gfx"};
if (triple.find(old_prefix) == 0) {
return new_prefix + triple.substr(sizeof(old_prefix) - 1);
}
return (triple.find(new_prefix) == 0) ? triple : "";
}
inline
std::string isa_name(std::string triple)
{
static constexpr const char offload_prefix[]{"hcc-"};
triple = transmogrify_triple(triple);
if (triple.empty()) return {};
triple.erase(0, sizeof(offload_prefix) - 1);
return triple;
}
inline
hsa_isa_t triple_to_hsa_isa(const std::string& triple) {
const std::string isa{isa_name(std::move(triple))};
if (isa.empty()) return hsa_isa_t({});
hsa_isa_t r{};
if(HSA_STATUS_SUCCESS != hsa_isa_from_name(isa.c_str(), &r)) {
r.handle = 0;
}
return r;
}
struct Bundled_code {
union Header {
@@ -2506,7 +2506,41 @@ hipError_t hipModuleGetFunction(hipFunction_t* function, hipModule_t module, con
hipError_t hipFuncGetAttributes(hipFuncAttributes* attr, const void* func);
struct Agent_global {
std::string name;
Agent_global() : name(nullptr), address(nullptr), byte_cnt(0) {}
Agent_global(const char* name, hipDeviceptr_t address, uint32_t byte_cnt)
: name(nullptr), address(address), byte_cnt(byte_cnt) {
if (name)
this->name = strdup(name);
}
Agent_global& operator=(Agent_global&& t) {
if (this == &t) return *this;
if (name) free(name);
name = t.name;
address = t.address;
byte_cnt = t.byte_cnt;
t.name = nullptr;
t.address = nullptr;
t.byte_cnt = 0;
return *this;
}
Agent_global(Agent_global&& t)
: name(nullptr), address(nullptr), byte_cnt(0) {
*this = std::move(t);
}
// not needed, delete them to prevent bugs
Agent_global(const Agent_global&) = delete;
Agent_global& operator=(Agent_global& t) = delete;
~Agent_global() { if (name) free(name); }
char* name;
hipDeviceptr_t address;
uint32_t byte_cnt;
};
@@ -2518,13 +2552,13 @@ struct Agent_global {
namespace hip_impl {
hsa_executable_t executable_for(hipModule_t);
const std::string& hash_for(hipModule_t);
const char* hash_for(hipModule_t);
template<typename ForwardIterator>
std::pair<hipDeviceptr_t, std::size_t> read_global_description(
ForwardIterator f, ForwardIterator l, const char* name) {
const auto it = std::find_if(f, l, [=](const Agent_global& x) {
return x.name == name;
return strcmp(x.name, name) == 0;
});
return it == l ?
@@ -2543,7 +2577,7 @@ hipError_t read_agent_global_from_module(hipDeviceptr_t* dptr, size_t* bytes,
// hipModule_t instance
static std::unordered_map<
std::string, std::vector<Agent_global>> agent_globals;
auto key = hash_for(hmod);
std::string key(hash_for(hmod));
if (agent_globals.count(key) == 0) {
static std::mutex mtx;