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