SWDEV-341360 - Handle named expressions with space in hipRTC
Change-Id: I1c26855d8a94e0a4d818664ca71094c6992221c9
[ROCm/clr commit: b263ab3248]
Dieser Commit ist enthalten in:
@@ -151,7 +151,7 @@ hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog, const char* name_expressio
|
||||
|
||||
auto* rtcProgram = hiprtc::RTCCompileProgram::as_RTCCompileProgram(prog);
|
||||
|
||||
if (!rtcProgram->getDemangledName(name_expression, loweredName)) {
|
||||
if (!rtcProgram->getMangledName(name_expression, loweredName)) {
|
||||
return HIPRTC_RETURN(HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID);
|
||||
}
|
||||
|
||||
|
||||
@@ -466,7 +466,7 @@ std::string handleMangledName(std::string loweredName) {
|
||||
return loweredName;
|
||||
}
|
||||
|
||||
bool fillDemangledNames(std::vector<char>& executable, std::vector<std::string>& mangledNames) {
|
||||
bool fillMangledNames(std::vector<char>& executable, std::vector<std::string>& mangledNames) {
|
||||
amd_comgr_data_t dataObject;
|
||||
if (auto res = amd::Comgr::create_data(AMD_COMGR_DATA_KIND_EXECUTABLE, &dataObject);
|
||||
res != AMD_COMGR_STATUS_SUCCESS) {
|
||||
@@ -504,8 +504,7 @@ bool fillDemangledNames(std::vector<char>& executable, std::vector<std::string>&
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getMangledNames(const std::vector<std::string>& mangledNames,
|
||||
std::map<std::string, std::string>& strippedNames,
|
||||
bool getDemangledNames(const std::vector<std::string>& mangledNames,
|
||||
std::map<std::string, std::string>& demangledNames) {
|
||||
for (auto& i : mangledNames) {
|
||||
std::string demangledName;
|
||||
@@ -516,22 +515,10 @@ bool getMangledNames(const std::vector<std::string>& mangledNames,
|
||||
[](unsigned char c) { return std::isspace(c); }),
|
||||
demangledName.end());
|
||||
|
||||
if (auto res = strippedNames.find(demangledName); res != strippedNames.end()) {
|
||||
auto& strippedName = res->second;
|
||||
if (auto dres = demangledNames.find(strippedName); dres != demangledNames.end()) {
|
||||
dres->second = i;
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto dres = demangledNames.find(demangledName); dres != demangledNames.end()) {
|
||||
dres->second = i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace helpers
|
||||
|
||||
@@ -52,9 +52,8 @@ bool dumpIsaFromBC(const amd_comgr_data_set_t isaInputs, const std::string& isa,
|
||||
std::vector<std::string>& exeOptions, std::string name, std::string& buildLog);
|
||||
bool demangleName(const std::string& mangledName, std::string& demangledName);
|
||||
std::string handleMangledName(std::string loweredName);
|
||||
bool fillDemangledNames(std::vector<char>& executable, std::vector<std::string>& mangledNames);
|
||||
bool getMangledNames(const std::vector<std::string>& mangledNames,
|
||||
std::map<std::string, std::string>& strippedNames,
|
||||
bool fillMangledNames(std::vector<char>& executable, std::vector<std::string>& mangledNames);
|
||||
bool getDemangledNames(const std::vector<std::string>& mangledNames,
|
||||
std::map<std::string, std::string>& demangledNames);
|
||||
} // namespace helpers
|
||||
} // namespace hiprtc
|
||||
|
||||
@@ -288,25 +288,21 @@ bool RTCCompileProgram::compile(const std::vector<std::string>& options, bool fg
|
||||
}
|
||||
|
||||
std::vector<std::string> mangledNames;
|
||||
if (!fillDemangledNames(executable_, mangledNames)) {
|
||||
LogError("Error in hiprtc: unable to fill demangled names");
|
||||
if (!fillMangledNames(executable_, mangledNames)) {
|
||||
LogError("Error in hiprtc: unable to fill mangled names");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!getMangledNames(mangledNames, stripped_names_, demangled_names_)) {
|
||||
LogError("Error in hiprtc: unable to get mangled names");
|
||||
if (!getDemangledNames(mangledNames, demangled_names_)) {
|
||||
LogError("Error in hiprtc: unable to get demangled names");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTCCompileProgram::trackMangledName(std::string& name) {
|
||||
amd::ScopedLock lock(lock_);
|
||||
void RTCCompileProgram::stripNamedExpression(std::string& strippedName) {
|
||||
|
||||
if (name.size() == 0) return false;
|
||||
|
||||
std::string strippedName = name;
|
||||
if (strippedName.back() == ')') {
|
||||
strippedName.pop_back();
|
||||
strippedName.erase(0, strippedName.find('('));
|
||||
@@ -314,16 +310,24 @@ bool RTCCompileProgram::trackMangledName(std::string& name) {
|
||||
if (strippedName.front() == '&') {
|
||||
strippedName.erase(0, 1);
|
||||
}
|
||||
|
||||
std::string strippedNameNoSpace = strippedName;
|
||||
strippedNameNoSpace.erase(std::remove_if(strippedNameNoSpace.begin(),
|
||||
strippedNameNoSpace.end(),
|
||||
// Removes the spaces from strippedName if present
|
||||
strippedName.erase(std::remove_if(strippedName.begin(),
|
||||
strippedName.end(),
|
||||
[](unsigned char c) {
|
||||
return std::isspace(c);
|
||||
}), strippedNameNoSpace.end());
|
||||
}), strippedName.end());
|
||||
}
|
||||
|
||||
bool RTCCompileProgram::trackMangledName(std::string& name) {
|
||||
amd::ScopedLock lock(lock_);
|
||||
|
||||
if (name.size() == 0) return false;
|
||||
|
||||
std::string strippedNameNoSpace = name;
|
||||
stripNamedExpression(strippedNameNoSpace);
|
||||
|
||||
stripped_names_.insert(std::pair<std::string, std::string>(name, strippedNameNoSpace));
|
||||
demangled_names_.insert(std::pair<std::string, std::string>(strippedName, ""));
|
||||
demangled_names_.insert(std::pair<std::string, std::string>(strippedNameNoSpace, ""));
|
||||
|
||||
const auto var{"__hiprtc_" + std::to_string(stripped_names_.size())};
|
||||
const auto code{"\nextern \"C\" constexpr auto " + var + " = " + name + ";\n"};
|
||||
@@ -332,23 +336,17 @@ bool RTCCompileProgram::trackMangledName(std::string& name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTCCompileProgram::getDemangledName(const char* name_expression, const char** loweredName) {
|
||||
std::string name = name_expression;
|
||||
if (auto res = stripped_names_.find(name); res != stripped_names_.end()) {
|
||||
if (auto dres = demangled_names_.find(res->second); dres != demangled_names_.end()) {
|
||||
if (dres->second.size() != 0) {
|
||||
*loweredName = dres->second.c_str();
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (auto dres = demangled_names_.find(name); dres != demangled_names_.end()) {
|
||||
bool RTCCompileProgram::getMangledName(const char* name_expression, const char** loweredName) {
|
||||
|
||||
std::string strippedName = name_expression;
|
||||
stripNamedExpression(strippedName);
|
||||
|
||||
if (auto dres = demangled_names_.find(strippedName); dres != demangled_names_.end()) {
|
||||
if (dres->second.size() != 0) {
|
||||
*loweredName = dres->second.c_str();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -159,8 +159,9 @@ class RTCCompileProgram : public RTCProgram {
|
||||
bool addSource(const std::string& source, const std::string& name);
|
||||
bool addHeader(const std::string& source, const std::string& name);
|
||||
bool compile(const std::vector<std::string>& options, bool fgpu_rdc);
|
||||
bool getDemangledName(const char* name_expression, const char** loweredName);
|
||||
bool getMangledName(const char* name_expression, const char** loweredName);
|
||||
bool trackMangledName(std::string& name);
|
||||
void stripNamedExpression(std::string& named_expression);
|
||||
|
||||
bool GetBitcode(char* bitcode);
|
||||
bool GetBitcodeSize(size_t* bitcode_size);
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren