Compute Library
 23.05
Tensor.h
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  */
24 #ifndef ARM_COMPUTE_GRAPH_TENSOR_H
25 #define ARM_COMPUTE_GRAPH_TENSOR_H
26 
28 
32 
33 #include <memory>
34 #include <set>
35 
36 namespace arm_compute
37 {
38 namespace graph
39 {
40 /** Tensor object **/
41 class Tensor final
42 {
43 public:
44  /** Default constructor
45  *
46  * @param[in] id Tensor ID
47  * @param[in] desc Tensor information
48  */
50  /** Tensor ID accessor
51  *
52  * @return Tensor ID
53  */
54  TensorID id() const;
55  /** TensorInfo metadata accessor
56  *
57  * @return Tensor descriptor metadata
58  */
60  /** TensorInfo metadata accessor
61  *
62  * @return Tensor descriptor metadata
63  */
64  const TensorDescriptor &desc() const;
65  /** Sets the backend tensor
66  *
67  * @param[in] backend_tensor Backend tensor to set
68  */
69  void set_handle(std::unique_ptr<ITensorHandle> backend_tensor);
70  /** Backend tensor handle accessor
71  *
72  * @return Backend tensor handle
73  */
75  /** Sets the backend tensor accessor
76  *
77  * @param[in] accessor Accessor to set
78  */
79  void set_accessor(std::unique_ptr<ITensorAccessor> accessor);
80  /** Backend tensor accessor
81  *
82  * @return Backend tensor accessor
83  */
85  /** Extracts accessor from the tensor
86  *
87  * @warning Accessor gets unbound from the tensor
88  *
89  * @return The accessor of the tensor
90  */
91  std::unique_ptr<ITensorAccessor> extract_accessor();
92  /** Calls accessor on tensor
93  *
94  * @return True if the accessor was called else false
95  */
96  bool call_accessor();
97  /** Binds the tensor with an edge
98  *
99  * @param[in] eid Edge ID that is bound to the tensor
100  */
101  void bind_edge(EdgeID eid);
102  /** Unbinds an edge from a tensor
103  *
104  * @param[in] eid Edge to unbind
105  */
106  void unbind_edge(EdgeID eid);
107  /** Accessor the edges that are bound with the tensor
108  *
109  * @return Bound edges
110  */
111  std::set<EdgeID> bound_edges() const;
112 
113 private:
114  TensorID _id; /**< Tensor id */
115  TensorDescriptor _desc; /**< Tensor metadata */
116  std::unique_ptr<ITensorHandle> _handle; /**< Tensor Handle */
117  std::unique_ptr<ITensorAccessor> _accessor; /**< Tensor Accessor */
118  std::set<EdgeID> _bound_edges; /**< Edges bound to this tensor */
119 };
120 } // namespace graph
121 } // namespace arm_compute
122 #endif /* ARM_COMPUTE_GRAPH_TENSOR_H */
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-2023 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
Tensor object.
Definition: Tensor.h:41