• 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_CHECKER_OP_CHECKER_H_
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_OP_CHECKER_H_
19 
20 #include <string>
21 #include <utility>
22 #include <vector>
23 #include <memory>
24 #include <map>
25 #include <unordered_map>
26 #include "mindapi/base/format.h"
27 #include "include/errorcode.h"
28 #include "mindapi/ir/anf.h"
29 #include "mindapi/base/logging.h"
30 #include "ops/op_name.h"
31 
32 using mindspore::lite::RET_ERROR;
33 using mindspore::lite::RET_OK;
34 using mindspore::lite::STATUS;
35 namespace mindspore {
36 namespace dpico {
37 class OpChecker {
38  public:
OpChecker(std::string node_name)39   explicit OpChecker(std::string node_name) : name(std::move(node_name)) {}
40   virtual ~OpChecker() = default;
41   virtual bool Check(api::CNodePtr op, int32_t output_num, mindspore::Format format) = 0;
42 
43  protected:
44   const std::string name;
45 };
46 
47 STATUS GetWidth(const std::vector<int64_t> &shape, mindspore::Format format, int64_t *width);
48 STATUS GetTensorChannel(const std::vector<int64_t> &shape, mindspore::Format format, int64_t *channel);
49 STATUS GetVectorChannel(const std::vector<int64_t> &shape, int64_t *channel);
50 bool HasOfflineData(const api::AnfNodePtr &node);
51 bool CheckInputW(const api::CNodePtr &op, size_t index, mindspore::Format format, int limit_w);
52 
53 class OpCheckerRegistry {
54  public:
55   OpCheckerRegistry() = default;
56   ~OpCheckerRegistry();
57 
58   static OpCheckerRegistry *GetInstance();
59 
60   OpChecker *GetOpChecker(const std::string &type);
61 
62   std::unordered_map<std::string, OpChecker *> checkers;
63 };
64 
65 class OpCheckerRegistrar {
66  public:
OpCheckerRegistrar(const std::string & type,OpChecker * parser)67   OpCheckerRegistrar(const std::string &type, OpChecker *parser) {
68     OpCheckerRegistry::GetInstance()->checkers[type] = parser;
69   }
70   ~OpCheckerRegistrar() = default;
71 };
72 }  // namespace dpico
73 }  // namespace mindspore
74 
75 #endif  // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_DPICO_CHECKER_OP_CHECKER_H_
76