aboutsummaryrefslogtreecommitdiff
path: root/arm_compute
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2017-09-18 18:33:07 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commit511347a7282b948bddfc071e9a8fa08e79da25b4 (patch)
treefc1d9aea0c6679ff758407da5bd32a954b578d6e /arm_compute
parent96880cf00707d394938ec7fe31c21c79a2ac3f0c (diff)
downloadComputeLibrary-511347a7282b948bddfc071e9a8fa08e79da25b4.tar.gz
COMPMID-485: Offset-based memory manager support.
Adds support for offset-based memory mappings used from CPU system memory and SVM based allocations. Change-Id: Ibee6a3c02a61df9b11fe8878cfe40dc6fd9a4be0 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/88307 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'arm_compute')
-rw-r--r--arm_compute/runtime/BlobLifetimeManager.h41
-rw-r--r--arm_compute/runtime/BlobMemoryPool.h2
-rw-r--r--arm_compute/runtime/ILifetimeManager.h14
-rw-r--r--arm_compute/runtime/ISimpleLifetimeManager.h85
-rw-r--r--arm_compute/runtime/OffsetLifetimeManager.h67
-rw-r--r--arm_compute/runtime/OffsetMemoryPool.h72
6 files changed, 242 insertions, 39 deletions
diff --git a/arm_compute/runtime/BlobLifetimeManager.h b/arm_compute/runtime/BlobLifetimeManager.h
index ec43f47fe6..edf4d43421 100644
--- a/arm_compute/runtime/BlobLifetimeManager.h
+++ b/arm_compute/runtime/BlobLifetimeManager.h
@@ -24,21 +24,20 @@
#ifndef __ARM_COMPUTE_BLOBLIFETIMEMANAGER_H__
#define __ARM_COMPUTE_BLOBLIFETIMEMANAGER_H__
-#include "arm_compute/runtime/ILifetimeManager.h"
+#include "arm_compute/runtime/ISimpleLifetimeManager.h"
-#include "arm_compute/runtime/IMemoryGroup.h"
+#include "arm_compute/runtime/IMemoryPool.h"
#include "arm_compute/runtime/Types.h"
#include <cstddef>
-#include <map>
+#include <memory>
#include <vector>
namespace arm_compute
{
-class IMemoryGroup;
-
-/** Class that tracks the lifetime of registered tensors and calculates the systems memory requirements in terms of blobs */
-class BlobLifetimeManager : public ILifetimeManager
+/** Concrete class that tracks the lifetime of registered tensors and
+ * calculates the systems memory requirements in terms of blobs */
+class BlobLifetimeManager : public ISimpleLifetimeManager
{
public:
/** Constructor */
@@ -53,35 +52,15 @@ public:
BlobLifetimeManager &operator=(BlobLifetimeManager &&) = default;
// Inherited methods overridden:
- void register_group(IMemoryGroup *group) override;
- void start_lifetime(void *obj) override;
- void end_lifetime(void *obj, void **handle, size_t size) override;
std::unique_ptr<IMemoryPool> create_pool(IAllocator *allocator) override;
- bool are_all_finalized() const override;
MappingType mapping_type() const override;
private:
- /** Update blobs and mappings */
- void update_blobs_and_mappings();
+ // Inherited methods overridden:
+ void update_blobs_and_mappings() override;
private:
- /** Element struct */
- struct Element
- {
- Element(void *id_ = nullptr, void **handle_ = nullptr, size_t size_ = 0, bool status_ = false)
- : id(id_), handle(handle_), size(size_), status(status_)
- {
- }
- void *id; /**< Element id */
- void **handle; /**< Element's memory handle */
- size_t size; /**< Element's size */
- bool status; /**< Lifetime status */
- };
-
- IMemoryGroup *_active_group; /**< Active group */
- std::vector<Element> _active_elements; /**< A map that contains the active elements */
- std::map<IMemoryGroup *, std::vector<Element>> _finalized_groups; /**< A map that contains the finalized groups */
- std::vector<size_t> _blobs;
+ std::vector<size_t> _blobs; /**< Memory blobs' sizes */
};
-} // arm_compute
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_BLOBLIFETIMEMANAGER_H__ */
diff --git a/arm_compute/runtime/BlobMemoryPool.h b/arm_compute/runtime/BlobMemoryPool.h
index f703bf0b82..25bfd539f6 100644
--- a/arm_compute/runtime/BlobMemoryPool.h
+++ b/arm_compute/runtime/BlobMemoryPool.h
@@ -79,5 +79,5 @@ private:
std::vector<void *> _blobs; /**< Vector holding all the memory blobs */
std::vector<size_t> _blob_sizes; /**< Sizes of each blob */
};
-} // arm_compute
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_BLOBMEMORYPOOL_H__ */
diff --git a/arm_compute/runtime/ILifetimeManager.h b/arm_compute/runtime/ILifetimeManager.h
index 4f9af6f535..6f2c68d372 100644
--- a/arm_compute/runtime/ILifetimeManager.h
+++ b/arm_compute/runtime/ILifetimeManager.h
@@ -28,7 +28,7 @@
#include "arm_compute/runtime/Types.h"
#include <cstddef>
-#include <vector>
+#include <memory>
namespace arm_compute
{
@@ -58,6 +58,11 @@ public:
* @param[in] size Size of the given object at given time
*/
virtual void end_lifetime(void *obj, void **handle, size_t size) = 0;
+ /** Checks if the lifetime of the registered object is complete
+ *
+ * @return True if all object lifetimes are finalized else false.
+ */
+ virtual bool are_all_finalized() const = 0;
/** Creates a memory pool depending on the memory requirements
*
* @param allocator Allocator to use
@@ -65,16 +70,11 @@ public:
* @return A memory pool
*/
virtual std::unique_ptr<IMemoryPool> create_pool(IAllocator *allocator) = 0;
- /** Checks if the lifetime of the registered object is complete
- *
- * @return True if all object lifetimes are finalized else false.
- */
- virtual bool are_all_finalized() const = 0;
/** Returns the type of mappings that the lifetime manager returns
*
* @return Mapping type of the lifetime manager
*/
virtual MappingType mapping_type() const = 0;
};
-} // arm_compute
+} // namespace arm_compute
#endif /* __ARM_COMPUTE_ILIFETIMEMANAGER_H__ */
diff --git a/arm_compute/runtime/ISimpleLifetimeManager.h b/arm_compute/runtime/ISimpleLifetimeManager.h
new file mode 100644
index 0000000000..792ab0b558
--- /dev/null
+++ b/arm_compute/runtime/ISimpleLifetimeManager.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2017 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H__
+#define __ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H__
+
+#include "arm_compute/runtime/ILifetimeManager.h"
+
+#include "arm_compute/runtime/IMemoryPool.h"
+#include "arm_compute/runtime/Types.h"
+
+#include <cstddef>
+#include <map>
+#include <vector>
+
+namespace arm_compute
+{
+class IAllocator;
+class IMemoryGroup;
+
+/** Abstract class of the simple lifetime manager interface */
+class ISimpleLifetimeManager : public ILifetimeManager
+{
+public:
+ /** Constructor */
+ ISimpleLifetimeManager();
+ /** Prevent instances of this class to be copy constructed */
+ ISimpleLifetimeManager(const ISimpleLifetimeManager &) = delete;
+ /** Prevent instances of this class to be copied */
+ ISimpleLifetimeManager &operator=(const ISimpleLifetimeManager &) = delete;
+ /** Allow instances of this class to be move constructed */
+ ISimpleLifetimeManager(ISimpleLifetimeManager &&) = default;
+ /** Allow instances of this class to be moved */
+ ISimpleLifetimeManager &operator=(ISimpleLifetimeManager &&) = default;
+
+ // Inherited methods overridden:
+ void register_group(IMemoryGroup *group) override;
+ void start_lifetime(void *obj) override;
+ void end_lifetime(void *obj, void **handle, size_t size) override;
+ bool are_all_finalized() const override;
+
+protected:
+ /** Update blobs and mappings */
+ virtual void update_blobs_and_mappings() = 0;
+
+protected:
+ /** Element struct */
+ struct Element
+ {
+ Element(void *id_ = nullptr, void **handle_ = nullptr, size_t size_ = 0, bool status_ = false)
+ : id(id_), handle(handle_), size(size_), status(status_)
+ {
+ }
+ void *id; /**< Element id */
+ void **handle; /**< Element's memory handle */
+ size_t size; /**< Element's size */
+ bool status; /**< Lifetime status */
+ };
+
+ IMemoryGroup *_active_group; /**< Active group */
+ std::vector<Element> _active_elements; /**< A map that contains the active elements */
+ std::map<IMemoryGroup *, std::vector<Element>> _finalized_groups; /**< A map that contains the finalized groups */
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_ISIMPLELIFETIMEMANAGER_H__ */
diff --git a/arm_compute/runtime/OffsetLifetimeManager.h b/arm_compute/runtime/OffsetLifetimeManager.h
new file mode 100644
index 0000000000..e39d6a0d6a
--- /dev/null
+++ b/arm_compute/runtime/OffsetLifetimeManager.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2017 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_OFFSETLIFETIMEMANAGER_H__
+#define __ARM_COMPUTE_OFFSETLIFETIMEMANAGER_H__
+
+#include "arm_compute/runtime/ISimpleLifetimeManager.h"
+
+#include "arm_compute/runtime/Types.h"
+
+#include <cstddef>
+#include <map>
+#include <vector>
+
+namespace arm_compute
+{
+class IMemoryPool;
+
+/** Concrete class that tracks the lifetime of registered tensors and
+ * calculates the systems memory requirements in terms of a single blob and a list of offsets */
+class OffsetLifetimeManager : public ISimpleLifetimeManager
+{
+public:
+ /** Constructor */
+ OffsetLifetimeManager();
+ /** Prevent instances of this class to be copy constructed */
+ OffsetLifetimeManager(const OffsetLifetimeManager &) = delete;
+ /** Prevent instances of this class to be copied */
+ OffsetLifetimeManager &operator=(const OffsetLifetimeManager &) = delete;
+ /** Allow instances of this class to be move constructed */
+ OffsetLifetimeManager(OffsetLifetimeManager &&) = default;
+ /** Allow instances of this class to be moved */
+ OffsetLifetimeManager &operator=(OffsetLifetimeManager &&) = default;
+
+ // Inherited methods overridden:
+ std::unique_ptr<IMemoryPool> create_pool(IAllocator *allocator) override;
+ MappingType mapping_type() const override;
+
+private:
+ // Inherited methods overridden:
+ void update_blobs_and_mappings() override;
+
+private:
+ size_t _blob; /**< Memory blob size */
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_OFFSETLIFETIMEMANAGER_H__ */
diff --git a/arm_compute/runtime/OffsetMemoryPool.h b/arm_compute/runtime/OffsetMemoryPool.h
new file mode 100644
index 0000000000..9685fd1319
--- /dev/null
+++ b/arm_compute/runtime/OffsetMemoryPool.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2017 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_OFFSETMEMORYPOOL_H__
+#define __ARM_COMPUTE_OFFSETMEMORYPOOL_H__
+
+#include "arm_compute/runtime/IMemoryPool.h"
+
+#include "arm_compute/runtime/Types.h"
+
+#include <cstddef>
+
+namespace arm_compute
+{
+class IAllocator;
+
+/** Offset based memory pool */
+class OffsetMemoryPool : public IMemoryPool
+{
+public:
+ /** Default Constructor
+ *
+ * @note allocator should outlive the memory pool
+ *
+ * @param[in] allocator Backing memory allocator
+ * @param[in] blob_size Size of the memory be allocated
+ */
+ OffsetMemoryPool(IAllocator *allocator, size_t blob_size);
+ /** Default Destructor */
+ ~OffsetMemoryPool();
+ /** Prevent instances of this class to be copy constructed */
+ OffsetMemoryPool(const OffsetMemoryPool &) = delete;
+ /** Prevent instances of this class to be copy assigned */
+ OffsetMemoryPool &operator=(const OffsetMemoryPool &) = delete;
+ /** Allow instances of this class to be move constructed */
+ OffsetMemoryPool(OffsetMemoryPool &&) = default;
+ /** Allow instances of this class to be move assigned */
+ OffsetMemoryPool &operator=(OffsetMemoryPool &&) = default;
+
+ // Inherited methods overridden:
+ void acquire(MemoryMappings &handles) override;
+ void release(MemoryMappings &handles) override;
+ MappingType mapping_type() const override;
+ std::unique_ptr<IMemoryPool> duplicate() override;
+
+private:
+ IAllocator *_allocator; /**< Allocator to use for internal allocation */
+ void *_blob; /**< Memory blob */
+ size_t _blob_size; /**< Sizes of the allocated memory blob */
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_OFFSETMEMORYPOOL_H__ */