Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Isabella Gottardi | d56e770 | 2018-02-28 14:29:36 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 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_ITENSOR_H__ |
| 25 | #define __ARM_COMPUTE_ITENSOR_H__ |
| 26 | |
Isabella Gottardi | d56e770 | 2018-02-28 14:29:36 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/ITensorInfo.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | |
| 29 | #include <cstdint> |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | class Coordinates; |
| 34 | |
| 35 | /** Interface for NEON tensor */ |
| 36 | class ITensor |
| 37 | { |
| 38 | public: |
| 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 Pinitas | 1562be3 | 2018-03-08 19:09:19 +0000 | [diff] [blame] | 86 | /** 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 | |
| 94 | private: |
| 95 | mutable bool _is_used = { true }; /**< Flag that marks if the tensor is used or not */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | using IImage = ITensor; |
| 99 | } |
| 100 | #endif /*__ARM_COMPUTE_ITENSOR_H__ */ |