• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-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_SRC_EXTENDRT_MINDIR_LOADER_MINDIR_MODEL_MINDIR_MODEL_LOADER_H_
18 #define MINDSPORE_LITE_SRC_EXTENDRT_MINDIR_LOADER_MINDIR_MODEL_MINDIR_MODEL_LOADER_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include "extendrt/mindir_loader/mindir_model/mindir_model.h"
24 #include "extendrt/mindir_loader/model_loader.h"
25 #include "proto/mind_ir.pb.h"
26 #include "ops/base_operator.h"
27 
28 namespace mindspore::infer::mindir {
29 class MindirModelLoader : public ModelLoader {
30  public:
MindirModelLoader()31   MindirModelLoader() {}
32   ~MindirModelLoader() = default;
33 
34   AbstractBaseModel *ImportModel(const char *model_buf, size_t size, bool take_buf) override;
35 
36  private:
37   bool ConvertModel(const mind_ir::ModelProto &model_proto);
38   bool ConvertPrimitives(const mind_ir::ModelProto &model_proto);
39   bool ConvertGraph(const mind_ir::GraphProto &graph_proto, LiteGraph::SubGraph *sub_graph = nullptr,
40                     bool is_main_graph = false);
41   bool ConvertNodes(const mind_ir::GraphProto &graph_proto, LiteGraph::SubGraph *sub_graph = nullptr,
42                     bool is_main_graph = false);
43   bool ConvertTensors(const mind_ir::GraphProto &graph_proto, LiteGraph::SubGraph *sub_graph = nullptr,
44                       bool is_main_graph = false);
45   std::shared_ptr<void> MakePrimitiveC(const std::string &node_type);
46 
47  private:
48   MindirModel *model_;
49   mindspore::HashMap<std::string, std::shared_ptr<mindspore::ops::BaseOperator>> all_operators_;
50   mindspore::HashMap<std::string, int32_t> tensor_index_map_;
51   int tensor_count_;
52   int node_count_;
53 };
54 }  // namespace mindspore::infer::mindir
55 
56 #endif  // MINDSPORE_LITE_SRC_EXTENDRT_MINDIR_LOADER_MINDIR_MODEL_MINDIR_MODEL_LOADER_H_
57