blob: 8481fa20f9951dd308b16eafa2b92087049016dd [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"
28
Georgios Pinitasdf310362018-11-14 13:16:56 +000029#include "arm_compute/runtime/IMemoryRegion.h"
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010030#include "arm_compute/runtime/Types.h"
31
32#include <cstddef>
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010033#include <memory>
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010034#include <vector>
35
36namespace arm_compute
37{
Georgios Pinitas555f1c22018-12-14 17:11:20 +000038// Forward declaration
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010039class IAllocator;
40
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010041/** Blob memory pool */
42class BlobMemoryPool : public IMemoryPool
43{
44public:
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010045 /** Default Constructor
46 *
47 * @note allocator should outlive the memory pool
48 *
Georgios Pinitas555f1c22018-12-14 17:11:20 +000049 * @param[in] allocator Backing memory allocator
50 * @param[in] blob_info Configuration information of the blobs to be allocated
Georgios Pinitasd9e5b192017-09-19 15:03:20 +010051 */
Georgios Pinitas555f1c22018-12-14 17:11:20 +000052 BlobMemoryPool(IAllocator *allocator, std::vector<BlobInfo> blob_info);
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010053 /** Default Destructor */
54 ~BlobMemoryPool();
55 /** Prevent instances of this class to be copy constructed */
56 BlobMemoryPool(const BlobMemoryPool &) = delete;
57 /** Prevent instances of this class to be copy assigned */
58 BlobMemoryPool &operator=(const BlobMemoryPool &) = delete;
59 /** Allow instances of this class to be move constructed */
60 BlobMemoryPool(BlobMemoryPool &&) = default;
61 /** Allow instances of this class to be move assigned */
62 BlobMemoryPool &operator=(BlobMemoryPool &&) = default;
63
64 // Inherited methods overridden:
65 void acquire(MemoryMappings &handles) override;
66 void release(MemoryMappings &handles) override;
67 MappingType mapping_type() const override;
68 std::unique_ptr<IMemoryPool> duplicate() override;
69
70private:
71 /** Allocates internal blobs
72 *
Georgios Pinitas555f1c22018-12-14 17:11:20 +000073 * @param blob_info Size of each blob
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010074 */
Georgios Pinitas555f1c22018-12-14 17:11:20 +000075 void allocate_blobs(const std::vector<BlobInfo> &blob_info);
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010076 /** Frees blobs **/
77 void free_blobs();
78
79private:
Georgios Pinitas555f1c22018-12-14 17:11:20 +000080 IAllocator *_allocator; /**< Allocator to use for internal allocation */
81 std::vector<std::unique_ptr<IMemoryRegion>> _blobs; /**< Vector holding all the memory blobs */
82 std::vector<BlobInfo> _blob_info; /**< Information of each blob */
Georgios Pinitasbaf174e2017-09-08 19:47:30 +010083};
Georgios Pinitas511347a2017-09-18 18:33:07 +010084} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000085#endif /* ARM_COMPUTE_BLOBMEMORYPOOL_H */