huajsj commented on a change in pull request #9108: URL: https://github.com/apache/tvm/pull/9108#discussion_r726658113
########## File path: src/runtime/pipeline/pipeline_struct.h ########## @@ -0,0 +1,182 @@ +/* + * 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. + */ +#ifndef TVM_RUNTIME_PIPELINE_PIPELINE_STRUCT_H_ +#define TVM_RUNTIME_PIPELINE_PIPELINE_STRUCT_H_ +#include <assert.h> +#include <dlpack/dlpack.h> +#include <dmlc/json.h> + +#include <limits> +#include <string> +#include <unordered_map> +#include <vector> +#define PIPELINE_EXECUTOR_INDEX -1 +/*! + * \brief All binding information of a output interface. + */ +struct OutputBindings { + /*!\brief Output interface binding information, 'int' is the index of the module that + * uses this output data as the input interface data, 'string' is the input interface name + * of the module. + */ + std::unordered_map<int, std::string> bindings; + /*! + * \brief If there is one PipelineExecutor binding in bindings, then the current output is + * PipelineExecutor interface. + * \return Whether this output interface is PipelineExecutor output interface. + */ + bool IsGlobalOutput() const { + int num_output = 0; + for (auto binding : bindings) { + /* The output is a PipelineExecutor output when the index value + * equal PIPELINE_EXECUTOR_INDEX. + */ + num_output += (binding.first == PIPELINE_EXECUTOR_INDEX); + } + /* If this output is a global output then there is only one such output in map.*/ + ICHECK(num_output <= 1); + return num_output == 1; + } + /*! + * \brief Create a module interface map from JSONReader. + * \param reader JSON reader. + */ + void Load(dmlc::JSONReader* reader) { + reader->BeginArray(); + while (reader->NextArrayItem()) { + std::string key; + reader->BeginObject(); + std::string input_name; + int mod_idx = std::numeric_limits<int>::min(); + while (reader->NextObjectItem(&key)) { + if (key == "mod_idx") { + reader->Read(&mod_idx); + } + if (key == "input_name") { + reader->Read(&input_name); + } + } + // In this level 'Load' that reading the output binding , the module can be + // a 'PipelineExecutor', hence the value of 'mod_idx' should start from + // PIPELINE_EXECUTOR_INDEX. + ICHECK(mod_idx >= PIPELINE_EXECUTOR_INDEX); + bindings[mod_idx] = input_name; Review comment: removed PIPELINE_EXECUTOR_INDEX, add int global_input_index. -- 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]
