aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/graph/Tensor.h
blob: de96c998bd1376bb0511daffc67d45f132809b16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (c) 2018-2019 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef ARM_COMPUTE_GRAPH_TENSOR_H
#define ARM_COMPUTE_GRAPH_TENSOR_H

#include "arm_compute/graph/Types.h"

#include "arm_compute/graph/ITensorAccessor.h"
#include "arm_compute/graph/ITensorHandle.h"
#include "arm_compute/graph/TensorDescriptor.h"

#include <memory>
#include <set>

namespace arm_compute
{
namespace graph
{
/** Tensor object **/
class Tensor final
{
public:
    /** Default constructor
     *
     * @param[in] id   Tensor ID
     * @param[in] desc Tensor information
     */
    Tensor(TensorID id, TensorDescriptor desc);
    /** Tensor ID accessor
     *
     * @return Tensor ID
     */
    TensorID id() const;
    /** TensorInfo metadata accessor
     *
     * @return Tensor descriptor metadata
     */
    TensorDescriptor &desc();
    /** TensorInfo metadata accessor
     *
     * @return Tensor descriptor metadata
     */
    const TensorDescriptor &desc() const;
    /** Sets the backend tensor
     *
     * @param[in] backend_tensor Backend tensor to set
     */
    void set_handle(std::unique_ptr<ITensorHandle> backend_tensor);
    /** Backend tensor handle accessor
     *
     * @return Backend tensor handle
     */
    ITensorHandle *handle();
    /** Sets the backend tensor accessor
     *
     * @param[in] accessor Accessor to set
     */
    void set_accessor(std::unique_ptr<ITensorAccessor> accessor);
    /** Backend tensor accessor
     *
     * @return Backend tensor accessor
     */
    ITensorAccessor *accessor();
    /** Extracts accessor from the tensor
     *
     * @warning Accessor gets unbound from the tensor
     *
     * @return The accessor of the tensor
     */
    std::unique_ptr<ITensorAccessor> extract_accessor();
    /** Calls accessor on tensor
     *
     * @return True if the accessor was called else false
     */
    bool call_accessor();
    /** Binds the tensor with an edge
     *
     * @param[in] eid Edge ID that is bound to the tensor
     */
    void bind_edge(EdgeID eid);
    /** Unbinds an edge from a tensor
     *
     * @param[in] eid Edge to unbind
     */
    void unbind_edge(EdgeID eid);
    /** Accessor the edges that are bound with the tensor
     *
     * @return Bound edges
     */
    std::set<EdgeID> bound_edges() const;

private:
    TensorID                         _id;          /**< Tensor id */
    TensorDescriptor                 _desc;        /**< Tensor metadata */
    std::unique_ptr<ITensorHandle>   _handle;      /**< Tensor Handle */
    std::unique_ptr<ITensorAccessor> _accessor;    /**< Tensor Accessor */
    std::set<EdgeID>                 _bound_edges; /**< Edges bound to this tensor */
};
} // namespace graph
} // namespace arm_compute
#endif /* ARM_COMPUTE_GRAPH_TENSOR_H */