blob: 6103e436bc910f3d8fef5d9257650661397513bf [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 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_ITENSORALLOCATOR_H__
25#define __ARM_COMPUTE_ITENSORALLOCATOR_H__
26
27#include "arm_compute/core/TensorInfo.h"
28#include "arm_compute/core/Types.h"
29
30#include <cstdint>
31
32namespace arm_compute
33{
34/** Interface to allocate tensors */
35class ITensorAllocator
36{
37public:
38 /** Default constructor. */
39 ITensorAllocator();
40 /** Allow instances of this class to be copy constructed */
41 ITensorAllocator(const ITensorAllocator &) = default;
42 /** Allow instances of this class to be copied */
43 ITensorAllocator &operator=(const ITensorAllocator &) = default;
44 /** Allow instances of this class to be move constructed */
45 ITensorAllocator(ITensorAllocator &&) = default;
46 /** Allow instances of this class to be moved */
47 ITensorAllocator &operator=(ITensorAllocator &&) = default;
48 /** Default virtual destructor. */
49 virtual ~ITensorAllocator() = default;
50
51 /** Initialize a tensor based on the passed @ref TensorInfo.
52 *
53 * @param[in] input TensorInfo object containing the description of the tensor to initialize.
54 */
55 void init(const TensorInfo &input);
56 /** Return a reference to the tensor's metadata
57 *
58 * @return Reference to the tensor's metadata.
59 */
60 TensorInfo &info();
61 /** Return a constant reference to the tensor's metadata
62 *
63 * @return Constant reference to the tensor's metadata.
64 */
65 const TensorInfo &info() const;
66
67 /** Interface to be implemented by the child class to allocate the tensor.
68 *
69 * @note The child is expected to use the TensorInfo to get the size of the memory allocation.
70 * @warning The tensor must not already be allocated. Otherwise calling the function will fail.
71 */
72 virtual void allocate() = 0;
73
74 /** Interface to be implemented by the child class to free the allocated tensor.
75 *
76 * @warning The tensor must have been allocated previously. Otherwise calling the function will fail.
77 */
78 virtual void free() = 0;
79
80protected:
81 /** Interface to be implemented by the child class to lock the memory allocation for the CPU to access.
82 *
83 * @return Pointer to a CPU mapping of the memory
84 */
85 virtual uint8_t *lock() = 0;
86 /** Interface to be implemented by the child class to unlock the memory allocation after the CPU is done accessing it. */
87 virtual void unlock() = 0;
88
89private:
90 TensorInfo _info; /**< Tensor's metadata. */
91};
92}
93#endif /*__ARM_COMPUTE_ITENSORALLOCATOR_H__ */