telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 7 | #include <armnn/Optional.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 8 | #include <backendsCommon/WorkloadFactory.hpp> |
| 9 | #include <backendsCommon/OutputHandler.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 11 | #include "RefMemoryManager.hpp" |
| 12 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | #include <boost/core/ignore_unused.hpp> |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 14 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | namespace armnn |
| 17 | { |
| 18 | |
| 19 | template <typename QueueDescriptorType> |
| 20 | constexpr bool IsOperationQueueDescriptor(const QueueDescriptorType&) { return true; } |
| 21 | |
| 22 | template <> |
| 23 | constexpr bool IsOperationQueueDescriptor(const MemCopyQueueDescriptor&) { return false; } |
| 24 | |
| 25 | template <> |
| 26 | constexpr bool IsOperationQueueDescriptor(const ConstantQueueDescriptor&) { return false; } |
| 27 | |
| 28 | template <> |
| 29 | constexpr bool IsOperationQueueDescriptor(const PermuteQueueDescriptor&) { return false; } |
| 30 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 31 | // Reference workload factory. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 32 | class RefWorkloadFactory : public IWorkloadFactory |
| 33 | { |
| 34 | public: |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 35 | explicit RefWorkloadFactory(const std::shared_ptr<RefMemoryManager>& memoryManager); |
| 36 | RefWorkloadFactory(); |
| 37 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 38 | ~RefWorkloadFactory() {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 39 | |
David Beck | 79141b9 | 2018-10-23 16:09:36 +0100 | [diff] [blame] | 40 | const BackendId& GetBackendId() const override; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 42 | static bool IsLayerSupported(const Layer& layer, |
| 43 | Optional<DataType> dataType, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | std::string& outReasonIfUnsupported); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 45 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 46 | bool SupportsSubTensors() const override { return false; } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 47 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 48 | std::unique_ptr<ITensorHandle> CreateSubTensorHandle(ITensorHandle& parent, |
| 49 | TensorShape const& subTensorShape, |
| 50 | unsigned int const* subTensorOrigin) const override |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 51 | { |
| 52 | boost::ignore_unused(parent, subTensorShape, subTensorOrigin); |
| 53 | return nullptr; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 54 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 55 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 56 | std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo) const override; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 57 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 58 | std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo, |
| 59 | DataLayout dataLayout) const override; |
Francis Murtagh | 351d13d | 2018-09-24 15:01:18 +0100 | [diff] [blame] | 60 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 61 | std::unique_ptr<IWorkload> CreateInput(const InputQueueDescriptor& descriptor, |
| 62 | const WorkloadInfo& info) const override; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 63 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 64 | std::unique_ptr<IWorkload> CreateOutput(const OutputQueueDescriptor& descriptor, |
| 65 | const WorkloadInfo& info) const override; |
| 66 | |
| 67 | std::unique_ptr<IWorkload> CreateActivation(const ActivationQueueDescriptor& descriptor, |
| 68 | const WorkloadInfo& info) const override; |
| 69 | |
| 70 | std::unique_ptr<IWorkload> CreateSoftmax(const SoftmaxQueueDescriptor& descriptor, |
| 71 | const WorkloadInfo& info) const override; |
| 72 | |
| 73 | std::unique_ptr<IWorkload> CreateSplitter(const SplitterQueueDescriptor& descriptor, |
| 74 | const WorkloadInfo& info) const override; |
| 75 | |
Jim Flynn | 4ed6c83 | 2019-05-20 11:02:46 +0100 | [diff] [blame] | 76 | ARMNN_DEPRECATED_MSG("Use CreateConcat instead") |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 77 | std::unique_ptr<IWorkload> CreateMerger(const MergerQueueDescriptor& descriptor, |
| 78 | const WorkloadInfo& info) const override; |
| 79 | |
| 80 | std::unique_ptr<IWorkload> CreateFullyConnected(const FullyConnectedQueueDescriptor& descriptor, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 81 | const WorkloadInfo& info) const override; |
| 82 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 83 | std::unique_ptr<IWorkload> CreatePooling2d(const Pooling2dQueueDescriptor& descriptor, |
| 84 | const WorkloadInfo& info) const override; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 85 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 86 | std::unique_ptr<IWorkload> CreatePermute(const PermuteQueueDescriptor& descriptor, |
| 87 | const WorkloadInfo& info) const override; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 88 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 89 | std::unique_ptr<IWorkload> CreateConvolution2d(const Convolution2dQueueDescriptor& descriptor, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 90 | const WorkloadInfo& info) const override; |
| 91 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 92 | std::unique_ptr<IWorkload> CreateDepthwiseConvolution2d(const DepthwiseConvolution2dQueueDescriptor& descriptor, |
| 93 | const WorkloadInfo& info) const override; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 94 | |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 95 | std::unique_ptr<IWorkload> CreateDetectionPostProcess(const DetectionPostProcessQueueDescriptor& descriptor, |
| 96 | const WorkloadInfo& info) const override; |
| 97 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 98 | std::unique_ptr<IWorkload> CreateNormalization(const NormalizationQueueDescriptor& descriptor, |
| 99 | const WorkloadInfo& info) const override; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 100 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 101 | std::unique_ptr<IWorkload> CreateMultiplication(const MultiplicationQueueDescriptor& descriptor, |
| 102 | const WorkloadInfo& info) const override; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 103 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 104 | std::unique_ptr<IWorkload> CreateAddition(const AdditionQueueDescriptor& descriptor, |
| 105 | const WorkloadInfo& info) const override; |
| 106 | |
| 107 | std::unique_ptr<IWorkload> CreateBatchNormalization(const BatchNormalizationQueueDescriptor& descriptor, |
| 108 | const WorkloadInfo& info) const override; |
| 109 | |
| 110 | std::unique_ptr<IWorkload> CreateMemCopy(const MemCopyQueueDescriptor& descriptor, |
| 111 | const WorkloadInfo& info) const override; |
| 112 | |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 113 | std::unique_ptr<IWorkload> CreateResize(const ResizeQueueDescriptor& descriptor, |
| 114 | const WorkloadInfo& info) const override; |
| 115 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 116 | std::unique_ptr<IWorkload> CreateResizeBilinear(const ResizeBilinearQueueDescriptor& descriptor, |
| 117 | const WorkloadInfo& info) const override; |
| 118 | |
| 119 | std::unique_ptr<IWorkload> CreateFakeQuantization(const FakeQuantizationQueueDescriptor& descriptor, |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 120 | const WorkloadInfo& info) const override; |
| 121 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 122 | std::unique_ptr<IWorkload> CreateL2Normalization(const L2NormalizationQueueDescriptor& descriptor, |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 123 | const WorkloadInfo& info) const override; |
| 124 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 125 | std::unique_ptr<IWorkload> CreateConcat(const ConcatQueueDescriptor& descriptor, |
Jim Flynn | 4ed6c83 | 2019-05-20 11:02:46 +0100 | [diff] [blame] | 126 | const WorkloadInfo& info) const override; |
| 127 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 128 | std::unique_ptr<IWorkload> CreateConstant(const ConstantQueueDescriptor& descriptor, |
| 129 | const WorkloadInfo& info) const override; |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 130 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 131 | std::unique_ptr<IWorkload> CreateReshape(const ReshapeQueueDescriptor& descriptor, |
| 132 | const WorkloadInfo& info) const override; |
| 133 | |
| 134 | std::unique_ptr<IWorkload> CreateSpaceToBatchNd(const SpaceToBatchNdQueueDescriptor& descriptor, |
| 135 | const WorkloadInfo& info) const override; |
| 136 | |
Keith Davis | a57eccb | 2019-06-14 17:33:22 +0100 | [diff] [blame] | 137 | std::unique_ptr<IWorkload> CreateSpaceToDepth(const SpaceToDepthQueueDescriptor& descriptor, |
| 138 | const WorkloadInfo& info) const override; |
| 139 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 140 | std::unique_ptr<IWorkload> CreateFloor(const FloorQueueDescriptor& descriptor, |
| 141 | const WorkloadInfo& info) const override; |
| 142 | |
| 143 | std::unique_ptr<IWorkload> CreateLstm(const LstmQueueDescriptor& descriptor, |
| 144 | const WorkloadInfo& info) const override; |
| 145 | |
| 146 | std::unique_ptr<IWorkload> CreateConvertFp16ToFp32(const ConvertFp16ToFp32QueueDescriptor& descriptor, |
| 147 | const WorkloadInfo& info) const override; |
| 148 | |
| 149 | std::unique_ptr<IWorkload> CreateConvertFp32ToFp16(const ConvertFp32ToFp16QueueDescriptor& descriptor, |
| 150 | const WorkloadInfo& info) const override; |
| 151 | |
| 152 | std::unique_ptr<IWorkload> CreateDivision(const DivisionQueueDescriptor& descriptor, |
| 153 | const WorkloadInfo& info) const override; |
| 154 | |
| 155 | std::unique_ptr<IWorkload> CreateSubtraction(const SubtractionQueueDescriptor& descriptor, |
jimfly01 | 2c9322a | 2018-09-19 10:59:49 +0100 | [diff] [blame] | 156 | const WorkloadInfo& info) const override; |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 157 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 158 | std::unique_ptr<IWorkload> CreateMaximum(const MaximumQueueDescriptor& descriptor, |
| 159 | const WorkloadInfo& info) const override; |
FrancisMurtagh | 2099595 | 2018-12-17 12:11:36 +0000 | [diff] [blame] | 160 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 161 | std::unique_ptr<IWorkload> CreateMean(const MeanQueueDescriptor& descriptor, |
| 162 | const WorkloadInfo& Info) const override; |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 163 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 164 | std::unique_ptr<IWorkload> CreatePad(const PadQueueDescriptor& descriptor, |
| 165 | const WorkloadInfo& info) const override; |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 166 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 167 | std::unique_ptr<IWorkload> CreateEqual(const EqualQueueDescriptor& descriptor, |
| 168 | const WorkloadInfo& info) const override; |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 169 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 170 | std::unique_ptr<IWorkload> CreateBatchToSpaceNd(const BatchToSpaceNdQueueDescriptor& descriptor, |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 171 | const WorkloadInfo& info) const override; |
| 172 | |
Matteo Martincigh | 3d6898c | 2019-01-15 16:11:44 +0000 | [diff] [blame] | 173 | std::unique_ptr<IWorkload> CreateStridedSlice(const StridedSliceQueueDescriptor& descriptor, |
| 174 | const WorkloadInfo& info) const override; |
| 175 | |
| 176 | std::unique_ptr<IWorkload> CreateMinimum(const MinimumQueueDescriptor& descriptor, |
| 177 | const WorkloadInfo& info) const override; |
| 178 | |
| 179 | std::unique_ptr<IWorkload> CreateGreater(const GreaterQueueDescriptor& descriptor, |
| 180 | const WorkloadInfo& info) const override; |
| 181 | |
| 182 | std::unique_ptr<IWorkload> CreateDebug(const DebugQueueDescriptor& descriptor, |
| 183 | const WorkloadInfo& info) const override; |
| 184 | |
| 185 | std::unique_ptr<IWorkload> CreateRsqrt(const RsqrtQueueDescriptor& descriptor, |
| 186 | const WorkloadInfo& info) const override; |
| 187 | |
| 188 | std::unique_ptr<IWorkload> CreatePreCompiled(const PreCompiledQueueDescriptor& descriptor, |
| 189 | const WorkloadInfo& info) const override; |
| 190 | |
| 191 | std::unique_ptr<IWorkload> CreateGather(const GatherQueueDescriptor& descriptor, |
| 192 | const WorkloadInfo& info) const override; |
| 193 | |
Nattapat Chaimanowong | 8a54ac0 | 2019-03-29 15:25:04 +0000 | [diff] [blame] | 194 | std::unique_ptr<IWorkload> CreateDequantize(const DequantizeQueueDescriptor& descriptor, |
| 195 | const WorkloadInfo& info) const override; |
| 196 | |
Derek Lamberti | 5f400d6 | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 197 | std::unique_ptr<IWorkload> CreateQuantize(const QuantizeQueueDescriptor& descriptor, |
| 198 | const WorkloadInfo& info) const override; |
| 199 | |
Matteo Martincigh | ab9e525 | 2019-06-13 17:27:46 +0100 | [diff] [blame] | 200 | std::unique_ptr<IWorkload> CreatePrelu(const PreluQueueDescriptor& descriptor, |
| 201 | const WorkloadInfo& info) const override; |
| 202 | |
Aron Virginas-Tar | 735a450 | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 203 | std::unique_ptr<IWorkload> CreateTransposeConvolution2d(const TransposeConvolution2dQueueDescriptor& descriptor, |
| 204 | const WorkloadInfo& info) const override; |
| 205 | |
Matthew Jackson | 81e601c | 2019-07-11 12:07:09 +0100 | [diff] [blame] | 206 | std::unique_ptr<IWorkload> CreateStack(const StackQueueDescriptor& descriptor, |
| 207 | const WorkloadInfo& info) const override; |
| 208 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 209 | private: |
| 210 | |
| 211 | template <typename F32Workload, typename U8Workload, typename QueueDescriptorType> |
| 212 | std::unique_ptr<IWorkload> MakeWorkload(const QueueDescriptorType& descriptor, const WorkloadInfo& info) const; |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 213 | |
| 214 | mutable std::shared_ptr<RefMemoryManager> m_MemoryManager; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | } // namespace armnn |