1 /** 2 * Copyright 2024 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_PI_JIT_BPROP_FUNC_GRAPH_MANAGERER_H_ 18 #define MINDSPORE_PI_JIT_BPROP_FUNC_GRAPH_MANAGERER_H_ 19 20 #include <map> 21 #include <memory> 22 #include <string> 23 #include <utility> 24 #include "ir/func_graph.h" 25 26 namespace mindspore { 27 namespace pijit { 28 namespace grad { 29 class BpropFuncGraphManager { 30 public: BpropFuncGraphManager()31 BpropFuncGraphManager() {} 32 virtual ~BpropFuncGraphManager() = default; 33 34 FuncGraphPtr PrimBpropGraphPass(const FuncGraphPtr &prim_grad_graph); 35 FuncGraphPtr GetAccumulateGraph(const ValuePtr &dout, const ValuePtr &factor); 36 FuncGraphPtr GetPrimBpropGraph(const PrimitivePtr &prim, const ValuePtrList &inputs, const ValuePtr &out, 37 const ValuePtr &dout); 38 FuncGraphPtr GetPrimBpropGraph(const PrimitivePtr &prim, const abstract::AbstractBasePtrList &args_abs); 39 FuncGraphPtr GetFuncGraphBpropGraph(const FuncGraphPtr &forward_graph, const ValuePtrList &inputs, 40 const ValuePtr &out, const ValuePtr &dout); 41 void Clear(); 42 43 private: 44 std::map<std::string, FuncGraphPtr> prim_to_bprop_; 45 std::map<FuncGraphPtr, FuncGraphPtr> func_graph_to_bprop_; 46 }; 47 48 using BpropFuncGraphManagerPtr = std::shared_ptr<BpropFuncGraphManager>; 49 } // namespace grad 50 } // namespace pijit 51 } // namespace mindspore 52 53 #endif // MINDSPORE_PI_JIT_BPROP_FUNC_GRAPH_MANAGERER_H_ 54