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

[TECompiler] Decouple TE compute and schedule lowering in ScheduleBuilder #10561

Merged
merged 6 commits into from
Mar 11, 2022

Conversation

masahi
Copy link
Member

@masahi masahi commented Mar 10, 2022

Refactors ScheduleBuilder, that currently does TE compute lowering and schedule application in one go, into two classes.

The motivation is to use the TE compute lowering class, LowerToTECompute, for meta schedule task extraction. For task extraction, there is no need to apply and lower schedules, but currently we do VMCompiler.lower() which is too hacky and overkill.

@mbs-octoml @junrushao1994 @jroesch @comaniac

@masahi masahi marked this pull request as ready for review March 10, 2022 09:46
@masahi masahi changed the title Decouple TE compute and schedule lowering in ScheduleBuilder [TECompiler] Decouple TE compute and schedule lowering in ScheduleBuilder Mar 10, 2022
auto outputs = lower_te_compute.Lower(prim_func, [&](std::string name) { return name; });
return CachedFunc(tgt, GlobalVar(lower_te_compute.candidate_name_), lower_te_compute.fn_inputs_,
outputs, te::Schedule(), tir::PrimFunc(), {},
IRModule(Map<GlobalVar, BaseFunc>({})), lower_te_compute.constant_tensors_);
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @mbaret for this change

int LowerToTECompute::const_index = 0;

// Construct a schedule for a given Relay primitive function and target.
class ScheduleBuilder : ExprVisitor {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could give this class a better name while we are doing this cleanup?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a bit hard to come up with a good name since this class does a lot more than "schedule building". See https://github.com/apache/tvm/pull/10561/files#r824096015

Over time we stuffed all lowering-dependent tasks onto this class...

use_auto_scheduler_ = backend::IsAutoSchedulerEnabled();
}

CachedFunc Create(const Function& relay_func, std::function<std::string(std::string)> renamer) {
Copy link
Member

Choose a reason for hiding this comment

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

While you are refactoring this code it might be good to better annotate it with comments describing the pieces here as now this code (due to me and Mark refactoring) has quite a few branches.

Copy link
Member Author

@masahi masahi Mar 10, 2022

Choose a reason for hiding this comment

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

Yeah, this function is not only used for ordinary lowering purposes, but also abused for ansor / meta schedule task extraction or "apply history best" depending on where it is called...

Optional<ObjectRef> opt_mod_or_base_func = meta_schedule::MetaScheduleContext::QueryInsideWithScope is very opaque since (1) we don't know if it returns anything and (2) we don't what concrete value it returns.

After my task extraction refactor, QueryInsideWithScope can always return a non-null, concrete Schedule object, since the None case is used only for task extraction currently. cc @junrushao1994

Copy link
Member

Choose a reason for hiding this comment

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

Per discussion with Masa, we decided to just clean up meta_schedule/integration.cc and make it clearer

@jroesch
Copy link
Member

jroesch commented Mar 10, 2022

Overall looks great Masa thanks for doing this!

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

Thanks @masahi! All look good to me! Just a few nits

src/relay/backend/te_compiler_cache.cc Outdated Show resolved Hide resolved
src/relay/backend/te_compiler_cache.cc Outdated Show resolved Hide resolved
use_auto_scheduler_ = backend::IsAutoSchedulerEnabled();
}

CachedFunc Create(const Function& relay_func, std::function<std::string(std::string)> renamer) {
Copy link
Member

Choose a reason for hiding this comment

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

Per discussion with Masa, we decided to just clean up meta_schedule/integration.cc and make it clearer

@masahi masahi merged commit 076fa33 into apache:main Mar 11, 2022
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
…lder (apache#10561)

* Decouple TE compute and schedule lowering in ScheduleBuilder

* fixed merge conflict

* removed create_schedule stuff

* add public, fix include path convention

* Forgot visiting arg in ScheduleBuilder CallNode vsit

* fixed anchor impl selection
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.

4 participants