blob: 54fb2583e782ac20e624b68b93edd671c4cdf273 [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();
Georgios Pinitasd3a78ab2018-06-18 15:35:09 +010085 /** 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();
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010092 /** 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 const std::set<EdgeID> bound_edges() const;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100112
113private:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100114 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 */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100119};
120} // namespace graph
121} // namespace arm_compute
122#endif /* __ARM_COMPUTE_GRAPH_TENSOR_H__ */