mbaret commented on a change in pull request #9469:
URL: https://github.com/apache/tvm/pull/9469#discussion_r773771558



##########
File path: src/contrib/ethosu/cascader/common.h
##########
@@ -103,6 +119,18 @@ inline std::size_t hash_vector(const std::vector<T>& vec) {
   return seed;
 }
 
+template <class T>
+inline T mul_reduce(const std::vector<T>& vec) {
+  if (vec.size() == 0) {
+    return 0;
+  }
+  T v = vec[0];
+  for (unsigned int i = 1; i < vec.size(); i++) {
+    v *= vec[i];
+  }
+  return v;
+}

Review comment:
       I've kept the function as I think it's a useful shorthand, but have 
changed the implementation to your suggestion.

##########
File path: src/contrib/ethosu/cascader/graph.h
##########
@@ -0,0 +1,321 @@
+/*
+ * 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 src/contrib/ethosu/cascader/graph.h
+ * \brief Graph objects (Tensor and Part) for the Ethos-U cascader
+ */
+#ifndef TVM_CONTRIB_ETHOSU_CASCADER_GRAPH_H_
+#define TVM_CONTRIB_ETHOSU_CASCADER_GRAPH_H_
+
+#include <tvm/runtime/data_type.h>
+#include <tvm/runtime/object.h>
+#include <tvm/te/operation.h>
+#include <tvm/te/tensor.h>
+
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include "propagator.h"
+
+namespace tvm {
+namespace contrib {
+namespace ethosu {
+namespace cascader {
+
+class Tensor;
+class Part;
+class StripeConfig;
+
+/*! \brief A struct to hold a Tensor Expression subgraph */
+struct TESubgraph {
+  /*! \brief The input te::Tensors to the subgraph */
+  std::vector<te::Tensor> input_tensors;
+  /*! \brief The output te::Tensor of the subgraph */
+  te::Tensor output_tensor;
+};
+
+/*! \brief Node to hold performance information for a Part */
+class PerformanceInfoNode : public Object {
+ public:
+  void VisitAttrs(AttrVisitor* v);
+
+  /*! \brief The cycles to compute a block */
+  size_t compute_cycles;
+  /*! \brief The number of bytes read per input tensor */
+  std::vector<size_t> read_bytes;
+  /*! \brief The number of bytes written to the output tensor */
+  size_t write_bytes;
+
+  static constexpr const char* _type_key = 
"contrib.ethosu.cascader.PerformanceInfo";
+  TVM_DECLARE_FINAL_OBJECT_INFO(PerformanceInfoNode, Object);
+};
+
+/*!
+ * \brief An class to hold the performance information for a Part.
+ * \note The performance information for a Part is composed of 3 factors: the 
compute cycles,
+ * the number of bytes read from each input tensor and the number of bytes 
written to the output
+ * tensor. Bytes read/written is reported in favour of read/write bandwidth 
cycles so the
+ * calculation of the performance information can be re-used with different 
memory homing.
+ */
+class PerformanceInfo : public ObjectRef {
+ public:
+  PerformanceInfo(size_t compute_cycles, std::vector<size_t> read_bytes, 
size_t write_bytes) {
+    auto n = make_object<PerformanceInfoNode>();
+    n->compute_cycles = compute_cycles;
+    n->read_bytes = std::move(read_bytes);
+    n->write_bytes = write_bytes;
+    data_ = std::move(n);
+  }
+
+  TVM_DEFINE_OBJECT_REF_METHODS(PerformanceInfo, ObjectRef, 
PerformanceInfoNode);
+};
+
+/*! \brief Node to represent a Tensor */
+class TensorNode : public Object {
+ public:
+  void VisitAttrs(AttrVisitor* v);
+
+  /*! \return The shape of the tensor */

Review comment:
       Making the members public isn't enough on its own to reflect them into 
Python, PerformanceInfo still defines VisitAttrs. Tensor having 
MUTABLE_OBJECT_REF is so that AddProducer/Consumer work as these are non-const 
methods.

##########
File path: cmake/modules/contrib/EthosU.cmake
##########
@@ -18,7 +18,8 @@
 if(USE_ETHOSU)
   file(GLOB COMPILER_ETHOSU_SRCS
        CONFIGURE_DEPENDS src/relay/backend/contrib/ethosu/*
-       CONFIGURE_DEPENDS src/contrib/ethosu/cascader/*)
+       CONFIGURE_DEPENDS src/contrib/ethosu/cascader/*

Review comment:
       Understood, good catch. I've added these files to the 'else' condition 
here.

##########
File path: python/tvm/contrib/ethosu/cascader/graph.py
##########
@@ -0,0 +1,170 @@
+# 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.
+"""Graph objects to define compute graphs for the NPU cascader."""
+from typing import List
+from collections import namedtuple
+import tvm._ffi
+
+from tvm.runtime import Object
+
+from .stripe_config import StripeConfig
+from . import _ffi_api
+
+
+TESubgraph = namedtuple("TESubgraph", ["input_tensors", "output_tensor"])
+
+
+@tvm._ffi.register_object("contrib.ethosu.cascader.PerformanceInfo")
+class PerformanceInfo(Object):

Review comment:
       ack




-- 
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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to