aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/runtime/MemoryRegion.h
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-06-18 18:13:51 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:53:20 +0000
commit17b12307edeaf488cfdf0cc3fa00b8f08293c93e (patch)
treed7025d84a03d9897b4811ade16a2a1952bdb09c4 /arm_compute/runtime/MemoryRegion.h
parent09b19129b65c5b8d1ca1c3851bab919bb9b7e1a1 (diff)
downloadComputeLibrary-17b12307edeaf488cfdf0cc3fa00b8f08293c93e.tar.gz
COMPMID-1293: Handle aligned allocations
Change-Id: I6e642c8cd968240f883c327464519e57e5d0c3e3 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/136088 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'arm_compute/runtime/MemoryRegion.h')
-rw-r--r--arm_compute/runtime/MemoryRegion.h29
1 files changed, 21 insertions, 8 deletions
diff --git a/arm_compute/runtime/MemoryRegion.h b/arm_compute/runtime/MemoryRegion.h
index bf4e1719de..481b20d375 100644
--- a/arm_compute/runtime/MemoryRegion.h
+++ b/arm_compute/runtime/MemoryRegion.h
@@ -27,6 +27,7 @@
#include "arm_compute/runtime/IMemoryRegion.h"
#include "arm_compute/core/Error.h"
+#include "support/ToolchainSupport.h"
#include <cstddef>
@@ -38,18 +39,28 @@ class MemoryRegion final : public IMemoryRegion
public:
/** Default constructor
*
- * @param[in] size Region size
+ * @param[in] size Region size
+ * @param[in] alignment Alignment in bytes of the base pointer. Defaults to 0
*/
- MemoryRegion(size_t size)
- : IMemoryRegion(size), _mem(nullptr), _ptr(nullptr)
+ MemoryRegion(size_t size, size_t alignment = 0)
+ : IMemoryRegion(size), _mem(nullptr), _alignment(alignment), _offset(0)
{
if(size != 0)
{
- _mem = std::shared_ptr<uint8_t>(new uint8_t[size](), [](uint8_t *ptr)
+ // Allocate backing memory
+ size_t space = size + alignment;
+ _mem = std::shared_ptr<uint8_t>(new uint8_t[space](), [](uint8_t *ptr)
{
delete[] ptr;
});
- _ptr = _mem.get();
+
+ // Calculate alignment offset
+ if(alignment != 0)
+ {
+ void *aligned_ptr = _mem.get();
+ support::cpp11::align(alignment, size, aligned_ptr, space);
+ _offset = reinterpret_cast<uintptr_t>(aligned_ptr) - reinterpret_cast<uintptr_t>(_mem.get());
+ }
}
}
/** Prevent instances of this class from being copied (As this class contains pointers) */
@@ -64,11 +75,12 @@ public:
// Inherited methods overridden :
void *buffer() final
{
- return _mem.get();
+ return reinterpret_cast<void *>(_mem.get() + _offset);
}
void *buffer() const final
{
- return _mem.get();
+ // FIXME (COMPMID-1088) : Remove handle() and _offset when done
+ return reinterpret_cast<void *>(_mem.get() + _offset);
}
void **handle() final
{
@@ -77,7 +89,8 @@ public:
protected:
std::shared_ptr<uint8_t> _mem;
- uint8_t *_ptr;
+ size_t _alignment;
+ size_t _offset;
};
} // namespace arm_compute
#endif /* __ARM_COMPUTE_RUNTIME_MEMORY_REGION_H__ */