FrozenGene commented on a change in pull request #6184:
URL: https://github.com/apache/incubator-tvm/pull/6184#discussion_r467875817



##########
File path: src/auto_scheduler/search_policy/utils.cc
##########
@@ -0,0 +1,301 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file auto_scheduler/utils.cc
+ * \brief Common utilities
+ */
+
+#include "utils.h"
+
+#include <algorithm>
+
+namespace tvm {
+namespace auto_scheduler {
+
+State DoMultiLevelTiling(const State& state, int stage_id, const std::string& 
format,
+                         std::vector<int>* spatial_split_step_ids) {
+  // Temporal object to be used if the input pointer is nullptr
+  std::vector<int> temp_split_step_ids;
+  if (spatial_split_step_ids == nullptr) {
+    spatial_split_step_ids = &temp_split_step_ids;
+  }
+  std::vector<std::vector<Iterator>> space_levels;
+  std::vector<std::vector<Iterator>> reduce_levels;
+  std::vector<Iterator> space_outer, space_inner, reduce_outer, reduce_inner;
+  Array<Iterator> split_res;
+
+  for (const auto c : format) {
+    if (tolower(c) == 's') {
+      space_levels.emplace_back();
+    } else if (tolower(c) == 'r') {
+      reduce_levels.emplace_back();
+    } else {
+      LOG(FATAL) << "Invalid multi-level tiling format: " << format;
+    }
+  }
+  size_t n_space = space_levels.size();
+  size_t n_reduce = reduce_levels.size();
+
+  spatial_split_step_ids->clear();
+
+  State tmp_s = state;
+  const Stage& stage = state->stages[stage_id];
+  const auto& no_split_name_pair = GetNoSplitAxisAttr(stage);  // handle 
special split strategy
+  const std::set<std::string>& no_split_at_inner_name_set = 
no_split_name_pair.first;
+  const std::set<std::string>& no_split_at_outer_name_set = 
no_split_name_pair.second;
+
+  for (const auto& iter : state->stages[stage_id]->iters) {
+    if (iter->iter_kind == IteratorKind::kSpatial) {
+      if (!no_split_at_inner_name_set.count(iter->name) &&
+          !no_split_at_outer_name_set.count(iter->name)) {
+        CHECK_GE(n_space, 1);
+
+        if (n_space == 1) {
+          space_levels[0].push_back(iter);
+        } else {
+          split_res = tmp_s.split(stage_id, iter, 
Array<Optional<Integer>>(n_space - 1, NullOpt));
+          for (size_t i = 0; i < n_space; i++) {
+            space_levels[i].push_back(split_res[i]);
+          }
+          spatial_split_step_ids->push_back(tmp_s->transform_steps.size() - 1);
+        }
+      } else {
+        if (no_split_at_inner_name_set.count(iter->name)) {
+          space_inner.push_back(iter);
+        }
+        if (no_split_at_outer_name_set.count(iter->name)) {
+          space_outer.push_back(iter);
+        }
+      }
+    } else if (iter->iter_kind == IteratorKind::kReduction) {
+      if (!no_split_at_inner_name_set.count(iter->name) &&
+          !no_split_at_outer_name_set.count(iter->name)) {
+        CHECK_GE(n_reduce, 1);
+
+        if (n_reduce == 1) {
+          reduce_levels[0].push_back(iter);
+        } else {
+          split_res = tmp_s.split(stage_id, iter, 
Array<Optional<Integer>>(n_reduce - 1, NullOpt));
+          for (size_t i = 0; i < n_reduce; i++) {
+            reduce_levels[i].push_back(split_res[i]);
+          }
+        }
+      } else {
+        if (no_split_at_inner_name_set.count(iter->name)) {
+          reduce_inner.push_back(iter);
+        }
+        if (no_split_at_outer_name_set.count(iter->name)) {
+          reduce_outer.push_back(iter);
+        }
+      }
+    } else {
+      LOG(FATAL) << "Invalid iter type: " << int(iter->iter_kind);
+    }
+  }
+
+  if (!space_outer.empty()) {
+    CHECK(!space_levels.empty());
+    space_levels.front().insert(space_levels.front().begin(),
+                                std::make_move_iterator(space_outer.begin()),
+                                std::make_move_iterator(space_outer.end()));
+  }
+  if (!space_inner.empty()) {
+    CHECK(!space_levels.empty());
+    space_levels.back().insert(space_levels.back().begin(),
+                               std::make_move_iterator(space_inner.begin()),
+                               std::make_move_iterator(space_inner.end()));
+  }
+
+  if (!reduce_outer.empty()) {
+    CHECK(!reduce_levels.empty());
+    reduce_levels.front().insert(reduce_levels.front().begin(),
+                                 std::make_move_iterator(reduce_outer.begin()),
+                                 std::make_move_iterator(reduce_outer.end()));
+  }
+  if (!reduce_inner.empty()) {
+    CHECK(!reduce_levels.empty());
+    reduce_levels.back().insert(reduce_levels.back().begin(),
+                                std::make_move_iterator(reduce_inner.begin()),
+                                std::make_move_iterator(reduce_inner.end()));
+  }
+
+  std::vector<Iterator> order;
+  int space_ct = 0, reduce_ct = 0;
+  for (const auto c : format) {
+    if (tolower(c) == 's') {
+      order.insert(order.end(), 
std::make_move_iterator(space_levels[space_ct].begin()),
+                   std::make_move_iterator(space_levels[space_ct].end()));
+      space_ct++;
+    } else if (tolower(c) == 'r') {
+      order.insert(order.end(), 
std::make_move_iterator(reduce_levels[reduce_ct].begin()),
+                   std::make_move_iterator(reduce_levels[reduce_ct].end()));
+      reduce_ct++;
+    } else {
+      LOG(FATAL) << "Invalid multi level tiling format: " << format;
+    }
+  }
+
+  tmp_s.reorder(stage_id, order);
+  return tmp_s;
+}
+
+State FollowTiling(const State& state, int stage_id, const std::vector<int>& 
split_step_ids,
+                   int n_split) {
+  if (n_split < 1 || n_split > 3) {
+    LOG(FATAL) << "Invalid split parts, currently only support 1, 2 and 3";
+  }
+  // Apply up to three-level tiling structure:  space_L0, space_L1, space_L2
+  std::vector<Iterator> space_0, space_1, space_2, space_3, tmp_order;
+  Array<Iterator> split_res;
+
+  auto pop = state->stages[stage_id]->op.as<te::ComputeOpNode>();
+  CHECK(pop != nullptr);
+  const Stage& stage = state->stages[stage_id];
+  const auto& no_split_name_pair = GetNoSplitAxisAttr(stage);  // handle 
special split strategy

Review comment:
       Ditto. I think we should need it.

##########
File path: src/auto_scheduler/compute_dag.cc
##########
@@ -342,11 +343,16 @@ AccessAnalyzer::AccessAnalyzer(const Array<te::Tensor>& 
tensors) {
         has_expensive_op |= HasExpensiveOp(expr);
       }
       if (has_expensive_op || has_branch[op]) {
-        is_strict_inlineable = false;
+        is_strictly_inlineable = false;
+      }
+
+      // constant tensor is strict-inlineable
+      if (node->read_from[op].empty()) {
+        is_strictly_inlineable = true;
       }

Review comment:
       We should always inline const matrix of transform matrices in Winograd. 
However, like `data_pad` which has `branch` but not `constant`, we shouldn't 
always inline it and should let it try different computation location to get 
better performance by solving `parallel-locality-compute` trade off. So I think 
this logic here makes sense to me.

##########
File path: include/tvm/auto_scheduler/search_policy.h
##########
@@ -89,46 +100,54 @@ class SearchCallback : public ObjectRef {
   TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(SearchCallback, ObjectRef, 
SearchCallbackNode);
 };
 
+/*! \brief Attribute keys of ops used for SearchPolicy. */
+struct SearchPolicyKey {
+  /*! \brief Always apply unroll to the inner most iterator of the specificed 
iterators. */
+  static constexpr const char* always_unroll_inner = 
"auto_scheduler_always_unroll_inner";
+  /*! \brief The specified iterators will not be placed as the inner most 
iterator. */
+  static constexpr const char* no_split_at_inner = 
"auto_scheduler_no_split_at_inner";
+  /*! \brief The specified iterators will not be placed as the outter most 
iterator. */
+  static constexpr const char* no_split_at_outer = 
"auto_scheduler_no_split_at_outer";

Review comment:
       I think we will no longer need these two attributes now. These two 
attributes only needed in the original winograd implementation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to