Georgios Pinitas | 511347a | 2017-09-18 18:33:07 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Georgios Pinitas | 511347a | 2017-09-18 18:33:07 +0100 | [diff] [blame] | 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_ISIMPLELIFETIMEMANAGER_H__ |
| 25 | #define __ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H__ |
| 26 | |
| 27 | #include "arm_compute/runtime/ILifetimeManager.h" |
| 28 | |
| 29 | #include "arm_compute/runtime/IMemoryPool.h" |
| 30 | #include "arm_compute/runtime/Types.h" |
| 31 | |
| 32 | #include <cstddef> |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 33 | #include <list> |
Georgios Pinitas | 511347a | 2017-09-18 18:33:07 +0100 | [diff] [blame] | 34 | #include <map> |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 35 | #include <set> |
Georgios Pinitas | 511347a | 2017-09-18 18:33:07 +0100 | [diff] [blame] | 36 | #include <vector> |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | class IAllocator; |
| 41 | class IMemoryGroup; |
| 42 | |
| 43 | /** Abstract class of the simple lifetime manager interface */ |
| 44 | class ISimpleLifetimeManager : public ILifetimeManager |
| 45 | { |
| 46 | public: |
| 47 | /** Constructor */ |
| 48 | ISimpleLifetimeManager(); |
| 49 | /** Prevent instances of this class to be copy constructed */ |
| 50 | ISimpleLifetimeManager(const ISimpleLifetimeManager &) = delete; |
| 51 | /** Prevent instances of this class to be copied */ |
| 52 | ISimpleLifetimeManager &operator=(const ISimpleLifetimeManager &) = delete; |
| 53 | /** Allow instances of this class to be move constructed */ |
| 54 | ISimpleLifetimeManager(ISimpleLifetimeManager &&) = default; |
| 55 | /** Allow instances of this class to be moved */ |
| 56 | ISimpleLifetimeManager &operator=(ISimpleLifetimeManager &&) = default; |
| 57 | |
| 58 | // Inherited methods overridden: |
| 59 | void register_group(IMemoryGroup *group) override; |
| 60 | void start_lifetime(void *obj) override; |
| 61 | void end_lifetime(void *obj, void **handle, size_t size) override; |
| 62 | bool are_all_finalized() const override; |
| 63 | |
| 64 | protected: |
| 65 | /** Update blobs and mappings */ |
| 66 | virtual void update_blobs_and_mappings() = 0; |
| 67 | |
| 68 | protected: |
| 69 | /** Element struct */ |
| 70 | struct Element |
| 71 | { |
| 72 | Element(void *id_ = nullptr, void **handle_ = nullptr, size_t size_ = 0, bool status_ = false) |
| 73 | : id(id_), handle(handle_), size(size_), status(status_) |
| 74 | { |
| 75 | } |
| 76 | void *id; /**< Element id */ |
| 77 | void **handle; /**< Element's memory handle */ |
| 78 | size_t size; /**< Element's size */ |
| 79 | bool status; /**< Lifetime status */ |
| 80 | }; |
| 81 | |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 82 | /** Blob struct */ |
| 83 | struct Blob |
| 84 | { |
| 85 | void *id; |
| 86 | size_t max_size; |
| 87 | std::set<void *> bound_elements; |
| 88 | }; |
| 89 | |
| 90 | IMemoryGroup *_active_group; /**< Active group */ |
| 91 | std::map<void *, Element> _active_elements; /**< A map that contains the active elements */ |
| 92 | std::list<Blob> _free_blobs; /**< Free blobs */ |
| 93 | std::list<Blob> _occupied_blobs; /**< Occupied blobs */ |
| 94 | std::map<IMemoryGroup *, std::map<void *, Element>> _finalized_groups; /**< A map that contains the finalized groups */ |
Georgios Pinitas | 511347a | 2017-09-18 18:33:07 +0100 | [diff] [blame] | 95 | }; |
| 96 | } // namespace arm_compute |
| 97 | #endif /* __ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H__ */ |