Skip to content

Trim the output names of non-digits #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: rocm7.0_internal_testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1611,15 +1611,15 @@ Status MIGraphXExecutionProvider::Compile(const std::vector<FusedNodeAndGraph>&
}
// It is an output argument
else {
auto compute_output_index = [](const std::string& name) -> int {
const std::string out_name_prefix = "#output_";
const auto pos = name.find(out_name_prefix);
if (pos == std::string::npos) {
auto compute_output_index = [](const std::string_view sv) -> int {
constexpr std::string_view out_name_prefix = "#output_";
const auto pos = sv.find(out_name_prefix);
if (pos == std::string_view::npos) {
return -1;
}

const std::string index_str = name.substr(pos + out_name_prefix.length());
return std::stoi(index_str);
const auto index_str = sv.substr(pos + out_name_prefix.length());
return ToInteger(Trim(index_str, std::isdigit));
};

int output_index = compute_output_index(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,28 @@ inline std::string GenerateGraphId(const GraphViewer& graph_viewer) {
return std::string{s.data(), ptr};
}

inline std::string_view TrimLeft(std::string_view sv, int (*fn)(int) = std::isspace) {
return sv.substr(0, sv.end() - std::find_if(sv.begin(), sv.end(), [fn](int ch) {
return fn(ch);
}));
}

inline std::string_view TrimRight(std::string_view sv, int (*fn)(int) = std::isspace) {
return sv.substr(sv.end() - std::find_if(sv.rbegin(), sv.rend(), [fn](int ch) {
return fn(ch);
}).base());
}

inline std::string_view Trim(std::string_view sv, int (*fn)(int) = std::isspace) {
return TrimRight(TrimLeft(sv, fn), fn);
}

inline int ToInteger(const std::string_view sv) {
int result = 0;
if (auto [_, ec] = std::from_chars(sv.data(), sv.data() + sv.length(), result); ec == std::errc()) {
return result;
}
ORT_THROW("invalid input for conversion to integer");
}

} // namespace onnxruntime
Loading