ArmNN
 24.02
SampleDynamicWorkloadFactory.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
9 
11 #include "SampleDynamicBackend.hpp"
13 #include "SampleTensorHandle.hpp"
14 
15 namespace sdb // sample dynamic backend
16 {
17 
18 namespace
19 {
20 static const armnn::BackendId s_Id{ GetBackendId() };
21 }
22 
23 SampleDynamicWorkloadFactory::SampleDynamicWorkloadFactory(const std::shared_ptr<SampleMemoryManager>& memoryManager)
24  : m_MemoryManager(memoryManager)
25 {
26 }
27 
29  : m_MemoryManager(new SampleMemoryManager())
30 {
31 }
32 
34 {
35  return s_Id;
36 }
37 
40  std::string& outReasonIfUnsupported)
41 {
42  return IWorkloadFactory::IsLayerSupported(s_Id, layer, dataType, outReasonIfUnsupported);
43 }
44 
45 std::unique_ptr<armnn::ITensorHandle> SampleDynamicWorkloadFactory::CreateTensorHandle(
46  const armnn::TensorInfo& tensorInfo,
47  const bool isMemoryManaged) const
48 {
49  return std::make_unique<armnn::ScopedTensorHandle>(tensorInfo);
50 }
51 
52 std::unique_ptr<armnn::ITensorHandle> SampleDynamicWorkloadFactory::CreateTensorHandle(
53  const armnn::TensorInfo& tensorInfo,
54  armnn::DataLayout dataLayout,
55  const bool isMemoryManaged) const
56 {
57  return std::make_unique<armnn::ScopedTensorHandle>(tensorInfo);
58 }
59 
60 std::unique_ptr<armnn::IWorkload> SampleDynamicWorkloadFactory::CreateAddition(
61  const armnn::AdditionQueueDescriptor& descriptor,
62  const armnn::WorkloadInfo& info) const
63 {
64  return std::make_unique<SampleDynamicAdditionWorkload>(descriptor, info);
65 }
66 
67 std::unique_ptr<armnn::IWorkload> SampleDynamicWorkloadFactory::CreateInput(
68  const armnn::InputQueueDescriptor& descriptor,
69  const armnn::WorkloadInfo& info) const
70 {
71  return std::make_unique<armnn::CopyMemGenericWorkload>(descriptor, info);
72 }
73 
74 std::unique_ptr<armnn::IWorkload> SampleDynamicWorkloadFactory::CreateOutput(
75  const armnn::OutputQueueDescriptor& descriptor,
76  const armnn::WorkloadInfo& info) const
77 {
78  return std::make_unique<armnn::CopyMemGenericWorkload>(descriptor, info);
79 }
80 
81 std::unique_ptr<armnn::IWorkload> SampleDynamicWorkloadFactory::CreateWorkload(
82  armnn::LayerType type,
83  const armnn::QueueDescriptor& descriptor,
84  const armnn::WorkloadInfo& info) const
85 {
86  using namespace armnn;
87  using namespace sdb;
88  switch(type)
89  {
90  case LayerType::Addition:
91  {
92  auto additionQueueDescriptor = PolymorphicDowncast<const AdditionQueueDescriptor*>(&descriptor);
93  return std::make_unique<SampleDynamicAdditionWorkload>(*additionQueueDescriptor, info);
94  }
95  case LayerType::Input:
96  {
97  auto inputQueueDescriptor = PolymorphicDowncast<const InputQueueDescriptor*>(&descriptor);
98  return std::make_unique<CopyMemGenericWorkload>(*inputQueueDescriptor, info);
99  }
100  case LayerType::Output:
101  {
102  auto outputQueueDescriptor = PolymorphicDowncast<const OutputQueueDescriptor*>(&descriptor);
103  return std::make_unique<CopyMemGenericWorkload>(*outputQueueDescriptor, info);
104  }
105  default:
106  return nullptr;
107  }
108 }
109 
110 } // namespace sdb
sdb::SampleDynamicWorkloadFactory::GetBackendId
const armnn::BackendId & GetBackendId() const override
Definition: SampleDynamicWorkloadFactory.cpp:33
armnn::Optional
Definition: Optional.hpp:270
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
sdb::SampleMemoryManager
Definition: SampleMemoryManager.hpp:16
SampleTensorHandle.hpp
armnn::TensorInfo
Definition: Tensor.hpp:152
sdb::SampleDynamicWorkloadFactory::CreateTensorHandle
std::unique_ptr< armnn::ITensorHandle > CreateTensorHandle(const armnn::TensorInfo &tensorInfo, const bool IsMemoryManaged=true) const override
Definition: SampleDynamicWorkloadFactory.cpp:45
SampleDynamicWorkloadFactory.hpp
SampleDynamicBackend.hpp
sdb
Definition: SampleDynamicAdditionWorkload.cpp:11
sdb::SampleDynamicWorkloadFactory::CreateWorkload
std::unique_ptr< armnn::IWorkload > CreateWorkload(armnn::LayerType type, const armnn::QueueDescriptor &descriptor, const armnn::WorkloadInfo &info) const override
Backends should implement their own CreateWorkload function with a switch statement.
Definition: SampleDynamicWorkloadFactory.cpp:81
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.hpp
sdb::SampleDynamicWorkloadFactory::CreateOutput
std::unique_ptr< armnn::IWorkload > CreateOutput(const armnn::OutputQueueDescriptor &descriptor, const armnn::WorkloadInfo &info) const
Definition: SampleDynamicWorkloadFactory.cpp:74
armnn::AdditionQueueDescriptor
Definition: WorkloadData.hpp:258
armnn::QueueDescriptor
Definition: WorkloadData.hpp:24
armnn::BoostLogSeverityMapping::info
@ info
armnn::MemCopyQueueDescriptor
Definition: WorkloadData.hpp:86
TensorHandle.hpp
MemCopyWorkload.hpp
armnn::BackendId
Definition: BackendId.hpp:75
armnn::IsLayerSupported
bool IsLayerSupported(const armnn::Layer *layer)
Definition: MockBackend.cpp:62
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
GetBackendId
const char * GetBackendId()
Definition: RefDynamicBackend.cpp:12
sdb::SampleDynamicWorkloadFactory::IsLayerSupported
static bool IsLayerSupported(const armnn::IConnectableLayer &layer, armnn::Optional< armnn::DataType > dataType, std::string &outReasonIfUnsupported)
Definition: SampleDynamicWorkloadFactory.cpp:38
sdb::SampleDynamicWorkloadFactory::CreateInput
std::unique_ptr< armnn::IWorkload > CreateInput(const armnn::InputQueueDescriptor &descriptor, const armnn::WorkloadInfo &info) const
Definition: SampleDynamicWorkloadFactory.cpp:67
SampleDynamicAdditionWorkload.hpp
armnn::IConnectableLayer
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:80
sdb::SampleDynamicWorkloadFactory::SampleDynamicWorkloadFactory
SampleDynamicWorkloadFactory()
Definition: SampleDynamicWorkloadFactory.cpp:28
armnn::LayerType
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition: Types.hpp:491
sdb::SampleDynamicWorkloadFactory::CreateAddition
std::unique_ptr< armnn::IWorkload > CreateAddition(const armnn::AdditionQueueDescriptor &descriptor, const armnn::WorkloadInfo &info) const
Definition: SampleDynamicWorkloadFactory.cpp:60