• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019 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 #include "backend/optimizer/mem_reuse/kernel_refcount.h"
17 #include <algorithm>
18 
19 namespace mindspore {
20 namespace memreuse {
21 /**
22  * Add some set && get function
23  */
SetKernelRefCountInfo(int index,size_t size,RefCountType reftype)24 void KernelRefCount::SetKernelRefCountInfo(int index, size_t size, RefCountType reftype) {
25   index_ = index;
26   size_ = size;
27   reftype_ = reftype;
28 }
29 
GetInputRefIndexs() const30 std::vector<int> KernelDef::GetInputRefIndexs() const {
31   std::vector<int> input_ref_indexs;
32   if (input_refs_.empty()) {
33     return input_ref_indexs;
34   }
35   (void)std::transform(input_refs_.begin(), input_refs_.end(), std::back_inserter(input_ref_indexs),
36                        [](const KernelRefCountPtr &ref_info) { return ref_info->index_; });
37   return input_ref_indexs;
38 }
39 
GetOutputRefIndexs() const40 std::vector<int> KernelDef::GetOutputRefIndexs() const {
41   std::vector<int> output_ref_indexs;
42   if (output_refs_.empty()) {
43     return output_ref_indexs;
44   }
45   (void)std::transform(output_refs_.begin(), output_refs_.end(), std::back_inserter(output_ref_indexs),
46                        [](const KernelRefCountPtr &ref_info) { return ref_info->index_; });
47   return output_ref_indexs;
48 }
49 
GetWorkspaceRefIndexs() const50 std::vector<int> KernelDef::GetWorkspaceRefIndexs() const {
51   std::vector<int> wk_ref_indexs;
52   if (wk_space_.empty()) {
53     return wk_ref_indexs;
54   }
55   // only one key
56   auto wk_refs_iter = wk_space_.begin();
57   auto wk_refs = wk_refs_iter->second;
58   (void)std::transform(wk_refs.begin(), wk_refs.end(), std::back_inserter(wk_ref_indexs),
59                        [](const KernelRefCountPtr &ref_info) { return ref_info->index_; });
60   return wk_ref_indexs;
61 }
62 }  // namespace memreuse
63 }  // namespace mindspore
64