Skip to content
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

[TVMScript] Deterministic function ordering #13962

Merged

Conversation

junrushao
Copy link
Member

This PR makes IRModule printing deterministic by fix the function ordering. The "main" function always comes last, while other functions should be ordered alphabetically.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Feb 11, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable)
.set_dispatch<IRModule>("", [](IRModule mod, ObjectPath p, IRDocsifier d) -> Doc {
std::vector<std::pair<GlobalVar, BaseFunc>> functions{mod->functions.begin(),
mod->functions.end()};
// print "main" first
std::sort(functions.begin(), functions.end(), [](const auto& lhs, const auto& rhs) {
String lhs_name = lhs.first->name_hint;
String rhs_name = rhs.first->name_hint;
if (lhs_name == "main") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can cache sort key by generating a tuple first then sort instead of doing string look up compare each time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated accordingly

This PR makes IRModule printing deterministic by fix the function
ordering. The "main" function always comes last, while other functions
should be ordered alphabetically.
@junrushao junrushao force-pushed the feature/2023-02-11/irmodule-func-ordering branch from 8ddf6c1 to adbf1f0 Compare February 12, 2023 07:37
@junrushao junrushao marked this pull request as ready for review February 12, 2023 07:39
@tqchen tqchen merged commit 8401bf6 into apache:main Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants