aboutsummaryrefslogtreecommitdiff
path: root/include/armnn
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2021-10-04 15:13:11 +0100
committerTeresaARM <teresa.charlinreyes@arm.com>2021-10-06 13:27:57 +0000
commitb8a26d8f497f92643288a4c519af4d230ede1d7e (patch)
tree89b1ad2303b8a18d4491eb47ab16f37e53e33c37 /include/armnn
parentbc3bb62c2d5b881ca7f0b3973a533134196fc802 (diff)
downloadarmnn-b8a26d8f497f92643288a4c519af4d230ede1d7e.tar.gz
IVGCVSW-6300 'IMemoryOptimizerStrategy Add strategy library and add support in BackendRegistry'
* Updated IRuntime interface for providing custom memory optimizer strategy. * Enabled selecting existing memory optimizer strategy by using BackendOptions * Added MemoryOptimizerStrategyLibrary that sets one of the existing memory optimizer strategies selected by user Signed-off-by: Sadik Armagan <sadik.armagan@arm.com> Change-Id: I037f8ac8efa79c0f71bd63e379101e3ad92d80c9
Diffstat (limited to 'include/armnn')
-rw-r--r--include/armnn/BackendOptions.hpp18
-rw-r--r--include/armnn/BackendRegistry.hpp7
-rw-r--r--include/armnn/IRuntime.hpp14
-rw-r--r--include/armnn/TypesUtils.hpp10
4 files changed, 49 insertions, 0 deletions
diff --git a/include/armnn/BackendOptions.hpp b/include/armnn/BackendOptions.hpp
index b8bf8f51f2..33cecf6614 100644
--- a/include/armnn/BackendOptions.hpp
+++ b/include/armnn/BackendOptions.hpp
@@ -296,4 +296,22 @@ void ParseOptions(const std::vector<BackendOptions>& options, BackendId backend,
}
}
+inline bool ParseBooleanBackendOption(const armnn::BackendOptions::Var& value, bool defaultValue)
+{
+ if (value.IsBool())
+ {
+ return value.AsBool();
+ }
+ return defaultValue;
+}
+
+inline std::string ParseStringBackendOption(const armnn::BackendOptions::Var& value, std::string defaultValue)
+{
+ if (value.IsString())
+ {
+ return value.AsString();
+ }
+ return defaultValue;
+}
+
} //namespace armnn
diff --git a/include/armnn/BackendRegistry.hpp b/include/armnn/BackendRegistry.hpp
index c13aa9f8b6..0d09607de2 100644
--- a/include/armnn/BackendRegistry.hpp
+++ b/include/armnn/BackendRegistry.hpp
@@ -8,7 +8,9 @@
#include <armnn/BackendId.hpp>
#include <armnn/Optional.hpp>
#include <armnn/backends/ICustomAllocator.hpp>
+#include <armnn/backends/IMemoryOptimizerStrategy.hpp>
+#include <algorithm>
#include <memory>
#include <unordered_map>
#include <functional>
@@ -22,6 +24,7 @@ namespace profiling
}
class IBackendInternal;
using IBackendInternalUniquePtr = std::unique_ptr<IBackendInternal>;
+using MemoryOptimizerStrategiesMapRef = std::unordered_map<BackendId, std::shared_ptr<IMemoryOptimizerStrategy>>;
class BackendRegistry
{
@@ -38,6 +41,8 @@ public:
void SetProfilingService(armnn::Optional<profiling::ProfilingService&> profilingService);
void RegisterAllocator(const BackendId& id, std::shared_ptr<ICustomAllocator> alloc);
std::unordered_map<BackendId, std::shared_ptr<ICustomAllocator>> GetAllocators();
+ void RegisterMemoryOptimizerStrategy(const BackendId& id, std::shared_ptr<IMemoryOptimizerStrategy> strategy);
+ MemoryOptimizerStrategiesMapRef GetMemoryOptimizerStrategies();
BackendRegistry() {}
virtual ~BackendRegistry() {}
@@ -54,6 +59,7 @@ public:
void Deregister(const BackendId& id);
void DeregisterAllocator(const BackendId &id);
+ void DeregisterMemoryOptimizerStrategy(const BackendId &id);
protected:
using FactoryStorage = std::unordered_map<BackendId, FactoryFunction>;
@@ -68,6 +74,7 @@ private:
FactoryStorage m_Factories;
armnn::Optional<profiling::ProfilingService&> m_ProfilingService;
std::unordered_map<BackendId, std::shared_ptr<ICustomAllocator>> m_CustomMemoryAllocatorMap;
+ std::unordered_map<BackendId, std::shared_ptr<IMemoryOptimizerStrategy>> m_MemoryOptimizerStrategyMap;
};
BackendRegistry& BackendRegistryInstance();
diff --git a/include/armnn/IRuntime.hpp b/include/armnn/IRuntime.hpp
index a46830c95a..ca9a0ceec2 100644
--- a/include/armnn/IRuntime.hpp
+++ b/include/armnn/IRuntime.hpp
@@ -15,6 +15,7 @@
#include "profiling/ILocalPacketHandler.hpp"
#include <armnn/backends/ICustomAllocator.hpp>
+#include <armnn/backends/IMemoryOptimizerStrategy.hpp>
#include <memory>
#include <map>
@@ -106,6 +107,7 @@ public:
, m_DynamicBackendsPath("")
, m_ProtectedMode(false)
, m_CustomAllocatorMap()
+ , m_MemoryOptimizerStrategyMap()
{}
/// If set, uses the GpuAcc tuned parameters from the given object when executing GPU workloads.
@@ -135,6 +137,14 @@ public:
/// @note Only supported for GpuAcc
std::map<BackendId, std::shared_ptr<ICustomAllocator>> m_CustomAllocatorMap;
+ /// @brief A map to define a custom memory optimizer strategy for specific backend Ids.
+ ///
+ /// @details A Memory Optimizer Strategy provides a solution to an abstract representation of
+ /// a network's memory requirements. This can also be used to return a pre-computed solution
+ /// for a specific network. Set this if you want to implement a Custom Memory Optimizer Strategy
+ /// for a given backend.
+ std::map<BackendId, std::shared_ptr<IMemoryOptimizerStrategy>> m_MemoryOptimizerStrategyMap;
+
struct ExternalProfilingOptions
{
ExternalProfilingOptions()
@@ -168,6 +178,7 @@ public:
/// {
/// {"TuningLevel", 2},
/// {"TuningFile", filename}
+ /// {"MemoryOptimizerStrategy", strategyname}
/// }
/// });
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -185,6 +196,9 @@ public:
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// The following backend options are available:
+ /// AllBackends:
+ /// "MemoryOptimizerStrategy" : string [stategynameString]
+ /// (Existing Memory Optimizer Strategies: ConstLayerMemoryOptimizerStrategy)
/// GpuAcc:
/// "TuningLevel" : int [0..3] (0=UseOnly(default) | 1=RapidTuning | 2=NormalTuning | 3=ExhaustiveTuning)
/// "TuningFile" : string [filenameString]
diff --git a/include/armnn/TypesUtils.hpp b/include/armnn/TypesUtils.hpp
index 9bd9c8148f..d08f592d86 100644
--- a/include/armnn/TypesUtils.hpp
+++ b/include/armnn/TypesUtils.hpp
@@ -249,6 +249,16 @@ constexpr const char* GetResizeMethodAsCString(ResizeMethod method)
}
}
+constexpr const char* GetMemBlockStrategyTypeName(MemBlockStrategyType memBlockStrategyType)
+{
+ switch (memBlockStrategyType)
+ {
+ case MemBlockStrategyType::SingleAxisPacking: return "SingleAxisPacking";
+ case MemBlockStrategyType::MultiAxisPacking: return "MultiAxisPacking";
+ default: return "Unknown";
+ }
+}
+
template<typename T>
struct IsHalfType
: std::integral_constant<bool, std::is_floating_point<T>::value && sizeof(T) == 2>