blob: 131ee205ea9dc46a8cd15b04331a92a3418f8e44 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2016-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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_ITENSOR_H
25#define ARM_COMPUTE_ITENSOR_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Isabella Gottardid56e7702018-02-28 14:29:36 +000027#include "arm_compute/core/ITensorInfo.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29#include <cstdint>
30
31namespace arm_compute
32{
33class Coordinates;
34
Michele Di Giorgio33f41fa2021-03-09 14:09:08 +000035/** Interface for CPU tensor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036class ITensor
37{
38public:
39 /** Interface to be implemented by the child class to return the tensor's metadata
40 *
41 * @return A pointer to the tensor's metadata.
42 */
43 virtual ITensorInfo *info() const = 0;
44 /** Interface to be implemented by the child class to return the tensor's metadata
45 *
46 * @return A pointer to the tensor's metadata.
47 */
48 virtual ITensorInfo *info() = 0;
49 /** Default virtual destructor */
50 virtual ~ITensor() = default;
51 /** Interface to be implemented by the child class to return a pointer to CPU memory
52 *
53 * @return A CPU pointer to the beginning of the image's allocation.
54 */
55 virtual uint8_t *buffer() const = 0;
56
57 /** Return a pointer to the element at the passed coordinates
58 *
59 * @param[in] id Coordinates of the element
60 *
61 * @return Pointer to the requested element
62 */
63 inline uint8_t *ptr_to_element(const Coordinates &id) const
64 {
65 return buffer() + info()->offset_element_in_bytes(id);
66 }
67
68 /** Copy the content of another tensor.
69 *
70 * @note The number of dimensions of the source tensor must be less or equal to those of the destination tensor.
71 *
72 * @note All dimensions of the destination tensor must be greater or equal to the source tensor ones.
73 *
74 * @note num_channels() and element_size() of both tensors must match.
75 *
76 * @param[in] src Source tensor to copy from.
77 */
78 void copy_from(const ITensor &src);
79
80 /** Print a tensor to a given stream using user defined formatting information
81 *
82 * @param s Output stream
83 * @param io_fmt Format information
84 */
85 void print(std::ostream &s, IOFormatInfo io_fmt = IOFormatInfo()) const;
Georgios Pinitas1562be32018-03-08 19:09:19 +000086 /** Flags if the tensor is used or not
87 *
88 * @return True if it is used else false
89 */
90 bool is_used() const;
91 /** Marks a tensor as unused */
92 void mark_as_unused() const;
93
94private:
95 mutable bool _is_used = { true }; /**< Flag that marks if the tensor is used or not */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096};
97
98using IImage = ITensor;
99}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000100#endif /*ARM_COMPUTE_ITENSOR_H */