blob: b25efc3821897dcc76f8ba3bba1f8e7a083c9978 [file] [log] [blame]
Georgios Pinitasbaf174e2017-09-08 19:47:30 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2019 Arm Limited.
Georgios Pinitasbaf174e2017-09-08 19:47:30 +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_BLOBMEMORYPOOL_H
25#define ARM_COMPUTE_BLOBMEMORYPOOL_H
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010026
27#include "arm_compute/runtime/IMemoryPool.h"
Georgios Pinitasdf310362018-11-14 13:16:56 +000028#include "arm_compute/runtime/IMemoryRegion.h"
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010029#include "arm_compute/runtime/Types.h"
30
31#include <cstddef>
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010032#include <memory>
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010033#include <vector>
34
35namespace arm_compute
36{
Georgios Pinitas555f1c22018-12-14 17:11:20 +000037// Forward declaration
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010038class IAllocator;
39
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010040/** Blob memory pool */
41class BlobMemoryPool : public IMemoryPool
42{
43public:
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010044 /** Default Constructor
45 *
46 * @note allocator should outlive the memory pool
47 *
Georgios Pinitas555f1c22018-12-14 17:11:20 +000048 * @param[in] allocator Backing memory allocator
49 * @param[in] blob_info Configuration information of the blobs to be allocated
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010050 */
Georgios Pinitas555f1c22018-12-14 17:11:20 +000051 BlobMemoryPool(IAllocator *allocator, std::vector<BlobInfo> blob_info);
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010052 /** Default Destructor */
53 ~BlobMemoryPool();
54 /** Prevent instances of this class to be copy constructed */
55 BlobMemoryPool(const BlobMemoryPool &) = delete;
56 /** Prevent instances of this class to be copy assigned */
57 BlobMemoryPool &operator=(const BlobMemoryPool &) = delete;
58 /** Allow instances of this class to be move constructed */
59 BlobMemoryPool(BlobMemoryPool &&) = default;
60 /** Allow instances of this class to be move assigned */
61 BlobMemoryPool &operator=(BlobMemoryPool &&) = default;
62
63 // Inherited methods overridden:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010064 void acquire(MemoryMappings &handles) override;
65 void release(MemoryMappings &handles) override;
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010066 MappingType mapping_type() const override;
67 std::unique_ptr<IMemoryPool> duplicate() override;
68
69private:
70 /** Allocates internal blobs
71 *
Georgios Pinitas555f1c22018-12-14 17:11:20 +000072 * @param blob_info Size of each blob
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010073 */
Georgios Pinitas555f1c22018-12-14 17:11:20 +000074 void allocate_blobs(const std::vector<BlobInfo> &blob_info);
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010075 /** Frees blobs **/
76 void free_blobs();
77
78private:
Georgios Pinitas555f1c22018-12-14 17:11:20 +000079 IAllocator *_allocator; /**< Allocator to use for internal allocation */
80 std::vector<std::unique_ptr<IMemoryRegion>> _blobs; /**< Vector holding all the memory blobs */
81 std::vector<BlobInfo> _blob_info; /**< Information of each blob */
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010082};
Georgios Pinitas511347a2017-09-18 18:33:07 +010083} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000084#endif /* ARM_COMPUTE_BLOBMEMORYPOOL_H */