blob: 5199ac23286ffc6c3ef3aabc6a020c2c27bab545 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
Georgios Pinitasd9eb2752018-04-03 13:44:29 +01002 * Copyright (c) 2018 ARM Limited.
Anthony Barbier2a07e182017-08-04 18:20:27 +01003 *
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
Anthony Barbier2a07e182017-08-04 18:20:27 +010027#include "arm_compute/graph/Types.h"
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010028
29#include "arm_compute/graph/ITensorAccessor.h"
30#include "arm_compute/graph/ITensorHandle.h"
31#include "arm_compute/graph/TensorDescriptor.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010032
33#include <memory>
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010034#include <set>
Anthony Barbier2a07e182017-08-04 18:20:27 +010035
36namespace arm_compute
37{
38namespace graph
39{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010040/** Tensor object **/
41class Tensor final
Anthony Barbier2a07e182017-08-04 18:20:27 +010042{
43public:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010044 /** Default constructor
Anthony Barbier2a07e182017-08-04 18:20:27 +010045 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010046 * @param[in] id Tensor ID
47 * @param[in] desc Tensor information
Anthony Barbier2a07e182017-08-04 18:20:27 +010048 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010049 Tensor(TensorID id, TensorDescriptor desc);
50 /** Tensor ID accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010051 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010052 * @return Tensor ID
Anthony Barbier2a07e182017-08-04 18:20:27 +010053 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010054 TensorID id() const;
55 /** TensorInfo metadata accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010056 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010057 * @return Tensor descriptor metadata
Anthony Barbier2a07e182017-08-04 18:20:27 +010058 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010059 TensorDescriptor &desc();
60 /** TensorInfo metadata accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010061 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010062 * @return Tensor descriptor metadata
Anthony Barbier2a07e182017-08-04 18:20:27 +010063 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010064 const TensorDescriptor &desc() const;
65 /** Sets the backend tensor
Gian Marco44ec2e72017-10-19 14:13:38 +010066 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010067 * @param[in] backend_tensor Backend tensor to set
Gian Marco44ec2e72017-10-19 14:13:38 +010068 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010069 void set_handle(std::unique_ptr<ITensorHandle> backend_tensor);
70 /** Backend tensor handle accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010071 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010072 * @return Backend tensor handle
Anthony Barbier2a07e182017-08-04 18:20:27 +010073 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010074 ITensorHandle *handle();
75 /** Sets the backend tensor accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010076 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010077 * @param[in] accessor Accessor to set
Anthony Barbier2a07e182017-08-04 18:20:27 +010078 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010079 void set_accessor(std::unique_ptr<ITensorAccessor> accessor);
80 /** Backend tensor accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010081 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010082 * @return Backend tensor accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010083 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010084 ITensorAccessor *accessor();
85 /** Calls accessor on tensor
86 *
87 * @return True if the accessor was called else false
88 */
89 bool call_accessor();
90 /** Binds the tensor with an edge
91 *
92 * @param[in] eid Edge ID that is bound to the tensor
93 */
94 void bind_edge(EdgeID eid);
95 /** Unbinds an edge from a tensor
96 *
97 * @param[in] eid Edge to unbind
98 */
99 void unbind_edge(EdgeID eid);
100 /** Accessor the edges that are bound with the tensor
101 *
102 * @return Bound edges
103 */
104 const std::set<EdgeID> bound_edges() const;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100105
106private:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100107 TensorID _id; /**< Tensor id */
108 TensorDescriptor _desc; /**< Tensor metadata */
109 std::unique_ptr<ITensorHandle> _handle; /**< Tensor Handle */
110 std::unique_ptr<ITensorAccessor> _accessor; /**< Tensor Accessor */
111 std::set<EdgeID> _bound_edges; /**< Edges bound to this tensor */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100112};
113} // namespace graph
114} // namespace arm_compute
115#endif /* __ARM_COMPUTE_GRAPH_TENSOR_H__ */