6 #include <doctest/doctest.h> 26 using namespace armnn;
31 TestMemMgr() =
default;
33 void Acquire()
override {}
34 void Release()
override {}
45 std::unique_ptr<ITensorHandle> CreateSubTensorHandle(
ITensorHandle& parent,
47 unsigned int const* subTensorOrigin)
const override 53 std::unique_ptr<ITensorHandle> CreateTensorHandle(
const TensorInfo& tensorInfo)
const override 59 std::unique_ptr<ITensorHandle> CreateTensorHandle(
const TensorInfo& tensorInfo,
66 const FactoryId& GetId()
const override {
return m_Id; }
68 bool SupportsSubTensors()
const override {
return true; }
75 std::weak_ptr<IMemoryManager> m_MemMgr;
86 std::unique_ptr<ITensorHandle> CreateSubTensorHandle(
ITensorHandle& parent,
88 unsigned int const* subTensorOrigin)
const override 94 std::unique_ptr<ITensorHandle> CreateTensorHandle(
const TensorInfo& tensorInfo)
const override 100 std::unique_ptr<ITensorHandle> CreateTensorHandle(
const TensorInfo& tensorInfo,
107 const FactoryId& GetId()
const override {
return m_Id; }
109 bool SupportsSubTensors()
const override {
return true; }
116 std::weak_ptr<IMemoryManager> m_MemMgr;
122 TestBackendA() =
default;
124 const BackendId& GetId()
const override {
return m_Id; }
126 IWorkloadFactoryPtr CreateWorkloadFactory(
const IMemoryManagerSharedPtr& memoryManager =
nullptr)
const override 129 return IWorkloadFactoryPtr{};
137 std::vector<ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences()
const override 139 return std::vector<ITensorHandleFactory::FactoryId>
141 "TestHandleFactoryA1",
142 "TestHandleFactoryA2",
143 "TestHandleFactoryB1",
144 "TestHandleFactoryD1" 150 auto mgr = std::make_shared<TestMemMgr>();
153 registry.
RegisterFactory(std::make_unique<TestFactory1>(mgr,
"TestHandleFactoryA1"));
154 registry.
RegisterFactory(std::make_unique<TestFactory1>(mgr,
"TestHandleFactoryA2"));
164 TestBackendB() =
default;
166 const BackendId& GetId()
const override {
return m_Id; }
168 IWorkloadFactoryPtr CreateWorkloadFactory(
const IMemoryManagerSharedPtr& memoryManager =
nullptr)
const override 171 return IWorkloadFactoryPtr{};
179 std::vector<ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences()
const override 181 return std::vector<ITensorHandleFactory::FactoryId>
183 "TestHandleFactoryB1" 189 auto mgr = std::make_shared<TestMemMgr>();
192 registry.
RegisterFactory(std::make_unique<TestFactory1>(mgr,
"TestHandleFactoryB1"));
202 TestBackendC() =
default;
204 const BackendId& GetId()
const override {
return m_Id; }
206 IWorkloadFactoryPtr CreateWorkloadFactory(
const IMemoryManagerSharedPtr& memoryManager =
nullptr)
const override 209 return IWorkloadFactoryPtr{};
217 std::vector<ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences()
const override 219 return std::vector<ITensorHandleFactory::FactoryId>{
220 "TestHandleFactoryC1" 226 auto mgr = std::make_shared<TestMemMgr>();
229 registry.
RegisterFactory(std::make_unique<TestFactory1>(mgr,
"TestHandleFactoryC1"));
239 TestBackendD() =
default;
241 const BackendId& GetId()
const override {
return m_Id; }
243 IWorkloadFactoryPtr CreateWorkloadFactory(
const IMemoryManagerSharedPtr& memoryManager =
nullptr)
const override 246 return IWorkloadFactoryPtr{};
254 std::vector<ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences()
const override 256 return std::vector<ITensorHandleFactory::FactoryId>{
257 "TestHandleFactoryD1",
263 auto mgr = std::make_shared<TestMemMgr>();
266 registry.
RegisterFactory(std::make_unique<TestFactoryImport>(mgr,
"TestHandleFactoryD1"));
276 TEST_CASE(
"RegisterFactories")
278 TestBackendA backendA;
279 TestBackendB backendB;
281 CHECK(backendA.GetHandleFactoryPreferences()[0] ==
"TestHandleFactoryA1");
282 CHECK(backendA.GetHandleFactoryPreferences()[1] ==
"TestHandleFactoryA2");
283 CHECK(backendA.GetHandleFactoryPreferences()[2] ==
"TestHandleFactoryB1");
284 CHECK(backendA.GetHandleFactoryPreferences()[3] ==
"TestHandleFactoryD1");
287 backendA.RegisterTensorHandleFactories(registry);
288 backendB.RegisterTensorHandleFactories(registry);
290 CHECK((registry.GetFactory(
"Non-existing Backend") ==
nullptr));
291 CHECK((registry.GetFactory(
"TestHandleFactoryA1") !=
nullptr));
292 CHECK((registry.GetFactory(
"TestHandleFactoryA2") !=
nullptr));
293 CHECK((registry.GetFactory(
"TestHandleFactoryB1") !=
nullptr));
296 TEST_CASE(
"TensorHandleSelectionStrategy")
298 auto backendA = std::make_unique<TestBackendA>();
299 auto backendB = std::make_unique<TestBackendB>();
300 auto backendC = std::make_unique<TestBackendC>();
301 auto backendD = std::make_unique<TestBackendD>();
304 backendA->RegisterTensorHandleFactories(registry);
305 backendB->RegisterTensorHandleFactories(registry);
306 backendC->RegisterTensorHandleFactories(registry);
307 backendD->RegisterTensorHandleFactories(registry);
310 backends[
"BackendA"] = std::move(backendA);
311 backends[
"BackendB"] = std::move(backendB);
312 backends[
"BackendC"] = std::move(backendC);
313 backends[
"BackendD"] = std::move(backendD);
344 std::vector<std::string> errors;
347 CHECK(result.m_Error ==
false);
348 CHECK(result.m_Warning ==
false);
381 CHECK(copyCount == 1);
392 CHECK(importCount == 1);
395 TEST_CASE(
"RegisterCopyAndImportFactoryPairTest")
TEST_SUITE("TestConstTensorLayerVisitor")
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
No strategy has been defined. Used internally to verify integrity of optimizations.
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
Source backends tensor data can be exported to destination backend tensor without copy...
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
int Connect(InputSlot &destination)
EdgeStrategy GetEdgeStrategyForConnection(unsigned int connectionIdx) const
unsigned int MemorySourceFlags
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
void SetBackendId(const BackendId &id)
Destination backend can work directly with tensors on source backend.
void RegisterCopyAndImportFactoryPair(ITensorHandleFactory::FactoryId copyFactoryId, ITensorHandleFactory::FactoryId importFactoryId)
Register a pair of TensorHandleFactory Id for Memory Copy and TensorHandleFactory Id for Memory Impor...
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
A layer user-provided data can be bound to (e.g. inputs, outputs).
void ForEachLayer(Func func) const
ITensorHandleFactory::FactoryId FactoryId
This layer represents a softmax operation.
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
ITensorHandleFactory::FactoryId GetMatchingImportFactoryId(ITensorHandleFactory::FactoryId copyFactoryId)
Get a matching TensorHandleFatory Id for Memory Import given TensorHandleFactory Id for Memory Copy...
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
OptimizationResult SelectTensorHandleStrategy(Graph &optGraph, BackendsMap &backends, TensorHandleFactoryRegistry ®istry, bool importEnabled, Optional< std::vector< std::string > &> errMessages)
ITensorHandleFactory::FactoryId GetTensorHandleFactoryId() const
Graph & TopologicalSort()
Sorts layers in topological order and return this.
A SoftmaxDescriptor for the SoftmaxLayer.
void AddCompatibilityLayers(std::map< BackendId, std::unique_ptr< class IBackendInternal >> &backends, TensorHandleFactoryRegistry ®istry)
Modifies the graph in-place, removing edges connecting layers using different compute devices...
std::map< BackendId, std::unique_ptr< class IBackendInternal > > BackendsMap