You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gllo_utils.h 3.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Copyright 2020 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. #ifndef MINDSPORE_LITE_SRC_PASS_COMMON_GLLO_UTILS_H_
  17. #define MINDSPORE_LITE_SRC_PASS_COMMON_GLLO_UTILS_H_
  18. #include <memory>
  19. #include <vector>
  20. #include "src/ops/primitive_c.h"
  21. #include "ir/anf.h"
  22. #include "ir/func_graph.h"
  23. #include "src/common/utils.h"
  24. #include "backend/optimizer/common/pattern_engine.h"
  25. #include "schema/inner/model_generated.h"
  26. #include "src/param_value_lite.h"
  27. #include "tools/converter/converter_context.h"
  28. using PrimitiveCPtr = std::shared_ptr<mindspore::lite::PrimitiveC>;
  29. using mindspore::lite::RET_ERROR;
  30. using mindspore::lite::RET_OK;
  31. using mindspore::lite::STATUS;
  32. namespace mindspore {
  33. namespace opt {
  34. bool IsRealCNodeKernel(const AnfNodePtr &node);
  35. bool IsGraphKernel(const AnfNodePtr &node);
  36. int CheckIfFuncGraphIsNull(const FuncGraphPtr &graph);
  37. int CheckIfAnfNodeIsNull(const AnfNodePtr &node);
  38. int CheckIfCNodeIsNull(const CNodePtr &node);
  39. int CheckIfVarIsNull(const VarPtr &var);
  40. int CheckInputSize(const CNodePtr &node, int size);
  41. int CheckIfNodeIsParam(const AnfNodePtr &node);
  42. int CheckLeastInputSize(const CNodePtr &node, int size);
  43. ParameterPtr AddNewBiasNode(float *bias_data, const FuncGraphPtr &func_graph, int kernel_num,
  44. const ParamValueLitePtr &weight_tensor);
  45. schema::PrimitiveType GetCNodeType(const BaseRef &node);
  46. bool IsParamNode(const BaseRef &n);
  47. bool IsConvNode(const BaseRef &n);
  48. bool IsPoolingNode(const BaseRef &n);
  49. bool IsQuantNode(const BaseRef &n);
  50. bool CheckIsAllInputsParam(const AnfNodePtr &node);
  51. size_t GetOutputTensorNum(const AnfNodePtr &node);
  52. bool IsMultiOutputTensors(const FuncGraphPtr &graph, const AnfNodePtr &node);
  53. size_t GetTupleGetItemOutIndex(const CNodePtr &tuple_get_item);
  54. ParamValueLitePtr GetLiteParamValue(const AnfNodePtr &node);
  55. enum kTransFilterType {
  56. kKCHW2HWCK, // 0
  57. kKCHW2KHWC,
  58. kCKHW2KHWC,
  59. kCKHW2HWCK,
  60. kKCHW2HWKC,
  61. kCKHW2HWKC,
  62. kHWCK2KCHW,
  63. kHWCK2CKHW,
  64. kHWKC2KCHW,
  65. kHWKC2CKHW,
  66. kNHWC2KCHW, // 10
  67. kNHWC2CKHW,
  68. kNHWC2HWCK,
  69. kKHWC2HWCK,
  70. kCHWK2HWCK,
  71. kKHWC2CHWK,
  72. kCHWK2KHWC,
  73. kKHWC2KCHW,
  74. kCKHW2KCHW,
  75. kCHWK2KCHW,
  76. kKCHW2CKHW // 20
  77. };
  78. STATUS GetFilterDim(const std::vector<int32_t> &oriDims, kTransFilterType type, int32_t *filterK, int32_t *filterC,
  79. int32_t *filterH, int32_t *filterW);
  80. STATUS SetFilterDim(const ParamValueLitePtr &tensor, kTransFilterType type, int32_t filterK, int32_t filterC,
  81. int32_t filterH, int32_t filterW);
  82. template <typename T>
  83. static STATUS TransFilterData(const ParamValueLitePtr &tensor, kTransFilterType type, int32_t filterK, int32_t filterC,
  84. int32_t filterH, int32_t filterW);
  85. template <typename T>
  86. static lite::STATUS TransFilterFormat(const ParamValueLitePtr &tensor, kTransFilterType type);
  87. STATUS TransFilterFormat(const ParamValueLitePtr &tensor, schema::Format dst_format);
  88. } // namespace opt
  89. } // namespace mindspore
  90. #endif // MINDSPORE_LITE_SRC_PASS_COMMON_GLLO_UTILS_H_