• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 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_LITE_TOOLS_LITE_EXPORTER_FETCH_CONTENT_H_
18 #define MINDSPORE_LITE_TOOLS_LITE_EXPORTER_FETCH_CONTENT_H_
19 
20 #include <string>
21 #include <vector>
22 #include <map>
23 #include <memory>
24 #include "ir/primitive.h"
25 #include "ir/func_graph.h"
26 #include "src/common/utils.h"
27 #include "nnacl/op_base.h"
28 #include "include/registry/converter_context.h"
29 
30 namespace mindspore {
31 namespace lite {
32 struct DataInfo {
33   bool enable_huffman_code_;
34   int compress_type_;
35   int format_;
36   int data_type_;
37   int node_type_;
38   std::vector<int> shape_;
39   std::vector<uint8_t> data_;
40   void *data_ptr_;
41   std::vector<std::shared_ptr<QuantizationParam>> quant_params_;
DataInfoDataInfo42   DataInfo()
43       : enable_huffman_code_(false),
44         compress_type_(kNoCompression),
45         format_(0),
46         data_type_(0),
47         node_type_{0},
48         data_ptr_(nullptr) {}
49 };
50 
51 int FetchFromDefaultParam(const ParameterPtr &param_node, const converter::FmkType &fmk_type, DataInfo *data_info,
52                           bool copy_data);
53 
54 int FetchDataFromParameterNode(const CNodePtr &cnode, size_t index, converter::FmkType fmk_type, DataInfo *data_info,
55                                bool copy_data);
56 
57 int FetchDataFromValueNode(const CNodePtr &cnode, size_t index, converter::FmkType fmk_type, bool train_flag,
58                            DataInfo *data_info, bool copy_data);
59 
60 int FetchDataFromCNode(const CNodePtr &cnode, size_t index, DataInfo *data_info);
61 
62 int FetchConstData(const CNodePtr &cnode, size_t index, converter::FmkType fmk_type, DataInfo *data_info,
63                    bool copy_data);
64 
65 int FetchDataFromAbstract(const AbstractBasePtr &abstract, DataInfo *data_info);
66 
67 int RemoveIfDepend(const CNodePtr &cnode);
68 
69 int RemoveIfMakeTuple(const CNodePtr &cnode);
70 
71 int GetFlattenInputsIfMakeTuple(const CNodePtr &cnode, std::vector<AnfNodePtr> *inputs, bool *has_make_tuple);
72 
73 // Notes:The op_parameter allocates memory through malloc, and may need to manually free op_parameter.
74 int FetchOpParameterFromNode(const AnfNodePtr &node, OpParameter **op_parameter);
75 
76 int FetchOpParameterFromFuncGraph(const FuncGraphPtr &func_graph, std::map<std::string, OpParameter *> *op_parameters);
77 }  // namespace lite
78 }  // namespace mindspore
79 #endif  // MINDSPORE_LITE_TOOLS_LITE_EXPORTER_FETCH_CONTENT_H_
80