2 * Copyright (c) 2016-2018 ARM Limited.
4 * SPDX-License-Identifier: MIT
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:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
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
24 #ifndef __ARM_COMPUTE_ITENSOR_H__
25 #define __ARM_COMPUTE_ITENSOR_H__
27 #include "arm_compute/core/ITensorInfo.h"
35 /** Interface for NEON tensor */
39 /** Interface to be implemented by the child class to return the tensor's metadata
41 * @return A pointer to the tensor's metadata.
43 virtual ITensorInfo *info() const = 0;
44 /** Interface to be implemented by the child class to return the tensor's metadata
46 * @return A pointer to the tensor's metadata.
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
53 * @return A CPU pointer to the beginning of the image's allocation.
55 virtual uint8_t *buffer() const = 0;
57 /** Return a pointer to the element at the passed coordinates
59 * @param[in] id Coordinates of the element
61 * @return Pointer to the requested element
63 inline uint8_t *ptr_to_element(const Coordinates &id) const
65 return buffer() + info()->offset_element_in_bytes(id);
68 /** Copy the content of another tensor.
70 * @note The number of dimensions of the source tensor must be less or equal to those of the destination tensor.
72 * @note All dimensions of the destination tensor must be greater or equal to the source tensor ones.
74 * @note num_channels() and element_size() of both tensors must match.
76 * @param[in] src Source tensor to copy from.
78 void copy_from(const ITensor &src);
80 /** Print a tensor to a given stream using user defined formatting information
82 * @param s Output stream
83 * @param io_fmt Format information
85 void print(std::ostream &s, IOFormatInfo io_fmt = IOFormatInfo()) const;
86 /** Flags if the tensor is used or not
88 * @return True if it is used else false
91 /** Marks a tensor as unused */
92 void mark_as_unused() const;
95 mutable bool _is_used = { true }; /**< Flag that marks if the tensor is used or not */
98 using IImage = ITensor;
100 #endif /*__ARM_COMPUTE_ITENSOR_H__ */