huajsj commented on a change in pull request #7892: URL: https://github.com/apache/tvm/pull/7892#discussion_r657376218
########## File path: src/runtime/pipeline/pipeline_executor.cc ########## @@ -0,0 +1,193 @@ +/* + * 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, input_int_map); + /* Clear the input map + */ +} + +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); + outpuNumber = pipeline_init(modules, &runtimes, &pipeline_conf); + return; +} + +/*! + * \brief set index-th input to the modIndx-th graph. + * \param index The input index. + * \param data_in The input data. + * \param modIndx The runtime index. + */ +void SubGraphRuntime::SetInput(int index, DLTensor* data_in, int modIndx) { + if (1 == modIndx) { + runtimes[0]->runtimePtr->SetInput(index, data_in); + } else { + pipeline_setinput(input_int_map, index, data_in, modIndx); + } +} + +/*! + * \brief Get the number of outputs + * + * \return The number of outputs from last pipeline. + */ +int SubGraphRuntime::NumOutputs() const { return outpuNumber; } + +/*! + * \brief Get the number of inputs + * + * \return The number of inputs to the first pipeline. + */ +int SubGraphRuntime::NumInputs() const { + int inputsNum = 0; + for (auto runtime : runtimes) { + inputsNum += runtime->runtimePtr->NumInputs(); + } + return inputsNum; +} + +/*! + * \brief Return NDArray for given input index. + * \param index The input index. + * + * \return NDArray corresponding to given input node index. + */ +NDArray SubGraphRuntime::GetInput(int index, int mIndx) const { + auto gruntime = runtimes[mIndx]; + return gruntime->runtimePtr->GetInput(index); +} + +/*! + * \brief Return input index for given input name. + * \param name The input name. + * + * \return int corresponding to given input node name. + */ +int SubGraphRuntime::GetInputIndex(const string& name, int mIndx) const { + auto gruntime = runtimes[mIndx - 1]; + return gruntime->runtimePtr->GetInputIndex(name); +} + +/*! + * \brief Return NDArray Array for all output. + * + * \return NDArray Array for all output. + */ +Array<NDArray> SubGraphRuntime::GetOutput(bool syncPoll) { + Array<NDArray> nd; + if (pipeline_poll(&output_entry_, runtimes, syncPoll)) { + for (auto output : output_entry_) { + nd.push_back(output); + } + } + return nd; +} + +PackedFunc SubGraphRuntime::GetFunction(const std::string& name, + const ObjectPtr<Object>& sptr_to_self) { + /* Return member functions during query. + */ + if (name == "set_input") { + return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { + /* Default use first runtime index value. + */ 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: [email protected]
