• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 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_PIPELINE_PYNATIVE_GRAD_IR_BPROP_TENSOR_REPLACE_H_
18 #define MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_IR_BPROP_TENSOR_REPLACE_H_
19 
20 #include <string>
21 #include <map>
22 #include <vector>
23 #include <utility>
24 #include "utils/hash_map.h"
25 #include "ir/tensor.h"
26 #include "pipeline/jit/ps/resource.h"
27 
28 namespace mindspore {
29 namespace pynative {
30 using TensorIdWithOpInfo = mindspore::HashMap<std::string, std::pair<std::string, size_t>>;
31 using OpInfoWithTensorObject = std::map<std::string, std::vector<std::pair<size_t, tensor::BaseTensorPtr>>>;
32 // key: op info, value: op output value
33 using OpInfoWithForwardOutput = std::map<std::string, ValuePtr>;
34 
35 struct TensorReplaceInfo {
36   TensorIdWithOpInfo id_with_op_info{};
37   OpInfoWithTensorObject op_info_with_tensor_object{};
38   OpInfoWithForwardOutput op_info_with_forward_output{};
39   size_t need_replace_size{};
clearTensorReplaceInfo40   void clear() {
41     op_info_with_tensor_object.clear();
42     op_info_with_forward_output.clear();
43   }
44 };
45 
46 void SetIdWithOpInfo(const ValuePtr &v, const std::string &op_info, size_t out_index,
47                      TensorIdWithOpInfo *id_with_op_info);
48 void UpdateForwardOutputTensorInfo(const std::string &op_info, const ValuePtr &v,
49                                    const TensorReplaceInfo &replace_info);
50 void StoreForwardOutputWithOpInfo(const OpInfoWithTensorObject &op_info_with_tensor_object, const std::string &op_info,
51                                   const ValuePtr &v, TensorReplaceInfo *replace_info);
52 void UpdatePipelineTopCellFowardTensor(const TensorReplaceInfo &ir_replace_info,
53                                        const TensorReplaceInfo &cur_replace_info);
54 void SaveForwardOutputTensorInfo(const FuncGraphPtr &func_graph, bool need_save_tensor_info,
55                                  TensorReplaceInfo *replace_info);
56 }  // namespace pynative
57 }  // namespace mindspore
58 #endif  // MINDSPORE_CCSRC_PIPELINE_PYNATIVE_GRAD_IR_BPROP_TENSOR_REPLACE_H_
59