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.

node_infershape.h 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #ifndef MINDSPORE_LITE_TOOLS_OPTIMIZER_GRAPH_NODE_INFERSHAPE_H_
  17. #define MINDSPORE_LITE_TOOLS_OPTIMIZER_GRAPH_NODE_INFERSHAPE_H_
  18. #include <vector>
  19. #include <memory>
  20. #include <string>
  21. #include "schema/inner/model_generated.h"
  22. #include "src/tensor.h"
  23. #include "tools/anf_exporter/fetch_content.h"
  24. #include "tools/converter/converter_flags.h"
  25. #include "tools/optimizer/common/format_utils.h"
  26. using mindspore::lite::converter::FmkType;
  27. namespace mindspore {
  28. namespace opt {
  29. class NodeInferShape {
  30. public:
  31. NodeInferShape() = default;
  32. virtual ~NodeInferShape() = default;
  33. void Init(FmkType fmk_type, bool train_flag) {
  34. fmk_type_ = fmk_type;
  35. train_flag_ = train_flag;
  36. }
  37. STATUS InferShape(const CNodePtr &cnode);
  38. bool JudgeOpSupportInfer(const CNodePtr &cnode);
  39. std::vector<int> GetInputShape(const CNodePtr &cnode, size_t index);
  40. std::vector<int> GetIntVecInput(const CNodePtr &cnode, size_t index);
  41. private:
  42. STATUS GetCNodeInputTensors(const CNodePtr &cnode, std::vector<lite::Tensor *> *inputs);
  43. STATUS GetCNodeConstInput(const CNodePtr &cnode, std::vector<lite::Tensor *> *const_ms_inputs);
  44. STATUS GetCNodeVarInput(const CNodePtr &cnode, std::vector<lite::Tensor *> *var_ms_inputs);
  45. lite::Tensor *GetCNodeTensorListVarInput(const lite::DataInfo &data_info);
  46. STATUS GetCNodeOutputTensors(const CNodePtr &cnode, std::vector<lite::Tensor *> *outputs);
  47. STATUS ConvertToLiteTensor(const std::vector<lite::DataInfo> &data_infos, std::vector<lite::Tensor *> *tensors);
  48. STATUS SetCNodeAbstract(const std::shared_ptr<CNode> &cnode, const std::vector<lite::Tensor *> &outputs, int status);
  49. abstract::AbstractBasePtr ConvertLiteTensorToAbstract(lite::Tensor *tensor);
  50. abstract::AbstractBasePtr ConvertTensorListToAbstract(lite::Tensor *tensor);
  51. FmkType fmk_type_{lite::converter::FmkType_MS};
  52. bool train_flag_{false};
  53. };
  54. } // namespace opt
  55. } // namespace mindspore
  56. #endif // MINDSPORE_LITE_TOOLS_OPTIMIZER_GRAPH_NODE_INFERSHAPE_H_