Skip to content

Commit

Permalink
[AutoScheduler] Skip useless calls to RewriteLayout (apache#6993)
Browse files Browse the repository at this point in the history
* [AutoScheduler] Skip useless calls of RewriteLayout

* fix lint

* fix lint
  • Loading branch information
merrymercy authored Nov 29, 2020
1 parent f65d0de commit d14e779
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/auto_scheduler/compute_dag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,25 @@ ComputeDAG ComputeDAG::RewriteLayout(Array<Step>* transform_steps,
return new_dag;
}

// Return whether a DAG has placeholders that are marked as "layout free".
bool HasLayoutFreeTensors(const ComputeDAG& dag) {
for (const auto& op : dag->ops) {
if (!op->IsInstance<te::ComputeOpNode>()) {
continue;
}
if (op->attrs.count(ComputeDAG::layout_free_placeholders_key)) {
return true;
}
}

return false;
}

std::pair<te::Schedule, Array<te::Tensor>> ComputeDAG::ApplySteps(
const Array<Step>& transform_steps, Array<te::Stage>* stages, StageToAxesMap* stage_to_axes,
LayoutRewriteOption layout_rewrite) const {
if (layout_rewrite != LayoutRewriteOption::NoRewrite && !transform_steps.empty()) {
if (layout_rewrite != LayoutRewriteOption::NoRewrite && HasLayoutFreeTensors(*this) &&
!transform_steps.empty()) {
Array<Step> steps = transform_steps;
const auto& dag = RewriteLayout(&steps, layout_rewrite);
return dag.ApplySteps(steps);
Expand Down

0 comments on commit d14e779

Please sign in to comment.