huajsj commented on a change in pull request #7892:
URL: https://github.com/apache/tvm/pull/7892#discussion_r645216506



##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Minimum pipeline executor that executes pipeline containing TVM 
PackedFunc."""

Review comment:
       fixed.

##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Minimum pipeline executor that executes pipeline containing TVM 
PackedFunc."""
+import json
+import tvm._ffi
+from tvm import relay
+from tvm.contrib import graph_executor
+
+
+def build_pipeline(config):
+    """build module list that can use for pipeline execution.
+    Parameters:
+    ir_mods:
+        list of IRModule
+
+    config:
+        build configuration informaiton, structure like following.
+        {IRModule: {"target":target,
+                    "target_host":target_host,
+                    "params":params,
+                    "mod_name"mod_name,
+                    "build":build}}
+
+    Return:
+        list of IRModule

Review comment:
       fixed.

##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Minimum pipeline executor that executes pipeline containing TVM 
PackedFunc."""
+import json
+import tvm._ffi
+from tvm import relay
+from tvm.contrib import graph_executor
+
+
+def build_pipeline(config):
+    """build module list that can use for pipeline execution.
+    Parameters:
+    ir_mods:
+        list of IRModule
+
+    config:
+        build configuration informaiton, structure like following.
+        {IRModule: {"target":target,
+                    "target_host":target_host,
+                    "params":params,
+                    "mod_name"mod_name,
+                    "build":build}}
+
+    Return:
+        list of IRModule
+    """
+    mods = {}
+    string_config = [{}] * len(config)
+    for ir_mod in config:
+        mod_config = config[ir_mod]
+        string_config[mod_config["pipeline"]["mod_indx"] - 1] = 
mod_config["pipeline"]
+        build_func = relay.build
+        # if there is a self defined build function then use it.
+        if mod_config["build"]:
+            build_func = mod_config.build
+
+        mod = build_func(
+            ir_mod,
+            mod_config["target"],
+            params=mod_config["params"],
+            target_host=mod_config["target_host"],
+            mod_name=mod_config["mod_name"],
+        )
+
+        mods[mod] = {"dev": mod_config["dev"]}
+
+    return mods, string_config
+
+
+def create(mods, mod_config):
+    """Create a pipeline runtime executor.
+
+    Parameters
+    ----------
+    sub_mods :
+        {"lib": <module>,
+         "dev": <device>}
+
+    Returns
+    -------
+    submodule : PipelineModule
+        Runtime pipeline module.
+    """
+    pipeline_mods, string_config = build_pipeline(mod_config)
+
+    mods = []
+    for pipeline_mod in pipeline_mods:
+        mod = graph_executor.GraphModule(
+            pipeline_mod["default"](pipeline_mods[pipeline_mod]["dev"])
+        )
+
+        mods.append(mod)
+
+    submodule = PipelineModule(mods, json.dumps(string_config))
+    return submodule
+
+
+class PipelineModule(object):
+    """Wrapper runtime module.
+
+    This is a thin wrapper of the underlying TVM module.
+    you can also directly call set_input, run, and get_output
+    of underlying module functions
+
+    Parameters
+    ----------
+    module : tvm.runtime.Module
+        The internal tvm module that holds the actual graph functions.
+
+    Attributes
+    ----------
+    module : tvm.runtime.Module
+        The internal tvm module that holds the actual graph functions.
+
+    """
+
+    def __init__(self, graph_modules, pipeline_config):
+        mods = []
+        for module in graph_modules:
+            mods.append(module.module)
+
+        pipelinecreate = 
tvm._ffi.get_global_func("tvm.pipeline_executor.create")
+        module = pipelinecreate(mods, pipeline_config)
+
+        self.graph_modules_ = graph_modules
+
+        self._set_input = module["set_input"]
+        self._run = module["run"]
+        self._stop = module["stop"]
+        self._get_output = module["get_output"]
+        self._get_input = module["get_input"]
+        self._get_num_outputs = module["get_num_outputs"]
+        self._get_num_inputs = module["get_num_inputs"]
+
+    def set_input(self, key=None, value=None, params=None):
+        """Set inputs to the module via kwargs
+
+        Parameters
+        ----------
+        key : int or str
+           The input key
+
+        value : the input value.

Review comment:
       fixed.

##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Minimum pipeline executor that executes pipeline containing TVM 
PackedFunc."""
+import json
+import tvm._ffi
+from tvm import relay
+from tvm.contrib import graph_executor
+
+
+def build_pipeline(config):
+    """build module list that can use for pipeline execution.
+    Parameters:
+    ir_mods:
+        list of IRModule
+
+    config:
+        build configuration informaiton, structure like following.
+        {IRModule: {"target":target,
+                    "target_host":target_host,
+                    "params":params,
+                    "mod_name"mod_name,
+                    "build":build}}
+
+    Return:
+        list of IRModule
+    """
+    mods = {}
+    string_config = [{}] * len(config)
+    for ir_mod in config:
+        mod_config = config[ir_mod]
+        string_config[mod_config["pipeline"]["mod_indx"] - 1] = 
mod_config["pipeline"]
+        build_func = relay.build
+        # if there is a self defined build function then use it.
+        if mod_config["build"]:
+            build_func = mod_config.build
+
+        mod = build_func(
+            ir_mod,
+            mod_config["target"],
+            params=mod_config["params"],
+            target_host=mod_config["target_host"],
+            mod_name=mod_config["mod_name"],
+        )
+
+        mods[mod] = {"dev": mod_config["dev"]}
+
+    return mods, string_config
+
+
+def create(mods, mod_config):
+    """Create a pipeline runtime executor.
+
+    Parameters
+    ----------
+    sub_mods :
+        {"lib": <module>,
+         "dev": <device>}
+
+    Returns
+    -------
+    submodule : PipelineModule
+        Runtime pipeline module.
+    """
+    pipeline_mods, string_config = build_pipeline(mod_config)
+
+    mods = []
+    for pipeline_mod in pipeline_mods:
+        mod = graph_executor.GraphModule(
+            pipeline_mod["default"](pipeline_mods[pipeline_mod]["dev"])
+        )
+
+        mods.append(mod)
+
+    submodule = PipelineModule(mods, json.dumps(string_config))
+    return submodule
+
+
+class PipelineModule(object):
+    """Wrapper runtime module.
+
+    This is a thin wrapper of the underlying TVM module.
+    you can also directly call set_input, run, and get_output
+    of underlying module functions
+
+    Parameters
+    ----------
+    module : tvm.runtime.Module
+        The internal tvm module that holds the actual graph functions.
+
+    Attributes
+    ----------
+    module : tvm.runtime.Module
+        The internal tvm module that holds the actual graph functions.
+
+    """
+
+    def __init__(self, graph_modules, pipeline_config):
+        mods = []
+        for module in graph_modules:
+            mods.append(module.module)
+
+        pipelinecreate = 
tvm._ffi.get_global_func("tvm.pipeline_executor.create")
+        module = pipelinecreate(mods, pipeline_config)
+
+        self.graph_modules_ = graph_modules
+
+        self._set_input = module["set_input"]
+        self._run = module["run"]
+        self._stop = module["stop"]
+        self._get_output = module["get_output"]
+        self._get_input = module["get_input"]
+        self._get_num_outputs = module["get_num_outputs"]
+        self._get_num_inputs = module["get_num_inputs"]
+
+    def set_input(self, key=None, value=None, params=None):
+        """Set inputs to the module via kwargs
+
+        Parameters
+        ----------
+        key : int or str
+           The input key
+
+        value : the input value.
+           The input key
+
+        params : dict of str to NDArray
+           Additional arguments
+        """
+        if key is not None:

