1 /** 2 * Copyright 2020-2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_PREDICT_ISOLATED_SUBGRAPH_TENSOR_PASS_H 18 #define MINDSPORE_PREDICT_ISOLATED_SUBGRAPH_TENSOR_PASS_H 19 20 #include <vector> 21 #include <utility> 22 #include "tools/converter/optimizer.h" 23 24 namespace mindspore { 25 namespace lite { 26 class SubgraphTensorPass : public GraphPass { 27 public: 28 SubgraphTensorPass() = default; 29 30 ~SubgraphTensorPass() override = default; 31 32 STATUS Run(schema::MetaGraphT *graph) override; 33 34 private: 35 STATUS RemoveUselessTensors(schema::MetaGraphT *graph); 36 bool IsUsing(schema::MetaGraphT *graph, const uint32_t &tensor_idx); 37 STATUS UpdateTensorIdx(schema::MetaGraphT *graph, const uint32_t &tensor_idx); 38 STATUS SyncMainGraphInputAndOutput(schema::MetaGraphT *graph); 39 40 template <typename T> UpdateVec(std::vector<T> * vec,T element)41 void UpdateVec(std::vector<T> *vec, T element) { 42 for (auto iter = vec->begin(); iter != vec->end(); iter++) { 43 if (*iter > element) { 44 (*iter)--; 45 } 46 } 47 } 48 }; 49 } // namespace lite 50 } // namespace mindspore 51 #endif // MINDSPORE_PREDICT_ISOLATED_NODE_REMOVE_PASS_H 52