1 /* 2 * Copyright (c) 2017-2019 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_BLOBMEMORYPOOL_H 25 #define ARM_COMPUTE_BLOBMEMORYPOOL_H 26 27 #include "arm_compute/runtime/IMemoryPool.h" 28 29 #include "arm_compute/runtime/IMemoryRegion.h" 30 #include "arm_compute/runtime/Types.h" 31 32 #include <cstddef> 33 #include <memory> 34 #include <vector> 35 36 namespace arm_compute 37 { 38 // Forward declaration 39 class IAllocator; 40 41 /** Blob memory pool */ 42 class BlobMemoryPool : public IMemoryPool 43 { 44 public: 45 /** Default Constructor 46 * 47 * @note allocator should outlive the memory pool 48 * 49 * @param[in] allocator Backing memory allocator 50 * @param[in] blob_info Configuration information of the blobs to be allocated 51 */ 52 BlobMemoryPool(IAllocator *allocator, std::vector<BlobInfo> blob_info); 53 /** 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 70 private: 71 /** Allocates internal blobs 72 * 73 * @param blob_info Size of each blob 74 */ 75 void allocate_blobs(const std::vector<BlobInfo> &blob_info); 76 /** Frees blobs **/ 77 void free_blobs(); 78 79 private: 80 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 */ 83 }; 84 } // namespace arm_compute 85 #endif /* ARM_COMPUTE_BLOBMEMORYPOOL_H */ 86