• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2023 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_CONVERTER_H_
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_CONVERTER_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <map>
24 #include "include/converter.h"
25 #include "include/registry/model_parser.h"
26 #include "schema/inner/model_generated.h"
27 #include "tools/converter/graphdef_transform.h"
28 #include "include/registry/model_parser_registry.h"
29 #include "tools/converter/anf_transform.h"
30 #include "tools/converter/converter_context.h"
31 #include "tools/common/graph_util.h"
32 #include "tools/converter/preprocess/preprocess_param.h"
33 #include "tools/converter/quantizer/quant_params.h"
34 #include "tools/converter/adapter/acl/common/acl_types.h"
35 #include "micro/coder/config.h"
36 #include "tools/converter/cxx_api/converter_para.h"
37 #include "tools/converter/config_parser/config_file_parser.h"
38 
39 namespace mindspore {
40 namespace lite {
41 constexpr auto kMaxSplitRatio = 10;
42 constexpr auto kComputeRate = "computeRate";
43 constexpr auto kSplitDevice0 = "device0";
44 constexpr auto kSplitDevice1 = "device1";
45 
46 int RunConverter(const std::shared_ptr<ConverterPara> &param, void **model_data = nullptr, size_t *data_size = nullptr,
47                  bool not_save = false);
48 
49 class ConverterImpl {
50  public:
51   ConverterImpl() = default;
~ConverterImpl()52   ~ConverterImpl() {}
53 
54   int Convert(const std::shared_ptr<ConverterPara> &param, void **model_data, size_t *data_size, bool not_save);
55 
56  private:
57   int InitConfigParam(const std::shared_ptr<ConverterPara> &param,
58                       std::map<int, std::map<std::string, std::string>> *model_param_infos);
59   int ParseParam(lite::ConfigFileParser *config_parser, const std::shared_ptr<ConverterPara> &param,
60                  const std::map<int, std::map<std::string, std::string>> *model_param_infos,
61                  const std::map<std::string, std::map<std::string, std::string>> maps);
62   int InitExtendedIntegrationInfo(const std::shared_ptr<ConverterPara> &param,
63                                   const lite::ConfigFileParser &config_file_parser);
64   bool CheckOfflineParallelConfig(const std::string &file, ParallelSplitConfig *parallel_split_config);
65   std::string GetStrFromConfigFile(const std::string &file, const std::string &target_key);
66   int SaveGraph(FuncGraphPtr graph, const std::shared_ptr<ConverterPara> &param, void **model_data, size_t *data_size,
67                 bool not_save, bool is_multi_model);
68   int SaveMindIRModel(FuncGraphPtr graph, const std::shared_ptr<ConverterPara> &param, void **model_data,
69                       size_t *data_size);
70   int LoadPluginLib(const std::shared_ptr<ConverterPara> &param);
71   int HandleGraphCommon(const std::shared_ptr<ConverterPara> &param, void **model_data, size_t *data_size,
72                         bool not_save, bool is_multi_model);
73   int ExecuteMicro(const schema::MetaGraphT *meta_graph, const std::shared_ptr<ConverterPara> &param,
74                    bool is_multi_model);
75 };
76 }  // namespace lite
77 }  // namespace mindspore
78 
79 #endif
80