Compute Library
 22.08
Tensor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019,2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
26 namespace arm_compute
27 {
28 namespace graph
29 {
31  : _id(id), _desc(std::move(desc)), _handle(nullptr), _accessor(nullptr), _bound_edges()
32 {
33 }
34 
36 {
37  return _id;
38 }
39 
41 {
42  return _desc;
43 }
44 
46 {
47  return _desc;
48 }
49 
50 void Tensor::set_handle(std::unique_ptr<ITensorHandle> backend_tensor)
51 {
52  _handle = std::move(backend_tensor);
53 }
54 
56 {
57  return _handle.get();
58 }
59 
60 void Tensor::set_accessor(std::unique_ptr<ITensorAccessor> accessor)
61 {
62  _accessor = std::move(accessor);
63 }
64 
66 {
67  return _accessor.get();
68 }
69 
70 std::unique_ptr<ITensorAccessor> Tensor::extract_accessor()
71 {
72  return std::move(_accessor);
73 }
74 
76 {
77  // Early exit guard
78  if(!_accessor || !_handle)
79  {
80  return false;
81  }
82 
83  const bool access_data = _accessor->access_tensor_data();
84 
85  if(access_data)
86  {
87  // Map tensor
88  _handle->map(true);
89 
90  // Return in case of null backend buffer
91  if(_handle->tensor().buffer() == nullptr)
92  {
93  return false;
94  }
95  }
96 
97  // Call accessor
98  bool retval = _accessor->access_tensor(_handle->tensor());
99 
100  if(access_data)
101  {
102  // Unmap tensor
103  _handle->unmap();
104  }
105 
106  return retval;
107 }
108 
110 {
111  _bound_edges.insert(eid);
112 }
113 
115 {
116  _bound_edges.erase(eid);
117 }
118 
119 std::set<EdgeID> Tensor::bound_edges() const
120 {
121  return _bound_edges;
122 }
123 } // namespace graph
124 } // namespace arm_compute
bool call_accessor()
Calls accessor on tensor.
Definition: Tensor.cpp:75
void set_handle(std::unique_ptr< ITensorHandle > backend_tensor)
Sets the backend tensor.
Definition: Tensor.cpp:50
ITensorHandle * handle()
Backend tensor handle accessor.
Definition: Tensor.cpp:55
Tensor(TensorID id, TensorDescriptor desc)
Default constructor.
Definition: Tensor.cpp:30
void set_accessor(std::unique_ptr< ITensorAccessor > accessor)
Sets the backend tensor accessor.
Definition: Tensor.cpp:60
Copyright (c) 2017-2022 Arm Limited.
TensorDescriptor & desc()
TensorInfo metadata accessor.
Definition: Tensor.cpp:40
void bind_edge(EdgeID eid)
Binds the tensor with an edge.
Definition: Tensor.cpp:109
ITensorAccessor * accessor()
Backend tensor accessor.
Definition: Tensor.cpp:65
void unbind_edge(EdgeID eid)
Unbinds an edge from a tensor.
Definition: Tensor.cpp:114
Tensor handle interface object.
Definition: ITensorHandle.h:38
Tensor accessor interface.
unsigned int EdgeID
Definition: Types.h:70
TensorID id() const
Tensor ID accessor.
Definition: Tensor.cpp:35
std::set< EdgeID > bound_edges() const
Accessor the edges that are bound with the tensor.
Definition: Tensor.cpp:119
unsigned int TensorID
Definition: Types.h:68
std::unique_ptr< ITensorAccessor > extract_accessor()
Extracts accessor from the tensor.
Definition: Tensor.cpp:70