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 17 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_REORDER_OPS_H_ 18 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_REORDER_OPS_H_ 19 20 #include <memory> 21 #include <vector> 22 #include <string> 23 #include "backend/optimizer/common/pass.h" 24 25 namespace mindspore { 26 namespace opt { 27 struct NodeIOInfo { 28 std::vector<std::string> inputs_format; 29 std::vector<std::string> outputs_format; 30 std::vector<TypeId> inputs_type; 31 std::vector<TypeId> outputs_type; 32 }; 33 34 class ReorderOps : public Pass { 35 public: ReorderOps()36 ReorderOps() : Pass("reorder_ops") {} 37 ~ReorderOps() override = default; 38 bool Run(const FuncGraphPtr &func_graph) override; 39 40 private: 41 void SetTypeInsensitiveNodeInputs(const CNodePtr &node, const std::vector<size_t> &indexes, 42 const std::vector<AnfNodePtr> &new_input_in_indexes, 43 std::vector<AnfNodePtr> *new_inputs); 44 void SetTypeInsensitiveNodeInputsInfo(const CNodePtr &node, const std::vector<size_t> &indexes, 45 const std::vector<AnfNodePtr> &input_at_indexes, NodeIOInfo *new_inputs_info, 46 bool from_input); 47 bool ReorderTypeInsensitiveCastDown(const FuncGraphPtr &func_graph, const FuncGraphManagerPtr &mng, 48 const CNodePtr &node); 49 bool ReorderCastUpTypeInsensitive(const FuncGraphPtr &func_graph, const FuncGraphManagerPtr &mng, 50 const CNodePtr &node); 51 bool ReorderCastTypeInsensitive(const FuncGraphPtr &func_graph); 52 }; 53 using ReorderOpsPtr = std::shared_ptr<ReorderOps>; 54 } // namespace opt 55 } // namespace mindspore 56 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_REORDER_OPS_H_ 57