• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 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 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_COMPACT_TENSOR_LIVENESS_H_
17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_COMPACT_TENSOR_LIVENESS_H_
18 
19 #include "include/backend/optimizer/pass.h"
20 
21 namespace mindspore::graphkernel {
22 /**
23  * @brief For memory efficiency, insert UpdateState for op with no cnode/param inputs to avoid early launching
24  * @example
25  * main(x, y){
26  *   %1 = Op1(x, y)
27  *   %2 = Op2()
28  *   %3 = Op3(%1, %2)
29  *   return %3
30  * }
31  *  --------------->
32  * main(x, y){
33  *   %1 = Op1(x, y)
34  *   %2 = UpdateState(U, %1)
35  *   %3 = Op2(%2)
36  *   %4 = Op3(%1, %3)
37  *   return %4
38  * }
39  * ------------------
40  * Here, Op2 has no cnode/param inputs and will be launched early, memory space of %2 will be taken up early and only
41  * be released after execution of Op3. By insertion of UpdateState, memory space of %2 will be created right before
42  * execution of Op3.
43  */
44 class CompactTensorLiveness : public opt::Pass {
45  public:
CompactTensorLiveness()46   CompactTensorLiveness() : Pass("compact_tensor_liveness") {}
47   ~CompactTensorLiveness() override = default;
48   bool Run(const FuncGraphPtr &func_graph) override;
49 };
50 }  // namespace mindspore::graphkernel
51 #endif  // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_COMPACT_TENSOR_LIVENESS_H_
52