comaniac commented on a change in pull request #6222:
URL: https://github.com/apache/incubator-tvm/pull/6222#discussion_r468046750



##########
File path: src/relay/backend/contrib/ethosn/ethosn_api.h
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.
+ */
+
+#ifndef TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_API_H_
+#define TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_API_H_
+
+#include <tvm/relay/expr.h>
+#include <tvm/relay/expr_functor.h>
+#include <tvm/relay/transform.h>
+#include <tvm/tir/analysis.h>
+#include <tvm/tir/op.h>
+
+#include <algorithm>
+#include <limits>
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "ethosn_support_library/Support.hpp"
+#include "ethosn_support_library/SupportQueries.hpp"
+
+namespace tvm {
+namespace relay {
+namespace contrib {
+namespace ethosn {
+
+namespace sl = ::ethosn::support_library;
+
+struct ConcatenateParams {
+  sl::QuantizationInfo qInfo;
+  sl::ConcatenationInfo concat_info = sl::ConcatenationInfo(1, qInfo);
+  std::vector<sl::TensorInfo> input_infos;
+};
+
+struct SplitParams {
+  sl::SplitInfo split_info = sl::SplitInfo(0, {});
+  sl::TensorInfo input_info;
+};
+
+class ErrStrm {
+ public:
+  template <typename T>
+  ErrStrm& operator<<(const T& val) {  // NOLINT(*)
+    stream_ << val;
+    return *this;
+  }
+
+ private:
+  std::stringstream stream_;
+  friend class EthosnError;
+};
+
+class EthosnError {
+ public:
+  EthosnError() {}
+  explicit EthosnError(const Array<String>& msgs) : msgs(msgs) {}
+  explicit EthosnError(const String& msg) { msgs.push_back(msg); }
+  explicit EthosnError(const ErrStrm& err) : EthosnError(err.stream_.str()) {}
+
+  explicit operator bool() const { return !msgs.empty(); }
+
+  EthosnError& operator+=(const EthosnError& other) {
+    msgs.insert(msgs.end(), other.msgs.begin(), other.msgs.end());
+    return *this;
+  }
+
+  Array<String> msgs;
+};
+
+class EthosnAPI {
+ public:
+  static std::unique_ptr<sl::CompiledNetwork> 
Compile(std::shared_ptr<sl::Network> network,
+                                                      const 
sl::CompilationOptions& options);
+
+  static sl::CompilationOptions CreateOptions();
+
+  static bool IsEthosFunc(const Call& call, const std::string& op_name);
+  static bool IsEthosOp(const Call& call, const std::string& op_name);
+
+  static EthosnError Concatenate(const Expr& expr, ConcatenateParams* params);
+  static EthosnError Split(const Expr& expr, SplitParams* params);
+
+ private:
+  static EthosnError Tvm2Npu(const Array<IndexExpr>& shape, sl::TensorShape* 
npu_shape);
+  static EthosnError Tvm2Npu(const tvm::DataType& dtype, sl::DataType* 
data_type);

Review comment:
       This API actually takes the shape and type of a TVM tensor and allocates 
a support library tensor. To me, this is more like creating a support library 
tensor with provided spec (shape and type). "TVM data structures to Support 
Library data structures" is more like creating a Support Library tensor and 
filling in data from the given TVM tensor.
   
   In terms of the name you just proposed, I personally think `Tvm2Npu` is 
better than `Tvm2SL` because "SL" to "Support Library" is not straightforward 
as "NPU" to "Ethos-N".




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to