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_CCSRC_FRONTEND_OPTIMIZER_AD_PYNATIVE_D_FUNCTOR_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_AD_PYNATIVE_D_FUNCTOR_H_ 19 20 #include <memory> 21 #include <vector> 22 23 #include "ir/anf.h" 24 #include "frontend/optimizer/ad/adjoint.h" 25 26 namespace mindspore { 27 namespace ad { 28 class PynativeDFunctor { 29 public: 30 static ValueNodePtr GenNewTensor(const CNodePtr &forward_node); 31 static tensor::TensorPtr GenNewTensorInner(const TypePtr &type_elem, const BaseShapePtr &shape_elem); 32 static void GetForwardOutNodeAndBpropGraph(const CNodePtr &k_app, CNodePtr *forward_node, FuncGraphPtr *bprop_graph, 33 FuncGraphPtr *fprop_graph); 34 static std::vector<AnfNodePtr> RunOutputReplace(const CNodePtr &forward_node, const FuncGraphPtr &bprop_graph, 35 const FuncGraphPtr &fprop_graph, const CNodePtr &cnode_morph); 36 static std::vector<AnfNodePtr> RunInputReplace(const FuncGraphPtr &bprop_graph, const FuncGraphPtr &fprop_graph, 37 const CNodePtr &cnode_morph); 38 static void ReplaceEquivdout(const CNodePtr &k_app, const CNodePtr &cnode_morph); 39 }; 40 } // namespace ad 41 } // namespace mindspore 42 43 #endif // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_AD_PYNATIVE_D_FUNCTOR_H_ 44