• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_NODE_PASS_H
18 #define MINDSPORE_PREDICT_ISOLATED_SUBGRAPH_NODE_PASS_H
19 
20 #include <vector>
21 #include <utility>
22 #include <set>
23 #include <memory>
24 #include "tools/converter/optimizer.h"
25 
26 namespace mindspore {
27 namespace lite {
28 class SubgraphNodePass : public GraphPass {
29  public:
SubgraphNodePass(std::vector<schema::CNodeT * > old_nodes)30   explicit SubgraphNodePass(std::vector<schema::CNodeT *> old_nodes) : old_nodes_(std::move(old_nodes)) {}
31 
32   ~SubgraphNodePass() override = default;
33 
34   STATUS Run(schema::MetaGraphT *graph) override;
35 
36  private:
37   void DecreaseSubgraphNodeIndices(const size_t &node_idx, schema::MetaGraphT *graph);
38   void IncreaseSubgraphNodeIndices(const size_t &node_idx, schema::MetaGraphT *graph);
39   STATUS GetSubgraphAllTensorIndices(const std::unique_ptr<SubGraphT> &subgraph, schema::MetaGraphT *graph,
40                                      std::set<uint32_t> *tensors_indices);
41   bool IsNodeInputInSubgraph(const std::set<uint32_t> &tensors_indices, const std::unique_ptr<CNodeT> &node,
42                              const std::unique_ptr<SubGraphT> &subgraph);
43   bool IsNodeOutputInSubgraph(const std::set<uint32_t> &tensors_indices, const std::unique_ptr<CNodeT> &node,
44                               const std::unique_ptr<SubGraphT> &subgraph);
45   std::vector<schema::CNodeT *> old_nodes_;
46 };
47 }  // namespace lite
48 }  // namespace mindspore
49 #endif  // MINDSPORE_PREDICT_ISOLATED_NODE_REMOVE_PASS_H
50