• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-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_OPTIMIZER_COMMON_FORMAT_UTILS_H_
18 #define MINDSPORE_LITE_TOOLS_OPTIMIZER_COMMON_FORMAT_UTILS_H_
19 
20 #include <vector>
21 #include <string>
22 #include <unordered_map>
23 #include "tools/optimizer/common/gllo_utils.h"
24 #include "utils/check_convert_utils.h"
25 
26 namespace mindspore {
27 namespace opt {
28 constexpr auto kOutputsFormat = "outputs_format";
29 enum FormatTransNodeType { kNCHW2NHWC, kNHWC2NCHW, kNONE };
30 struct TransTypePair {
31   FormatTransNodeType pre_;
32   FormatTransNodeType post_;
TransTypePairTransTypePair33   TransTypePair() : pre_(kNONE), post_(kNONE) {}
34 };
35 const std::unordered_map<std::string, std::vector<size_t>> &GetNHWCOpMap();
36 const std::unordered_map<std::string, std::vector<size_t>> &GetNCHWOpMap();
37 const std::unordered_map<std::string, std::vector<size_t>> &GetToNCHWOpMap();
38 const std::vector<std::string> &GetDynamicFormatOpList();
39 bool IsDynamicFormatOp(const std::string &op_type);
40 bool IsDynamicFormatOpWithAxis(const std::string &op_type);
41 STATUS GetCastDstDataType(const CNodePtr &cnode, int *perm);
42 STATUS GetTransposePerm(const CNodePtr &cnode, std::vector<int> *perm);
43 void RemoveIfMonad(const CNodePtr &cnode);
44 bool IsMonadNode(const AnfNodePtr &node);
45 bool IsSpecialType(const CNodePtr &cnode);
46 int DetermineCertainOutputFormat(const CNodePtr &cnode, int index, Format *format);
47 int DetermineCertainVarInputFormat(const CNodePtr &cnode, size_t index, Format *format);
48 int SetAbstractTensorInfo(const AbstractBasePtr &abstract);
49 STATUS GetFormatSensitiveOpInsertIndex(const CNodePtr &cnode, std::vector<size_t> *insert_index);
50 int ConvertAbstractFormatShape(const AbstractBasePtr &abstract, FormatTransNodeType perm);
51 }  // namespace opt
52 }  // namespace mindspore
53 
54 #endif  // MINDSPORE_LITE_TOOLS_OPTIMIZER_COMMON_FORMAT_UTILS_H_
55