You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/12/09 21:19:54 UTC

[GitHub] [tvm] guberti commented on a diff in pull request #13514: [microTVM] tuning on micro targets with meta-schedule

guberti commented on code in PR #13514:
URL: https://github.com/apache/tvm/pull/13514#discussion_r1043299575


##########
python/tvm/contrib/micro/meta_schedule/local_builder_micro.py:
##########
@@ -0,0 +1,83 @@
+# 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.
+"""Local builder for microTVM projects.that compile on the local host"""

Review Comment:
   nit:
   ```suggestion
   """Local builder for microTVM projects that compile on the local host."""
   ```



##########
python/tvm/contrib/micro/meta_schedule/local_builder_micro.py:
##########
@@ -0,0 +1,83 @@
+# 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.
+"""Local builder for microTVM projects.that compile on the local host"""
+
+import os
+import tempfile
+from typing import Optional, Dict
+from tvm.ir import IRModule
+from tvm.runtime import NDArray
+from tvm.target import Target
+from tvm.meta_schedule.builder import LocalBuilder
+from tvm.driver.build_module import OperatorModule
+from tvm import micro
+from tvm.contrib.tar import tar
+from tvm.relay.backend import Runtime
+from tvm.driver import build as tvm_build
+from tvm.tir.transform import RemoveWeightLayoutRewriteBlock
+
+
+def get_micro_local_builder():
+    """Return micro-compatible Builder for meta schedule."""
+
+    def micro_build(
+        mod: IRModule, target: Target, _params: Optional[Dict[str, NDArray]]
+    ) -> OperatorModule:
+        """build function for micro targets.
+
+        Parameters
+        ----------
+        mod : IRModule
+            The IRModule to be built.
+        target : Target
+            The target to be built.
+        _params : Optional[Dict[str, NDArray]]
+            The parameters to be used for the build. Must be None.
+
+        Returns
+        -------
+        rt_mod : OperatorModule
+            The built Module.
+        """
+
+        # Note: changing the global symbol is necessary for micro targets,
+        # since the generated projects already include a main function.
+        prim_func = mod["main"].with_attr("global_symbol", "default_function")

Review Comment:
   What is the global symbol? I assume it's a function name, but for what?



##########
python/tvm/contrib/micro/meta_schedule/rpc_runner_micro.py:
##########
@@ -0,0 +1,243 @@
+# 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.
+"""RPC Runner Micro"""
+
+from contextlib import contextmanager
+from typing import Callable, List, Optional
+from collections import namedtuple
+import signal
+
+from tvm import micro
+from tvm import nd
+from tvm.contrib.popen_pool import PopenPoolExecutor
+from tvm.rpc.server import Server
+from tvm.rpc.tracker import Tracker
+from tvm.meta_schedule.logging import get_logger
+from tvm.meta_schedule.utils import (
+    cpu_count,
+    derived_object,
+)

Review Comment:
   ```suggestion
   from tvm.meta_schedule.utils import cpu_count, derived_object
   ```



##########
python/tvm/contrib/micro/meta_schedule/local_builder_micro.py:
##########
@@ -0,0 +1,83 @@
+# 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.
+"""Local builder for microTVM projects.that compile on the local host"""
+
+import os
+import tempfile
+from typing import Optional, Dict
+from tvm.ir import IRModule
+from tvm.runtime import NDArray
+from tvm.target import Target
+from tvm.meta_schedule.builder import LocalBuilder
+from tvm.driver.build_module import OperatorModule
+from tvm import micro
+from tvm.contrib.tar import tar
+from tvm.relay.backend import Runtime
+from tvm.driver import build as tvm_build
+from tvm.tir.transform import RemoveWeightLayoutRewriteBlock
+
+
+def get_micro_local_builder():
+    """Return micro-compatible Builder for meta schedule."""
+
+    def micro_build(
+        mod: IRModule, target: Target, _params: Optional[Dict[str, NDArray]]
+    ) -> OperatorModule:
+        """build function for micro targets.

Review Comment:
   nit:
   ```suggestion
           """Build function for micro targets.
   ```



##########
python/tvm/contrib/micro/meta_schedule/local_builder_micro.py:
##########
@@ -0,0 +1,83 @@
+# 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.
+"""Local builder for microTVM projects.that compile on the local host"""
+
+import os
+import tempfile
+from typing import Optional, Dict
+from tvm.ir import IRModule
+from tvm.runtime import NDArray
+from tvm.target import Target
+from tvm.meta_schedule.builder import LocalBuilder
+from tvm.driver.build_module import OperatorModule
+from tvm import micro
+from tvm.contrib.tar import tar
+from tvm.relay.backend import Runtime
+from tvm.driver import build as tvm_build
+from tvm.tir.transform import RemoveWeightLayoutRewriteBlock
+
+
+def get_micro_local_builder():
+    """Return micro-compatible Builder for meta schedule."""
+
+    def micro_build(
+        mod: IRModule, target: Target, _params: Optional[Dict[str, NDArray]]
+    ) -> OperatorModule:
+        """build function for micro targets.
+
+        Parameters
+        ----------
+        mod : IRModule
+            The IRModule to be built.
+        target : Target
+            The target to be built.
+        _params : Optional[Dict[str, NDArray]]
+            The parameters to be used for the build. Must be None.
+
+        Returns
+        -------
+        rt_mod : OperatorModule
+            The built Module.
+        """
+
+        # Note: changing the global symbol is necessary for micro targets,
+        # since the generated projects already include a main function.
+        prim_func = mod["main"].with_attr("global_symbol", "default_function")
+        mod = IRModule({"main": prim_func})
+        runtime = Runtime("crt", {"system-lib": True})
+        mod = RemoveWeightLayoutRewriteBlock(skip_ndarray_rewrite=True)(mod)
+        rt_mod = tvm_build(mod, target=target, runtime=runtime)
+        return rt_mod
+
+    def micro_export(mod: OperatorModule) -> str:
+        """export function for micro targets.

Review Comment:
   nit:
   ```suggestion
           """Export function for micro targets.
   ```



##########
python/tvm/contrib/micro/meta_schedule/local_builder_micro.py:
##########
@@ -0,0 +1,83 @@
+# 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.
+"""Local builder for microTVM projects.that compile on the local host"""
+
+import os
+import tempfile
+from typing import Optional, Dict
+from tvm.ir import IRModule
+from tvm.runtime import NDArray
+from tvm.target import Target
+from tvm.meta_schedule.builder import LocalBuilder
+from tvm.driver.build_module import OperatorModule
+from tvm import micro
+from tvm.contrib.tar import tar
+from tvm.relay.backend import Runtime
+from tvm.driver import build as tvm_build
+from tvm.tir.transform import RemoveWeightLayoutRewriteBlock
+
+
+def get_micro_local_builder():

Review Comment:
   Since `micro_build` and `micro_export` don't use local variables from `get_micro_local_builder`, I'd prefer to have them as module level functions (e.g. `_micro_build` and `_micro_export`).



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org