aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Monahan <david.monahan@arm.com>2021-07-19 17:06:30 +0100
committerDavid Monahan <david.monahan@arm.com>2021-07-22 10:27:06 +0000
commit801e2d55de7a02b98f3d77dc9775b10b2bd9f16b (patch)
treea82709e7db40cb2982b2c5bcb4fba7d812965c7c
parentb49ed18ac76cbab23201598f08972cfed19cce4c (diff)
downloadarmnn-801e2d55de7a02b98f3d77dc9775b10b2bd9f16b.tar.gz
IVGCVSW-6077 Add the Custom Memory Allocator interface definition
* Added ICustomAllocator.hpp to include/armnn/backends/ * Added the ability to specify an ICustomAllocator to the CreationOptions Signed-off-by: David Monahan <david.monahan@arm.com> Change-Id: I820e468b691aa032c9bd2c1e1257dc9d02f981d9
-rw-r--r--CMakeLists.txt1
-rw-r--r--include/armnn/IRuntime.hpp7
-rw-r--r--include/armnn/backends/ICustomAllocator.hpp35
3 files changed, 43 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4e0a38b38..13d3937689 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -163,6 +163,7 @@ list(APPEND armnn_sources
include/armnn/DescriptorsFwd.hpp
include/armnn/Exceptions.hpp
include/armnn/backends/ILayerSupport.hpp
+ include/armnn/backends/ICustomAllocator.hpp
include/armnn/IAsyncExecutionCallback.hpp
include/armnn/ILayerVisitor.hpp
include/armnn/INetwork.hpp
diff --git a/include/armnn/IRuntime.hpp b/include/armnn/IRuntime.hpp
index f88b6b664f..bee61d21a9 100644
--- a/include/armnn/IRuntime.hpp
+++ b/include/armnn/IRuntime.hpp
@@ -14,6 +14,7 @@
#include "TypesUtils.hpp"
#include "profiling/ILocalPacketHandler.hpp"
+#include <armnn/backends/ICustomAllocator.hpp>
#include <memory>
namespace armnn
@@ -88,6 +89,7 @@ public:
: m_GpuAccTunedParameters(nullptr)
, m_EnableGpuProfiling(false)
, m_DynamicBackendsPath("")
+ , m_CustomAllocator(nullptr)
{}
/// If set, uses the GpuAcc tuned parameters from the given object when executing GPU workloads.
@@ -101,6 +103,11 @@ public:
/// Only a single path is allowed for the override
std::string m_DynamicBackendsPath;
+ /// A Custom Allocator used for allocation of working memory in the backends.
+ /// Set this for when you need to allocate Protected Working Memory, required for ProtectedMode
+ /// Only supported for GpuAcc
+ ICustomAllocator* m_CustomAllocator;
+
struct ExternalProfilingOptions
{
ExternalProfilingOptions()
diff --git a/include/armnn/backends/ICustomAllocator.hpp b/include/armnn/backends/ICustomAllocator.hpp
new file mode 100644
index 0000000000..1d4df0cb86
--- /dev/null
+++ b/include/armnn/backends/ICustomAllocator.hpp
@@ -0,0 +1,35 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <cstddef>
+#include <memory>
+
+namespace armnn
+{
+/** Custom Allocator interface */
+class ICustomAllocator
+{
+public:
+ /** Default virtual destructor. */
+ virtual ~ICustomAllocator() = default;
+
+ /** Interface to be implemented by the child class to allocate bytes
+ *
+ * @param[in] size Size to allocate
+ * @param[in] alignment Alignment that the returned pointer should comply with
+ *
+ * @return A pointer to the allocated memory
+ */
+ virtual void *allocate(size_t size, size_t alignment) = 0;
+ /** Interface to be implemented by the child class to free the allocated tensor */
+ virtual void free(void *ptr) = 0;
+
+ // Utility Function to define the Custom Memory Allocators capabilities
+ virtual bool SupportsProtectedMemory() = 0;
+
+};
+} // namespace armnn \ No newline at end of file