Compute Library
 23.08
ISimpleLifetimeManager.h
Go to the documentation of this file.
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_ISIMPLELIFETIMEMANAGER_H
25 #define ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H
26 
28 
31 
32 #include <cstddef>
33 #include <list>
34 #include <map>
35 #include <set>
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 */
45 {
46 public:
47  /** Constructor */
49  /** Prevent instances of this class to be copy constructed */
51  /** Prevent instances of this class to be copied */
53  /** Allow instances of this class to be move constructed */
55  /** Allow instances of this class to be moved */
57 
58  // Inherited methods overridden:
59  void register_group(IMemoryGroup *group) override;
60  bool release_group(IMemoryGroup *group) override;
61  void start_lifetime(void *obj) override;
62  void end_lifetime(void *obj, IMemory &obj_memory, size_t size, size_t alignment) override;
63  bool are_all_finalized() const override;
64 
65 protected:
66  /** Update blobs and mappings */
67  virtual void update_blobs_and_mappings() = 0;
68 
69 protected:
70  /** Element struct */
71  struct Element
72  {
73  Element(void *id_ = nullptr, IMemory *handle_ = nullptr, size_t size_ = 0, size_t alignment_ = 0, bool status_ = false)
74  : id(id_), handle(handle_), size(size_), alignment(alignment_), status(status_)
75  {
76  }
77  void *id; /**< Element id */
78  IMemory *handle; /**< Element's memory handle */
79  size_t size; /**< Element's size */
80  size_t alignment; /**< Alignment requirement */
81  bool status; /**< Lifetime status */
82  };
83 
84  /** Blob struct */
85  struct Blob
86  {
87  void *id;
88  size_t max_size;
89  size_t max_alignment;
90  std::set<void *> bound_elements;
91  };
92 
93  IMemoryGroup *_active_group; /**< Active group */
94  std::map<void *, Element> _active_elements; /**< A map that contains the active elements */
95  std::list<Blob> _free_blobs; /**< Free blobs */
96  std::list<Blob> _occupied_blobs; /**< Occupied blobs */
97  std::map<IMemoryGroup *, std::map<void *, Element>> _finalized_groups; /**< A map that contains the finalized groups */
98 };
99 } // namespace arm_compute
100 #endif /* ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H */
IMemoryPool.h
arm_compute::ISimpleLifetimeManager::release_group
bool release_group(IMemoryGroup *group) override
Unbound and release elements associated with a group.
Definition: ISimpleLifetimeManager.cpp:53
Types.h
arm_compute::ILifetimeManager
Interface for managing the lifetime of objects.
Definition: ILifetimeManager.h:41
ILifetimeManager.h
arm_compute::IMemoryGroup
Memory group interface.
Definition: IMemoryGroup.h:37
arm_compute::ISimpleLifetimeManager::end_lifetime
void end_lifetime(void *obj, IMemory &obj_memory, size_t size, size_t alignment) override
Ends lifetime of an object.
Definition: ISimpleLifetimeManager.cpp:87
arm_compute::ISimpleLifetimeManager::start_lifetime
void start_lifetime(void *obj) override
Registers and starts lifetime of an object.
Definition: ISimpleLifetimeManager.cpp:67
arm_compute::IMemory
Memory interface.
Definition: IMemory.h:32
arm_compute::ISimpleLifetimeManager::ISimpleLifetimeManager
ISimpleLifetimeManager()
Constructor.
Definition: ISimpleLifetimeManager.cpp:39
arm_compute::ISimpleLifetimeManager::register_group
void register_group(IMemoryGroup *group) override
Registers a group to the lifetime manager and assigns a group id.
Definition: ISimpleLifetimeManager.cpp:44
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::ISimpleLifetimeManager::operator=
ISimpleLifetimeManager & operator=(const ISimpleLifetimeManager &)=delete
Prevent instances of this class to be copied.
arm_compute::ISimpleLifetimeManager::are_all_finalized
bool are_all_finalized() const override
Checks if the lifetime of the registered object is complete.
Definition: ISimpleLifetimeManager.cpp:134
arm_compute::ISimpleLifetimeManager
Abstract class of the simple lifetime manager interface.
Definition: ISimpleLifetimeManager.h:44