blob: 9e481bb563102be5a6d336c8b816c779f8f81f80 [file] [log] [blame]
Georgios Pinitas511347a2017-09-18 18:33:07 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2019 Arm Limited.
Georgios Pinitas511347a2017-09-18 18:33:07 +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_ISIMPLELIFETIMEMANAGER_H
25#define ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H
Georgios Pinitas511347a2017-09-18 18:33:07 +010026
27#include "arm_compute/runtime/ILifetimeManager.h"
Georgios Pinitas511347a2017-09-18 18:33:07 +010028#include "arm_compute/runtime/IMemoryPool.h"
29#include "arm_compute/runtime/Types.h"
30
31#include <cstddef>
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010032#include <list>
Georgios Pinitas511347a2017-09-18 18:33:07 +010033#include <map>
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010034#include <set>
Georgios Pinitas511347a2017-09-18 18:33:07 +010035#include <vector>
36
37namespace arm_compute
38{
39class IAllocator;
40class IMemoryGroup;
41
42/** Abstract class of the simple lifetime manager interface */
43class ISimpleLifetimeManager : public ILifetimeManager
44{
45public:
46 /** Constructor */
47 ISimpleLifetimeManager();
48 /** Prevent instances of this class to be copy constructed */
49 ISimpleLifetimeManager(const ISimpleLifetimeManager &) = delete;
50 /** Prevent instances of this class to be copied */
51 ISimpleLifetimeManager &operator=(const ISimpleLifetimeManager &) = delete;
52 /** Allow instances of this class to be move constructed */
53 ISimpleLifetimeManager(ISimpleLifetimeManager &&) = default;
54 /** Allow instances of this class to be moved */
55 ISimpleLifetimeManager &operator=(ISimpleLifetimeManager &&) = default;
56
57 // Inherited methods overridden:
58 void register_group(IMemoryGroup *group) override;
Georgios Pinitas40958ad2019-09-18 12:04:56 +010059 bool release_group(IMemoryGroup *group) override;
Georgios Pinitas511347a2017-09-18 18:33:07 +010060 void start_lifetime(void *obj) override;
Georgios Pinitas555f1c22018-12-14 17:11:20 +000061 void end_lifetime(void *obj, IMemory &obj_memory, size_t size, size_t alignment) override;
Georgios Pinitas511347a2017-09-18 18:33:07 +010062 bool are_all_finalized() const override;
63
64protected:
65 /** Update blobs and mappings */
66 virtual void update_blobs_and_mappings() = 0;
67
68protected:
69 /** Element struct */
70 struct Element
71 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 Element(void *id_ = nullptr,
73 IMemory *handle_ = nullptr,
74 size_t size_ = 0,
75 size_t alignment_ = 0,
76 bool status_ = false)
Georgios Pinitas555f1c22018-12-14 17:11:20 +000077 : id(id_), handle(handle_), size(size_), alignment(alignment_), status(status_)
Georgios Pinitas511347a2017-09-18 18:33:07 +010078 {
79 }
Georgios Pinitas555f1c22018-12-14 17:11:20 +000080 void *id; /**< Element id */
81 IMemory *handle; /**< Element's memory handle */
82 size_t size; /**< Element's size */
83 size_t alignment; /**< Alignment requirement */
84 bool status; /**< Lifetime status */
Georgios Pinitas511347a2017-09-18 18:33:07 +010085 };
86
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010087 /** Blob struct */
88 struct Blob
89 {
90 void *id;
91 size_t max_size;
Georgios Pinitas555f1c22018-12-14 17:11:20 +000092 size_t max_alignment;
Georgios Pinitas3d1489d2018-05-03 20:47:16 +010093 std::set<void *> bound_elements;
94 };
95
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010096 IMemoryGroup *_active_group; /**< Active group */
97 std::map<void *, Element> _active_elements; /**< A map that contains the active elements */
98 std::list<Blob> _free_blobs; /**< Free blobs */
99 std::list<Blob> _occupied_blobs; /**< Occupied blobs */
100 std::map<IMemoryGroup *, std::map<void *, Element>>
101 _finalized_groups; /**< A map that contains the finalized groups */
Georgios Pinitas511347a2017-09-18 18:33:07 +0100102};
103} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000104#endif /* ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H */