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