Compute Library
 20.11
IMemoryGroup.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_IMEMORYGROUP_H
25 #define ARM_COMPUTE_IMEMORYGROUP_H
26 
29 
30 namespace arm_compute
31 {
32 // Forward declarations
33 class IMemoryGroup;
34 class IMemoryManageable;
35 
36 /** Memory group interface */
38 {
39 public:
40  /** Default virtual destructor */
41  virtual ~IMemoryGroup() = default;
42  /** Sets a object to be managed by the given memory group
43  *
44  * @note Manager must not be finalized
45  *
46  * @param[in] obj Object to be managed
47  */
48  virtual void manage(IMemoryManageable *obj) = 0;
49  /** Finalizes memory for a given object
50  *
51  * @note Manager must not be finalized
52  *
53  * @param[in, out] obj Object to request memory for
54  * @param[in, out] obj_memory Object's memory handling interface which can be used to alter the underlying memory
55  * that is used by the object.
56  * @param[in] size Size of memory to allocate
57  * @param[in] alignment (Optional) Alignment to use
58  */
59  virtual void finalize_memory(IMemoryManageable *obj, IMemory &obj_memory, size_t size, size_t alignment) = 0;
60  /** Acquires backing memory for the whole group */
61  virtual void acquire() = 0;
62  /** Releases backing memory of the whole group */
63  virtual void release() = 0;
64  /** Gets the memory mapping of the group */
65  virtual MemoryMappings &mappings() = 0;
66 };
67 
68 /** Interface of an object than can be memory managed */
70 {
71 public:
72  /** Default virtual destructor */
73  virtual ~IMemoryManageable() = default;
74  /** Associates a memory managable object with the memory group that manages it
75  *
76  * @param[in] memory_group Memory group that manages the object.
77  */
78  virtual void associate_memory_group(IMemoryGroup *memory_group) = 0;
79 };
80 
81 /** Memory group resources scope handling class */
83 {
84 public:
85  /** Constructor
86  *
87  * @param[in] memory_group Memory group to handle
88  */
89  explicit MemoryGroupResourceScope(IMemoryGroup &memory_group)
90  : _memory_group(memory_group)
91  {
92  _memory_group.acquire();
93  }
94  /** Destructor */
96  {
97  _memory_group.release();
98  }
99 
100 private:
101  IMemoryGroup &_memory_group;
102 };
103 } // arm_compute
104 #endif /*ARM_COMPUTE_IMEMORYGROUP_H */
Memory group interface.
Definition: IMemoryGroup.h:37
Memory interface.
Definition: IMemory.h:32
virtual void acquire()=0
Acquires backing memory for the whole group.
virtual ~IMemoryGroup()=default
Default virtual destructor.
MemoryGroupResourceScope(IMemoryGroup &memory_group)
Constructor.
Definition: IMemoryGroup.h:89
Copyright (c) 2017-2020 Arm Limited.
virtual void associate_memory_group(IMemoryGroup *memory_group)=0
Associates a memory managable object with the memory group that manages it.
virtual void finalize_memory(IMemoryManageable *obj, IMemory &obj_memory, size_t size, size_t alignment)=0
Finalizes memory for a given object.
virtual void release()=0
Releases backing memory of the whole group.
virtual ~IMemoryManageable()=default
Default virtual destructor.
virtual MemoryMappings & mappings()=0
Gets the memory mapping of the group.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
Interface of an object than can be memory managed.
Definition: IMemoryGroup.h:69
std::map< IMemory *, size_t > MemoryMappings
A map of (handle, index/offset), where handle is the memory handle of the object to provide the memor...
Definition: Types.h:45
virtual void manage(IMemoryManageable *obj)=0
Sets a object to be managed by the given memory group.