• 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_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_H_
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_H_
19 
20 #include <vector>
21 #include <string>
22 #include <utility>
23 #include <functional>
24 #include <memory>
25 #include "common/check_base.h"
26 #include "common/fetch_content.h"
27 #include "mindapi/base/base.h"
28 #include "mindapi/ir/anf.h"
29 #include "include/errorcode.h"
30 #include "op/base_operator.h"
31 #include "op/recurrent_operator.h"
32 #include "mindapi/base/logging.h"
33 #include "mindapi/ir/tensor.h"
34 #include "ops/op_name.h"
35 
36 using mindspore::lite::RET_ERROR;
37 using mindspore::lite::RET_OK;
38 using mindspore::lite::STATUS;
39 namespace mindspore {
40 namespace dpico {
41 using BaseOperatorPtr = std::unique_ptr<mapper::BaseOperator>;
42 class OpMapper {
43  public:
OpMapper(std::string node_name)44   explicit OpMapper(std::string node_name) : name(std::move(node_name)) {}
45   virtual ~OpMapper() = default;
46   virtual STATUS Map(const api::CNodePtr &node, std::vector<BaseOperatorPtr> *base_operators,
47                      const api::PrimitivePtr &prim, const api::CNodePtrList &output_cnodes) = 0;
48 
49  private:
50   const std::string name;
51 };
52 using OpMapperPtr = std::shared_ptr<OpMapper>;
53 
54 STATUS SetCommonAttr(const api::CNodePtr &node, mapper::BaseOperator *base_operator,
55                      const api::CNodePtrList &output_cnodes);
56 STATUS SetConvFcDataInfo(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator);
57 STATUS SetRecurrentDataInfo(const api::CNodePtr &cnode, mapper::RecurrentOperator *recurrent_operator);
58 STATUS SetRecurrentOnnxInfo(const api::CNodePtr &cnode, mapper::RecurrentOperator *recurrent_operator);
59 STATUS CheckTensorInfoType(const api::TensorPtr &tensor_info, std::vector<float> *offline_data);
60 STATUS SetOnnxLstmOffLineArgs(mapper::RecurrentOperator *recurrent_operator, size_t index,
61                               const vector<int32_t> &shape_vec, const float *data);
62 STATUS PushOfflineArgs(const api::CNodePtr &cnode, mapper::BaseOperator *base_operator, size_t offline_args_size);
63 }  // namespace dpico
64 }  // namespace mindspore
65 
66 #endif  // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_MAPPER_OP_MAPPER_H_
67