stoa commented on a change in pull request #7742:
URL: https://github.com/apache/tvm/pull/7742#discussion_r720874174



##########
File path: python/tvm/micro/contrib/stm32/emitter.py
##########
@@ -0,0 +1,1369 @@
+# 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=line-too-long
+
+"""Code emission for the STM32 targets."""
+
+import json
+import os
+import re
+import shutil
+import tarfile
+import textwrap
+
+from datetime import datetime
+
+import numpy as np
+
+import tvm
+from tvm.contrib import utils
+
+AI_API_VERSION_MAJOR = 1
+AI_API_VERSION_MINOR = 0
+AI_API_VERSION_MICRO = 0
+
+AI_TOOLS_REVISION = "v1"
+
+DBAR = "=" * 60
+
+
+def _fix_name(node_name):
+    """ Replace ':' with '_' in names like 'InputImg:0' """
+    return node_name.replace(":", "_")
+
+
+def get_input_tensor_name(node_name):
+    return _fix_name(node_name)
+
+
+def get_output_tensor_name(node_name, idx):
+    return _fix_name(node_name) + "_" + str(idx)
+
+
+def _get_node_args_name(node_name):
+    return _fix_name(node_name) + "_args"
+
+
+def _get_node_arg_types_name(node_name):
+    return _fix_name(node_name) + "_arg_type_ids"
+
+
+def _get_type_size(dltype):
+    if dltype in ("uint64", "int64"):
+        return 8
+    if dltype in ("uint32", "int32", "float32"):
+        return 4
+    if dltype in ("uint16", "int16"):
+        return 2
+    if dltype in ("uint8", "int8"):
+        return 1
+    raise ValueError(f"Data type {dltype} is not supported")
+
+
+C_TYPE_TO_DLTYPE = {
+    "uint64": "kDLUInt, 64, 1",
+    "int64": "kDLInt, 64, 1",
+    "float32": "kDLFloat, 32, 1",
+    "uint32": "kDLUInt, 32, 1",
+    "int32": "kDLInt, 32, 1",
+    "uint16": "kDLUInt, 16, 1",
+    "int16": "kDLInt, 16, 1",
+    "uint8": "kDLUInt, 8, 1",
+    "int8": "kDLInt, 8, 1",
+}
+
+
+def _get_type_data(dltype):
+    try:
+        return C_TYPE_TO_DLTYPE[dltype]
+    except KeyError:
+        raise ValueError(f"Data type {dltype} is not supported")
+
+
+def _get_aligned_offset(offset, dltype):
+    align = _get_type_size(dltype)
+    if offset % align != 0:
+        offset = offset + (align - offset % align)
+    return offset
+
+
+def _get_num_tensor_elts(shape):
+    size = 1
+    for dim in shape:
+        size = size * dim
+    return size
+
+
+def _get_tensor_size_bytes(dims, dltype):
+    size = _get_num_tensor_elts(dims)
+    return size * _get_type_size(dltype)
+
+
+def _preprocess_code(src):

Review comment:
       Yes. Because math.h is missing (perhaps no longer missing in the newwest 
TVM), and because we have a CMSIS option that I will contribute later that 
needs more.




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