Review comment:
       fixed.

##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Minimum pipeline executor that executes pipeline containing TVM 
PackedFunc."""
+import json
+import tvm._ffi
+from tvm import relay
+from tvm.contrib import graph_executor
+
+
+def build_pipeline(config):
+    """build module list that can use for pipeline execution.
+    Parameters:
+    ir_mods:
+        list of IRModule
+
+    config:
+        build configuration informaiton, structure like following.
+        {IRModule: {"target":target,
+                    "target_host":target_host,
+                    "params":params,
+                    "mod_name"mod_name,
+                    "build":build}}
+
+    Return:
+        list of IRModule
+    """
+    mods = {}
+    string_config = [{}] * len(config)
+    for ir_mod in config:
+        mod_config = config[ir_mod]
+        string_config[mod_config["pipeline"]["mod_indx"] - 1] = 
mod_config["pipeline"]
+        build_func = relay.build
+        # if there is a self defined build function then use it.
+        if mod_config["build"]:
+            build_func = mod_config.build
+
+        mod = build_func(
+            ir_mod,
+            mod_config["target"],
+            params=mod_config["params"],
+            target_host=mod_config["target_host"],
+            mod_name=mod_config["mod_name"],
+        )
+
+        mods[mod] = {"dev": mod_config["dev"]}
+
+    return mods, string_config
+
+
+def create(mods, mod_config):
+    """Create a pipeline runtime executor.
+
+    Parameters
+    ----------
+    sub_mods :
+        {"lib": <module>,
+         "dev": <device>}
+
+    Returns
+    -------
+    submodule : PipelineModule
+        Runtime pipeline module.
+    """
+    pipeline_mods, string_config = build_pipeline(mod_config)
+
+    mods = []
+    for pipeline_mod in pipeline_mods:
+        mod = graph_executor.GraphModule(
+            pipeline_mod["default"](pipeline_mods[pipeline_mod]["dev"])
+        )
+
+        mods.append(mod)
+
+    submodule = PipelineModule(mods, json.dumps(string_config))
+    return submodule
+
+
+class PipelineModule(object):
+    """Wrapper runtime module.
+
+    This is a thin wrapper of the underlying TVM module.
+    you can also directly call set_input, run, and get_output
+    of underlying module functions
+
+    Parameters
+    ----------
+    module : tvm.runtime.Module
+        The internal tvm module that holds the actual graph functions.
+
+    Attributes
+    ----------
+    module : tvm.runtime.Module
+        The internal tvm module that holds the actual graph functions.
+
+    """
+
+    def __init__(self, graph_modules, pipeline_config):
+        mods = []
+        for module in graph_modules:
+            mods.append(module.module)
+
+        pipelinecreate = 
tvm._ffi.get_global_func("tvm.pipeline_executor.create")

Review comment:
       fixed.

##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Minimum pipeline executor that executes pipeline containing TVM 
PackedFunc."""
+import json
+import tvm._ffi
+from tvm import relay
+from tvm.contrib import graph_executor
+
+
+def build_pipeline(config):
+    """build module list that can use for pipeline execution.
+    Parameters:
+    ir_mods:
+        list of IRModule
+
+    config:
+        build configuration informaiton, structure like following.
+        {IRModule: {"target":target,
+                    "target_host":target_host,
+                    "params":params,
+                    "mod_name"mod_name,
+                    "build":build}}
+
+    Return:
+        list of IRModule
+    """
+    mods = {}
+    string_config = [{}] * len(config)
+    for ir_mod in config:
+        mod_config = config[ir_mod]
+        string_config[mod_config["pipeline"]["mod_indx"] - 1] = 
mod_config["pipeline"]

Review comment:
       fixed.

##########
File path: python/tvm/contrib/pipeline_executor.py
##########
@@ -0,0 +1,223 @@
+# 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.
+"""Minimum pipeline executor that executes pipeline containing TVM 
PackedFunc."""
+import json
+import tvm._ffi
+from tvm import relay
+from tvm.contrib import graph_executor
+
+
+def build_pipeline(config):
+    """build module list that can use for pipeline execution.
+    Parameters:
+    ir_mods:
+        list of IRModule
+
+    config:
+        build configuration informaiton, structure like following.
+        {IRModule: {"target":target,
+                    "target_host":target_host,
+                    "params":params,
+                    "mod_name"mod_name,
+                    "build":build}}
+
+    Return:
+        list of IRModule
+    """
+    mods = {}
+    string_config = [{}] * len(config)

Review comment:
       fixed.




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