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



##########
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:
       Need to check if `pipeline` and `mod_index` are in `mod_config`; 
`mod_config["pipeline"]["mod_indx"] - 1` is not out of boundary.

##########
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:
       Please use the standard docstring style. Ditto to others.
   
   ```suggestion
   
       Parameters
       ----------
       ir_mods: List[IRModule]
           list of IRModule
   
       config: Dict[IRModule, Dict[str, Any]]
           build configuration information, structure like following.
           {IRModule: {"target":target,
                       "target_host":target_host,
                       "params":params,
                       "mod_name"mod_name,
                       "build":build}}
   
       Returns
       -------
       ret: List[IRModule]
           A list of built IR modules.
   ```

##########
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:
       `the input value` is not a type.

##########
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:
       Why `key` and `value` are allowed to be None?

##########
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"]:

Review comment:
       You basically need to check wheher all required configs are specified in 
the beginning of this function.
   
   ```suggestion
           if "build" in mod_config and mod_config["build"]:
   ```

##########
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:
       Do not use this style. It's dangerous and usually not what you want, 
because all elements are pointing to the same reference. For example
   ```python
   >>> cfg = [{}] * 3
   >>> cfg[0]["aa"] = 4
   >>> cfg
   [{'aa': 4}, {'aa': 4}, {'aa': 4}]
   ```
   
   Instead, 
   ```python
   >>> string_config = [{} for _ in range(len(config))]
   >>> string_config[0]["aa"] = 4
   >>> string_config
   [{'aa': 4}, {}, {}]
   ```

##########
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:
       missing a checker.

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

Review comment:
       ```suggestion
       """Wrapper runtime module. This is a wrapper of the underlying TVM 
module.
       You can also directly call set_input, run, and get_output of underlying 
module functions.
   ```

##########
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:
       ```suggestion
   """Pipeline executor that executes pipeline containing TVM PackedFunc."""
   ```

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

Review comment:
       ```suggestion
           mods = [module.module for module in graph_modules]
   ```

##########
File path: src/runtime/pipeline/pipeline_executor.cc
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file pipeline_executor.cc
+ */
+#include "pipeline_executor.h"
+
+#include <tvm/runtime/registry.h>
+
+namespace tvm {
+namespace runtime {
+
+/*!
+ *\bief Stop pipeline run.
+ */
+void SubGraphRuntime::Stop() { pipeline_stop(runtimes); }
+/*!
+ * \brief Run all the operations one by one.
+ */
+void SubGraphRuntime::Run() { pipeline_run(runtimes); }
+
+void SubGraphRuntime::Init(const Array<tvm::runtime::Module>& modules,
+                           const std::string& pipeline_json) {
+  std::istringstream is(pipeline_json);
+  dmlc::JSONReader reader(&is);
+  this->Load(&reader);
+  pipeline_init(modules, &runtimes, &pipeline_conf);
+  return;
+}
+
+/*!
+ * \brief set index-th input to the graph.
+ * \param index The input index.
+ * \param data_in The input data.
+ */
+void SubGraphRuntime::SetInput(int index, DLTensor* data_in) {
+  auto gruntime = runtimes.front();

Review comment:
       What if other modules also have primary inputs?

##########
File path: cmake/config.cmake
##########
@@ -98,6 +98,8 @@ set(USE_STACKVM_RUNTIME OFF)
 
 # Whether enable tiny embedded graph executor.
 set(USE_GRAPH_EXECUTOR ON)
+# Whether enable subgraph runtime.
+set(USE_PIPELINE_EXECUTOR ON)

Review comment:
       Let's make it off by default as it is an experimental feature.
   
   ```suggestion
   
   # Whether enable subgraph runtime.
   set(USE_PIPELINE_EXECUTOR OFF)
   ```

##########
File path: src/runtime/pipeline/pipeline_executor.cc
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+
+/*!
+ * \file pipeline_executor.cc
+ */
+#include "pipeline_executor.h"
+
+#include <tvm/runtime/registry.h>
+
+namespace tvm {
+namespace runtime {
+
+/*!
+ *\bief Stop pipeline run.
+ */
+void SubGraphRuntime::Stop() { pipeline_stop(runtimes); }
+/*!
+ * \brief Run all the operations one by one.
+ */
+void SubGraphRuntime::Run() { pipeline_run(runtimes); }
+
+void SubGraphRuntime::Init(const Array<tvm::runtime::Module>& modules,
+                           const std::string& pipeline_json) {
+  std::istringstream is(pipeline_json);
+  dmlc::JSONReader reader(&is);
+  this->Load(&reader);
+  pipeline_init(modules, &runtimes, &pipeline_conf);
+  return;
+}
+
+/*!
+ * \brief set index-th input to the graph.
+ * \param index The input index.
+ * \param data_in The input data.
+ */
+void SubGraphRuntime::SetInput(int index, DLTensor* data_in) {
+  auto gruntime = runtimes.front();
+  gruntime->runtimePtr->SetInput(index, data_in);
+}
+
+void SubGraphRuntime::SetInput(const std::string& name, DLTensor* data_in) {
+  auto gruntime = runtimes.front();
+  gruntime->runtimePtr->SetInput(name, data_in);
+}
+
+/*!
+ * \brief Get the number of outputs
+ *
+ * \return The number of outputs from last pipeline.
+ */
+int SubGraphRuntime::NumOutputs() const { return 
runtimes.back()->runtimePtr->NumOutputs(); }
+
+/*!
+ * \brief Get the number of inputs
+ *
+ * \return The number of inputs to the first pipeline.
+ */
+int SubGraphRuntime::NumInputs() const { return 
runtimes.front()->runtimePtr->NumInputs(); }

Review comment:
       I don't think this logic is correct? Inputs can come from non-front 
modules and outputs can come from non-back modules. For example, if users don't 
bind the weights and choose to set them on the fly, then every module must have 
inputs.




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