Compute Library
 21.05
Tensor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 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  // Map tensor
84  _handle->map(true);
85 
86  // Return in case of null backend buffer
87  if(_handle->tensor().buffer() == nullptr)
88  {
89  return false;
90  }
91 
92  // Call accessor
93  bool retval = _accessor->access_tensor(_handle->tensor());
94 
95  // Unmap tensor
96  _handle->unmap();
97 
98  return retval;
99 }
100 
102 {
103  _bound_edges.insert(eid);
104 }
105 
107 {
108  _bound_edges.erase(eid);
109 }
110 
111 std::set<EdgeID> Tensor::bound_edges() const
112 {
113  return _bound_edges;
114 }
115 } // namespace graph
116 } // 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-2021 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:101
ITensorAccessor * accessor()
Backend tensor accessor.
Definition: Tensor.cpp:65
void unbind_edge(EdgeID eid)
Unbinds an edge from a tensor.
Definition: Tensor.cpp:106
Tensor handle interface object.
Definition: ITensorHandle.h:38
Tensor accessor interface.
unsigned int EdgeID
Definition: Types.h:69
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:111
unsigned int TensorID
Definition: Types.h:67
std::unique_ptr< ITensorAccessor > extract_accessor()
Extracts accessor from the tensor.
Definition: Tensor.cpp:70