• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2022 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_GRAD_H_
18 #define MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_AD_GRAD_H_
19 
20 #include "ir/anf.h"
21 #include "ir/meta_func_graph.h"
22 #include "frontend/optimizer/optimizer.h"
23 
24 namespace mindspore {
25 namespace ad {
26 // We pass the bprop_auto_monad level to the ad::Grad, and then keep the order between forward and backward in the later
27 // pass 'add_forward_monad_depend'.
28 enum BpropAutoMonadLevel : int {
29   // When setting to None level, it will not keep the order for all side effect nodes between forward and backward.
30   kLevelNone = 0,
31   // When setting to Top level, ir will keep the order for all side effect nodes between forward inputs and backward.
32   kLevelTop,
33   // When setting to Whole level, it will keep the order for all side effect nodes between forward and backward.
34   kLevelWhole,
35 };
36 FuncGraphPtr Grad(const FuncGraphPtr &func_graph, const opt::OptimizerPtr &optimizer, bool is_top = true,
37                   BpropAutoMonadLevel level = kLevelNone);
38 FuncGraphVector GradMultiFuncGraph(const FuncGraphVector &func_graphs, const opt::OptimizerPtr &optimizer,
39                                    bool is_top = true);
40 FuncGraphPtr Kprim(const ValueNodePtr &value_node, const pipeline::ResourceBasePtr &resources);
41 MetaFuncGraphPtr Kmeta(const PrimitivePtr &prim, const pipeline::ResourceBasePtr &);
42 void CleanRes();
43 bool MergeForward(const FuncGraphPtr &root, const opt::OptimizerPtr &opt);
44 }  // namespace ad
45 }  // namespace mindspore
46 
47 #endif  // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_AD_GRAD_H_
48