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

Add order to functions in C Codegen #10590

Merged
merged 10 commits into from
Mar 18, 2022
Merged

Conversation

mehrdadh
Copy link
Member

This PR add ordering to functions in C codegen. Also, it add few logging messages.

cc @areusch

@github-actions github-actions bot requested a review from areusch March 11, 2022 21:45
Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

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

here's a couple comments, also it'd be great to see if we could improve the test to verify the ordering

@@ -132,6 +132,7 @@ PackedFunc AotExecutor::GetFunction(const std::string& name,
*rv = this->GetInputIndex(args[0].operator String());
});
} else {
LOG(INFO) << "Unknown packed function: " << name;
Copy link
Contributor

Choose a reason for hiding this comment

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

for this one, i think return PackedFunc() is still abiding by the GetFunction convention, so it might be a bit superfluous to emit a log line here.

Copy link
Member Author

@mehrdadh mehrdadh Mar 14, 2022

Choose a reason for hiding this comment

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

I'm looking for a way to show some output message to developers that they are using the wrong function name for this module. Specially since we have multiple version of this runtime.Module it would be very useful to have some messaging. What is your suggestion?
Also is LOG(DEBUG) better in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

does this work? or are you saying from c++?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah from C++. I would overwrite << operator in runtime::Module to provide more info on this. Cause that way we can get module type in C++.

@@ -105,7 +105,7 @@ PackedFunc Executable::GetFunction(const std::string& name, const ObjectPtr<Obje
});
} else {
LOG(FATAL) << "Unknown packed function: " << name;
return PackedFunc(nullptr);
return PackedFunc();
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this change is equivalent

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, PackedFunc() just matches with the rest of the codebase.

@@ -42,7 +43,12 @@ class CodeGenCHost : public CodeGenC {

void InitGlobalContext();
void AddFunction(const PrimFunc& f);

/*!
* \brief Add functions from the (unordered) range to the current module in a deterministic order.
Copy link
Contributor

Choose a reason for hiding this comment

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

a vector is ordered, so what do you mean by unordered?

Copy link
Member Author

Choose a reason for hiding this comment

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

name of the functions in the vector are not ordered.

@github-actions github-actions bot requested a review from areusch March 14, 2022 22:06
@mehrdadh
Copy link
Member Author

@areusch CI is green, PTAL!

@github-actions github-actions bot requested a review from areusch March 16, 2022 19:08
@mehrdadh
Copy link
Member Author

@areusch Addressed comments and added another test for the function order. PTAL!

@github-actions github-actions bot requested a review from areusch March 17, 2022 02:36
schedule_names.push_back(func.first->name_hint);
}
}
EXPECT_THAT(schedule_names, ElementsAre(StrEq("op_2"), StrEq("op_1")));
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry to ask for a second change--this is a little bit risky as the insertion order of unordered_map isn't guaranteed. this test could start randomly failing and be hard to reproduce. i think a more stable approach would be to wrap the logic that creates s1/s2 into a functor and call it at least 2 times (e.g. creating "op_9", "op_8", ...) and then continue calling it until the map is not sorted. then do the remainder. would you mind making that change? sorry about this.

@github-actions github-actions bot requested a review from areusch March 18, 2022 00:25
Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

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

almost there, just a couple more suggestions

@github-actions github-actions bot requested a review from areusch March 18, 2022 00:41
@mehrdadh
Copy link
Member Author

@areusch addressed comments, PTAL. thanks!

@areusch areusch merged commit ee1944d into apache:main Mar 18, 2022
@areusch
Copy link
Contributor

areusch commented Mar 18, 2022

thanks @mehrdadh !

@mehrdadh mehrdadh deleted the aot/fix_function_order branch March 18, 2022 17:31
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
* Add function ordering to C Codegen

* trigger

* fix comment

* address comments

* add test

* add unorder check

* fix test

* address comments
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