• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2022 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_LITE_TOOLS_CONVERTER_DPICO_COMMON_GRAPH_OUTPUT_NAME_KEEPER_H
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_DPICO_COMMON_GRAPH_OUTPUT_NAME_KEEPER_H
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 #include "mindapi/ir/func_graph.h"
24 
25 namespace mindspore {
26 namespace dpico {
27 class GraphOutputNameKeeper {
28  public:
29   static GraphOutputNameKeeper *GetInstance();
30   int SaveOriginalOutputs(const api::FuncGraphPtr &func_graph);
RecycleResource()31   void RecycleResource() {
32     original_outputs_.clear();
33     om_to_anf_mapper_.clear();
34   }
ResetOutputNameMapper()35   void ResetOutputNameMapper() { om_to_anf_mapper_.clear(); }
36   int DetermineOmOpInputName(const api::AnfNodePtr &in_node, std::string *input_name);
37   int DetermineOmOpOutputName(const api::AnfNodePtr &node, std::string *output_name, bool is_subgraph_input = false);
38   bool CanKeepOutputNames(const std::vector<std::string> &om_outputs);
39   std::string GetAnfOutputNameFromOm(const std::string &om_out_name);
40 
41  private:
42   GraphOutputNameKeeper() = default;
43   ~GraphOutputNameKeeper() = default;
44   api::AnfNodePtrList original_outputs_;
45   std::map<std::string, std::string> om_to_anf_mapper_;
46   std::map<std::string, std::string> ori_output_info_;
47 };
48 }  // namespace dpico
49 }  // namespace mindspore
50 #endif  // MINDSPORE_LITE_TOOLS_CONVERTER_DPICO_COMMON_GRAPH_OUTPUT_NAME_KEEPER_H
51