• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FRONTEND_OPTIMIZER_IRPASS_GRAD_VAR_PREPARE_H_
18 #define MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_GRAD_VAR_PREPARE_H_
19 
20 #include <vector>
21 #include <algorithm>
22 #include <unordered_map>
23 #include <memory>
24 
25 #include "frontend/operator/composite/composite.h"
26 #include "frontend/operator/ops.h"
27 #include "frontend/optimizer/irpass.h"
28 #include "frontend/optimizer/optimizer.h"
29 #include "frontend/optimizer/anf_visitor.h"
30 #include "ir/func_graph.h"
31 #include "ir/func_graph_cloner.h"
32 
33 namespace mindspore {
34 namespace opt {
35 namespace irpass {
36 // {{GradOperation, g, w}, Ys}
37 // {UnPackCall, {GradOperation, g, w}, Ys}
38 class GradVarPrepare : public AnfVisitor {
39  public:
GradVarPrepare()40   GradVarPrepare()
41       : grad_op_(std::make_shared<prim::GradOperation>("grad")),
42         unpack_op_(std::make_shared<prim::UnpackCall>("unpack_call")) {}
43   ~GradVarPrepare() override = default;
44 
45   AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override;
46 
47  private:
48   MetaFuncGraphPtr grad_op_;
49   MetaFuncGraphPtr unpack_op_;
50 };
51 }  // namespace irpass
52 }  // namespace opt
53 }  // namespace mindspore
54 #endif  // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_GRAD_VAR_PREPARE_H_
55