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