blob: fcba854a3e3c758b3f73e9b4d482dda684c91e95 [file] [log] [blame]
Georgios Pinitasd8734b52017-12-22 15:27:52 +00001/*
2 * Copyright (c) 2018 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_GRAPH2_TENSOR_H__
25#define __ARM_COMPUTE_GRAPH2_TENSOR_H__
26
27#include "arm_compute/graph2/Types.h"
28
29#include "arm_compute/graph2/ITensorAccessor.h"
30#include "arm_compute/graph2/ITensorHandle.h"
31#include "arm_compute/graph2/TensorDescriptor.h"
32
33#include <memory>
34
35namespace arm_compute
36{
37namespace graph2
38{
39/** Tensor object **/
40class Tensor final
41{
42public:
43 /** Default constructor
44 *
45 * @param[in] id Tensor ID
46 * @param[in] desc Tensor information
47 */
48 Tensor(TensorID id, TensorDescriptor desc);
49 /** Tensor ID accessor
50 *
51 * @return Tensor ID
52 */
53 TensorID id() const;
54 /** TensorInfo metadata accessor
55 *
56 * @return Tensor descriptor metadata
57 */
58 TensorDescriptor &desc();
59 /** TensorInfo metadata accessor
60 *
61 * @return Tensor descriptor metadata
62 */
63 const TensorDescriptor &desc() const;
64 /** Sets the backend tensor
65 *
66 * @param[in] backend_tensor Backend tensor to set
67 */
68 void set_handle(std::unique_ptr<ITensorHandle> backend_tensor);
69 /** Backend tensor handle accessor
70 *
71 * @return Backend tensor handle
72 */
73 ITensorHandle *handle();
74 /** Sets the backend tensor accessor
75 *
76 * @param[in] accessor Accessor to set
77 */
78 void set_accessor(std::unique_ptr<ITensorAccessor> accessor);
79 /** Backend tensor accessor
80 *
81 * @return Backend tensor accessor
82 */
83 ITensorAccessor *accessor();
84 /** Calls accessor on tensor
85 *
86 * @return True if the accessor was called else false
87 */
88 bool call_accessor();
89 /** Binds the tensor with an edge
90 *
91 * @param[in] eid Edge ID that is bound to the tensor
92 */
93 void bind_edge(EdgeID eid);
94 /** Unbinds an edge from a tensor
95 *
96 * @param[in] eid Edge to unbind
97 */
98 void unbind_edge(EdgeID eid);
99 /** Accessor the edges that are bound with the tensor
100 *
101 * @return Bound edges
102 */
103 const std::set<EdgeID> bound_edges() const;
104
105private:
106 TensorID _id; /**< Tensor id */
107 TensorDescriptor _desc; /**< Tensor metadata */
108 std::unique_ptr<ITensorHandle> _handle; /**< Tensor Handle */
109 std::unique_ptr<ITensorAccessor> _accessor; /**< Tensor Accessor */
110 std::set<EdgeID> _bound_edges; /**< Edges bound to this tensor */
111};
112} // namespace graph2
113} // namespace arm_compute
114#endif /* __ARM_COMPUTE_GRAPH2_TENSOR_H__ */