blob: 0ffae28ecc67936992e3d19deecd056ff6984363 [file] [log] [blame]
Anthony Barbier2a07e182017-08-04 18:20:27 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2019 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_TENSOR_H
25#define ARM_COMPUTE_GRAPH_TENSOR_H
Anthony Barbier2a07e182017-08-04 18:20:27 +010026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/ITensorAccessor.h"
28#include "arm_compute/graph/ITensorHandle.h"
29#include "arm_compute/graph/TensorDescriptor.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030#include "arm_compute/graph/Types.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010031
32#include <memory>
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010033#include <set>
Anthony Barbier2a07e182017-08-04 18:20:27 +010034
35namespace arm_compute
36{
37namespace graph
38{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010039/** Tensor object **/
40class Tensor final
Anthony Barbier2a07e182017-08-04 18:20:27 +010041{
42public:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010043 /** Default constructor
Anthony Barbier2a07e182017-08-04 18:20:27 +010044 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010045 * @param[in] id Tensor ID
46 * @param[in] desc Tensor information
Anthony Barbier2a07e182017-08-04 18:20:27 +010047 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010048 Tensor(TensorID id, TensorDescriptor desc);
49 /** Tensor ID accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010050 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010051 * @return Tensor ID
Anthony Barbier2a07e182017-08-04 18:20:27 +010052 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010053 TensorID id() const;
54 /** TensorInfo metadata accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010055 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010056 * @return Tensor descriptor metadata
Anthony Barbier2a07e182017-08-04 18:20:27 +010057 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010058 TensorDescriptor &desc();
59 /** TensorInfo metadata accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010060 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010061 * @return Tensor descriptor metadata
Anthony Barbier2a07e182017-08-04 18:20:27 +010062 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010063 const TensorDescriptor &desc() const;
64 /** Sets the backend tensor
Gian Marco44ec2e72017-10-19 14:13:38 +010065 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010066 * @param[in] backend_tensor Backend tensor to set
Gian Marco44ec2e72017-10-19 14:13:38 +010067 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010068 void set_handle(std::unique_ptr<ITensorHandle> backend_tensor);
69 /** Backend tensor handle accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010070 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010071 * @return Backend tensor handle
Anthony Barbier2a07e182017-08-04 18:20:27 +010072 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010073 ITensorHandle *handle();
74 /** Sets the backend tensor accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010075 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010076 * @param[in] accessor Accessor to set
Anthony Barbier2a07e182017-08-04 18:20:27 +010077 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010078 void set_accessor(std::unique_ptr<ITensorAccessor> accessor);
79 /** Backend tensor accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010080 *
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010081 * @return Backend tensor accessor
Anthony Barbier2a07e182017-08-04 18:20:27 +010082 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010083 ITensorAccessor *accessor();
Georgios Pinitasd3a78ab2018-06-18 15:35:09 +010084 /** Extracts accessor from the tensor
85 *
86 * @warning Accessor gets unbound from the tensor
87 *
88 * @return The accessor of the tensor
89 */
90 std::unique_ptr<ITensorAccessor> extract_accessor();
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010091 /** Calls accessor on tensor
92 *
93 * @return True if the accessor was called else false
94 */
95 bool call_accessor();
96 /** Binds the tensor with an edge
97 *
98 * @param[in] eid Edge ID that is bound to the tensor
99 */
100 void bind_edge(EdgeID eid);
101 /** Unbinds an edge from a tensor
102 *
103 * @param[in] eid Edge to unbind
104 */
105 void unbind_edge(EdgeID eid);
106 /** Accessor the edges that are bound with the tensor
107 *
108 * @return Bound edges
109 */
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100110 std::set<EdgeID> bound_edges() const;
Anthony Barbier2a07e182017-08-04 18:20:27 +0100111
112private:
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100113 TensorID _id; /**< Tensor id */
114 TensorDescriptor _desc; /**< Tensor metadata */
115 std::unique_ptr<ITensorHandle> _handle; /**< Tensor Handle */
116 std::unique_ptr<ITensorAccessor> _accessor; /**< Tensor Accessor */
117 std::set<EdgeID> _bound_edges; /**< Edges bound to this tensor */
Anthony Barbier2a07e182017-08-04 18:20:27 +0100118};
119} // namespace graph
120} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000121#endif /* ARM_COMPUTE_GRAPH_TENSOR_H */