Bring loader in sync with stg/sc

Change-Id: Iccce07b8fa03d37c4267a2a9bd343e6614dc43e7


[ROCm/ROCR-Runtime commit: 9887c26113]
Cette révision appartient à :
Konstantin Zhuravlyov
2017-02-09 17:57:10 -05:00
Parent 16d8e2caa9
révision 2a071e1456
8 fichiers modifiés avec 245 ajouts et 131 suppressions
+34 -47
Voir le fichier
@@ -122,60 +122,30 @@ namespace code {
hsa_status_t Symbol::GetInfo(hsa_code_symbol_info_t attribute, void *value)
{
assert(value);
std::string name = Name();
switch (attribute) {
case HSA_CODE_SYMBOL_INFO_TYPE: {
*((hsa_symbol_kind_t*)value) = Kind();
break;
}
case HSA_CODE_SYMBOL_INFO_NAME_LENGTH:
case HSA_CODE_SYMBOL_INFO_NAME: {
std::string matter = "";
switch (Linkage()) {
case HSA_SYMBOL_LINKAGE_PROGRAM:
assert(name.rfind(":") == std::string::npos);
matter = name;
break;
case HSA_SYMBOL_LINKAGE_MODULE:
assert(name.rfind(":") != std::string::npos);
matter = name.substr(name.rfind(":") + 1);
break;
default:
assert(!"Unsupported linkage in Symbol::GetInfo");
return HSA_STATUS_ERROR;
}
if (attribute == HSA_CODE_SYMBOL_INFO_NAME_LENGTH) {
*((uint32_t*) value) = matter.size() + 1;
} else {
memset(value, 0x0, matter.size() + 1);
memcpy(value, matter.c_str(), matter.size());
}
case HSA_CODE_SYMBOL_INFO_NAME_LENGTH: {
*((uint32_t*)value) = GetSymbolName().size();
break;
}
case HSA_CODE_SYMBOL_INFO_NAME: {
std::string SymbolName = GetSymbolName();
memset(value, 0x0, SymbolName.size());
memcpy(value, SymbolName.c_str(), SymbolName.size());
break;
}
case HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH: {
*((uint32_t*)value) = GetModuleName().size();
break;
}
case HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH:
case HSA_CODE_SYMBOL_INFO_MODULE_NAME: {
switch (Linkage()) {
case HSA_SYMBOL_LINKAGE_PROGRAM:
if (attribute == HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH) {
*((uint32_t*) value) = 0;
}
break;
case HSA_SYMBOL_LINKAGE_MODULE: {
assert(name.find(":") != std::string::npos);
std::string matter = name.substr(0, name.find(":"));
if (attribute == HSA_CODE_SYMBOL_INFO_MODULE_NAME_LENGTH) {
*((uint32_t*) value) = matter.length() + 1;
} else {
memset(value, 0x0, matter.size() + 1);
memcpy(value, matter.c_str(), matter.length());
((char*)value)[matter.size() + 1] = '\0';
}
break;
}
default:
assert(!"Unsupported linkage in Symbol::GetInfo");
return HSA_STATUS_ERROR;
}
std::string ModuleName = GetModuleName();
memset(value, 0x0, ModuleName.size());
memcpy(value, ModuleName.c_str(), ModuleName.size());
break;
}
case HSA_CODE_SYMBOL_INFO_LINKAGE: {
@@ -193,6 +163,18 @@ namespace code {
return HSA_STATUS_SUCCESS;
}
std::string Symbol::GetModuleName() const {
std::string FullName = Name();
return FullName.rfind(":") != std::string::npos ?
FullName.substr(0, FullName.find(":")) : "";
}
std::string Symbol::GetSymbolName() const {
std::string FullName = Name();
return FullName.rfind(":") != std::string::npos ?
FullName.substr(FullName.rfind(":") + 1) : FullName;
}
hsa_code_symbol_t Symbol::ToHandle(Symbol* sym)
{
hsa_code_symbol_t s;
@@ -994,6 +976,7 @@ namespace code {
PrintSymbols(out);
out << std::endl;
PrintMachineCode(out);
out << std::endl;
out << "AMD HSA Code Object End" << std::endl;
}
@@ -1250,7 +1233,7 @@ namespace code {
} else if (major_version == 8) {
asic = "VI";
} else if (major_version == 9) {
asic = "GREENLAND";
asic = "GFX9";
} else {
assert(!"unknown compute capability");
}
@@ -1522,11 +1505,15 @@ namespace code {
bool AmdHsaCode::PullElfV2()
{
Segment* note = NULL;
for (size_t i = 0; i < img->segmentCount(); ++i) {
Segment* s = img->segment(i);
if (s->type() == PT_LOAD) {
dataSegments.push_back(s);
}
else if (s->type() == PT_NOTE && s->align() >= 4) {
note = s;
}
}
for (size_t i = 0; i < img->sectionCount(); ++i) {
Section* sec = img->section(i);