Compute Library
 23.05
ITensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2021 Arm Limited.
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 
28 
29 #include <cstdint>
30 
31 namespace arm_compute
32 {
33 class Coordinates;
34 
35 /** Interface for CPU 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;
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  /** Marks a tensor as used */
94  void mark_as_used() const;
95 
96 private:
97  mutable bool _is_used = { true }; /**< Flag that marks if the tensor is used or not */
98 };
99 
100 using IImage = ITensor;
101 }
102 #endif /*ARM_COMPUTE_ITENSOR_H */
void mark_as_used() const
Marks a tensor as used.
Definition: ITensor.cpp:173
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
Definition: ITensor.h:63
virtual int32_t offset_element_in_bytes(const Coordinates &pos) const =0
The offset in bytes from the beginning of the memory allocation to access the element at position (x...
bool is_used() const
Flags if the tensor is used or not.
Definition: ITensor.cpp:163
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:43
Interface for CPU tensor.
Definition: ITensor.h:36
virtual ~ITensor()=default
Default virtual destructor.
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2023 Arm Limited.
void mark_as_unused() const
Marks a tensor as unused.
Definition: ITensor.cpp:168
IO formatting information class.
Definition: Types.h:2660
Coordinates of an item.
Definition: Coordinates.h:37
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void copy_from(const ITensor &src)
Copy the content of another tensor.
Definition: ITensor.cpp:35
void print(std::ostream &s, IOFormatInfo io_fmt=IOFormatInfo()) const
Print a tensor to a given stream using user defined formatting information.