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



##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -0,0 +1,90 @@
+# 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.
+# pylint: disable=invalid-name, unused-argument
+"""Arm(R) Ethos(TM) -N NPU supported operators."""
+import tvm.ir
+from enum import Enum
+from ... import qnn as _qnn
+from . import _ethosn as support
+
+
+class Available(Enum):
+    UNAVAILABLE = 0
+    SW_ONLY = 1
+    SW_AND_HW = 2
+
+    def __bool__(self):
+        return self != Available.UNAVAILABLE
+
+
+def ethosn_available():
+    """Return whether Ethos-N software and hardware support is available"""
+    if not tvm.get_global_func("relay.ethos-n.query", True):
+        print("skip because Ethos-N module is not available")
+        return Available.UNAVAILABLE
+    else:
+        hw = tvm.get_global_func("relay.ethos-n.query")()
+        return Available.SW_AND_HW if hw else Available.SW_ONLY
+
+
[email protected]_op_attr("qnn.concatenate", "target.ethos-n")
+def qnn_concatenate(attrs, args):
+    """Check if a concatenate is supported by Ethos-N."""
+    if not ethosn_available():
+        return False
+
+    conc = _qnn.op.concatenate(*args, **attrs)
+    if not support.concatenate(conc):
+        return False
+
+    # Support library has some unenforced restrictions on qnn params
+    min_range = 1e9
+    max_range = -1e9
+    qnn_params = []
+    for i in range(len(args[1].fields)):
+        scale = args[1].fields[i].data.asnumpy()
+        zero_point = args[2].fields[i].data.asnumpy()
+        min_range = min(-1 * zero_point * scale, min_range)
+        max_range = max((255 - zero_point) * scale, max_range)
+        qnn_params.append((scale, zero_point))
+
+    scale = (max_range - min_range) / 255
+    zero_point = int(-min_range/scale)
+    if (scale, zero_point) in qnn_params:
+        return True
+
+    return False
+
+
[email protected]_op_attr("split", "target.ethos-n")
+def split(attrs, args):

Review comment:
       Conv2D is coming in the next PR. We split it up like this so that we 
could focus initially on the mechanics of the integration itself. Split/Concat 
motivate the tuple handling in the codegen which is why they were introduced 
now. Conv2D has a lot of other complexity to do with conversion between TVM and 
Support Library and so we thought that would be best handled separately.




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