huajsj commented on a change in pull request #8702: URL: https://github.com/apache/tvm/pull/8702#discussion_r708846035
########## File path: python/tvm/contrib/pipeline_executor.py ########## @@ -0,0 +1,539 @@ +# 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. +"""Pipeline executor that executes a series of modules in a pipeline fashion.""" +import json +import tvm._ffi +from tvm import relay +from tvm.relay.transform import InferType +from tvm.contrib import graph_executor + + +def pipeline_executor_enabled(): + """Check if the pipeline executor is enabled. + + Return + ------- + enable: bool + Return whether the pipeline executor is enabled. + """ + return tvm._ffi.get_global_func("tvm.pipeline_executor.create", allow_missing=True) is not None + + +def build(pipe_configs): + """Build these modules used in the pipeline executor, then use these modules and configuration + to create a pipeline executor. + + Parameters + ---------- + pipe_configs: PipelineConfig + Build Configuration information. + + Returns + ------- + ret: PipelineExecutorFactoryModule + Common interface for pipeline executor factory modules. + """ + mods = {} + mod_n_configs = pipe_configs.get_config() + config_len = len(mod_n_configs) + string_config = [{} for _ in range(config_len)] + for ir_mod, mod_config in mod_n_configs.items(): + mconf = mod_config["pipeline"].copy() + mod_idx = mconf["mod_idx"] - 1 + dev = mod_config["dev"] + target = mod_config["target"] + build_func = relay.build + # Check whether there is a customized build function. + if "build" in mod_config and mod_config["build"]: + build_func = mod_config["build"] + + mod = build_func( + ir_mod, + target, + params=mod_config["params"], + target_host=mod_config["target_host"], + mod_name=mod_config["mod_name"], + ) + + mconf["dev"] = "{},{}".format(dev.device_type, dev.device_id) + # Create a pipeline configuration. + string_config[mod_idx] = mconf + mods[mod] = {"dev": dev} + + return PipelineExecutorFactoryModule(mods, string_config) + + +class PipelineModule(object): + """Wrapper of runtime module, caller can use this module to set parameters and get outputs. + + Parameters + ---------- + module : PipelineExecutorFactoryModule + Common interface for pipeline executor factory modules. + """ + + def __init__(self, module): + self.module = module.module + + +class PipelineConfig(object): + """Pipeline configuration information, this class contains the DAG that expresses + the dependency of each module involved by pipeline and the specific parameters + of each module build. Review comment: changed into "the parameters for building each module." -- 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]
