You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ma...@apache.org on 2022/11/18 20:26:21 UTC

[tvm] branch main updated: [Fix,Roofline] Handle zero length features in roofline (#13424)

This is an automated email from the ASF dual-hosted git repository.

masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new b023e9539c [Fix,Roofline] Handle zero length features in roofline (#13424)
b023e9539c is described below

commit b023e9539c33a2fa43207a122ec60ad11c67314b
Author: Tristan Konolige <tk...@octoml.ai>
AuthorDate: Fri Nov 18 12:26:16 2022 -0800

    [Fix,Roofline] Handle zero length features in roofline (#13424)
    
    These features may occur for extern ops.
---
 python/tvm/auto_scheduler/feature.py  | 2 ++
 python/tvm/utils/roofline/__init__.py | 2 ++
 src/auto_scheduler/feature.cc         | 5 ++++-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/python/tvm/auto_scheduler/feature.py b/python/tvm/auto_scheduler/feature.py
index 491f8b7643..21db37abd4 100644
--- a/python/tvm/auto_scheduler/feature.py
+++ b/python/tvm/auto_scheduler/feature.py
@@ -327,4 +327,6 @@ def named_features_from_primfunc(
     """
     features = features_from_primfunc(func, cache_line_bytes, max_n_bufs, log_scale)
     names = get_per_store_feature_names(max_n_bufs)
+    if features.shape[0] == 0:
+        return None
     return {name: features[:, i] for i, name in enumerate(names)}
diff --git a/python/tvm/utils/roofline/__init__.py b/python/tvm/utils/roofline/__init__.py
index 3b0144cb90..1129ac2c0e 100644
--- a/python/tvm/utils/roofline/__init__.py
+++ b/python/tvm/utils/roofline/__init__.py
@@ -142,6 +142,8 @@ def roofline_from_existing(
     for call in report.calls:
         if "Hash" in call.keys() and call["Hash"] in all_features:
             _, prim, features = all_features[call["Hash"]]
+            if features is None:
+                continue
 
             with target:
                 flops, peak_flops, flops_name = registry.estimate_peak_flops(
diff --git a/src/auto_scheduler/feature.cc b/src/auto_scheduler/feature.cc
index 0b5a157c88..2f993c0c8b 100644
--- a/src/auto_scheduler/feature.cc
+++ b/src/auto_scheduler/feature.cc
@@ -1737,7 +1737,10 @@ TVM_REGISTER_GLOBAL("auto_scheduler.FeaturesFromPrimFunc")
       std::vector<float> vec;
       GetPerStoreFeature(func, cache_line_size, max_n_bufs, &vec, log_scale);
       int64_t num_feature_rows = vec[0];  // first element is number of rows
-      int64_t row_length = (vec.size() - 1) / num_feature_rows;
+      int64_t row_length = 0;
+      if (num_feature_rows != 0) {
+        row_length = (vec.size() - 1) / num_feature_rows;
+      }
       auto ary =
           runtime::NDArray::Empty({num_feature_rows, row_length}, {kDLFloat, 32, 1}, {kDLCPU, 0});
       // NDArray is row major by default