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 | // |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 5 | #include <Layer.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 6 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 7 | #include <backendsCommon/MemCopyWorkload.hpp> |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 8 | #include <backendsCommon/MemImportWorkload.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | #include <backendsCommon/MakeWorkloadHelper.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include "RefWorkloadFactory.hpp" |
David Beck | 79141b9 | 2018-10-23 16:09:36 +0100 | [diff] [blame] | 11 | #include "RefBackendId.hpp" |
David Beck | b4540be | 2018-09-24 13:18:27 +0100 | [diff] [blame] | 12 | #include "workloads/RefWorkloads.hpp" |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 13 | #include "RefTensorHandle.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | namespace armnn |
| 17 | { |
| 18 | |
David Beck | 79141b9 | 2018-10-23 16:09:36 +0100 | [diff] [blame] | 19 | namespace |
| 20 | { |
| 21 | static const BackendId s_Id{RefBackendId()}; |
| 22 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 23 | template <typename F32Workload, typename U8Workload, typename QueueDescriptorType> |
| 24 | std::unique_ptr<IWorkload> RefWorkloadFactory::MakeWorkload(const QueueDescriptorType& descriptor, |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 25 | const WorkloadInfo& info) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 26 | { |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 27 | return MakeWorkloadHelper<NullWorkload, F32Workload, U8Workload, NullWorkload, NullWorkload, NullWorkload> |
| 28 | (descriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 31 | template <DataType ArmnnType> |
| 32 | bool IsDataType(const WorkloadInfo& info) |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 33 | { |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 34 | auto checkType = [](const TensorInfo& tensorInfo) {return tensorInfo.GetDataType() == ArmnnType;}; |
| 35 | auto it = std::find_if(std::begin(info.m_InputTensorInfos), std::end(info.m_InputTensorInfos), checkType); |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 36 | if (it != std::end(info.m_InputTensorInfos)) |
| 37 | { |
| 38 | return true; |
| 39 | } |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 40 | it = std::find_if(std::begin(info.m_OutputTensorInfos), std::end(info.m_OutputTensorInfos), checkType); |
Jim Flynn | 82fbe7c | 2019-04-02 15:19:08 +0100 | [diff] [blame] | 41 | if (it != std::end(info.m_OutputTensorInfos)) |
| 42 | { |
| 43 | return true; |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 48 | bool IsSigned32(const WorkloadInfo& info) |
| 49 | { |
| 50 | return IsDataType<DataType::Signed32>(info); |
| 51 | } |
| 52 | |
Ferran Balaguer | d73d14f | 2019-06-10 10:29:54 +0100 | [diff] [blame] | 53 | bool IsFloat16(const WorkloadInfo& info) |
| 54 | { |
| 55 | return IsDataType<DataType::Float16>(info); |
| 56 | } |
| 57 | |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 58 | bool IsQSymmS16(const WorkloadInfo& info) |
nikraj01 | 99a6631 | 2019-06-06 10:31:27 +0100 | [diff] [blame] | 59 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 60 | return IsDataType<DataType::QSymmS16>(info); |
nikraj01 | 99a6631 | 2019-06-06 10:31:27 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 63 | bool IsQSymmS8(const WorkloadInfo& info) |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 64 | { |
| 65 | return IsDataType<DataType::QSymmS8>(info); |
| 66 | } |
| 67 | |
Keith Davis | 67e6c54 | 2020-02-19 10:08:33 +0000 | [diff] [blame] | 68 | bool IsQAsymmS8(const WorkloadInfo& info) |
| 69 | { |
| 70 | return IsDataType<DataType::QAsymmS8>(info); |
| 71 | } |
| 72 | |
| 73 | bool IsQAsymmU8(const WorkloadInfo& info) |
| 74 | { |
| 75 | return IsDataType<DataType::QAsymmU8>(info); |
| 76 | } |
| 77 | |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 78 | RefWorkloadFactory::RefWorkloadFactory(const std::shared_ptr<RefMemoryManager>& memoryManager) |
| 79 | : m_MemoryManager(memoryManager) |
| 80 | { |
| 81 | } |
| 82 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 83 | RefWorkloadFactory::RefWorkloadFactory() |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 84 | : m_MemoryManager(new RefMemoryManager()) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 85 | { |
| 86 | } |
| 87 | |
David Beck | 79141b9 | 2018-10-23 16:09:36 +0100 | [diff] [blame] | 88 | const BackendId& RefWorkloadFactory::GetBackendId() const |
| 89 | { |
| 90 | return s_Id; |
| 91 | } |
| 92 | |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 93 | bool RefWorkloadFactory::IsLayerSupported(const Layer& layer, |
| 94 | Optional<DataType> dataType, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 95 | std::string& outReasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 96 | { |
David Beck | 79141b9 | 2018-10-23 16:09:36 +0100 | [diff] [blame] | 97 | return IWorkloadFactory::IsLayerSupported(s_Id, layer, dataType, outReasonIfUnsupported); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 98 | } |
| 99 | |
David Monahan | 3fb7e10 | 2019-08-20 11:25:29 +0100 | [diff] [blame] | 100 | std::unique_ptr<ITensorHandle> RefWorkloadFactory::CreateTensorHandle(const TensorInfo& tensorInfo, |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 101 | const bool isMemoryManaged) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 102 | { |
David Monahan | 3fb7e10 | 2019-08-20 11:25:29 +0100 | [diff] [blame] | 103 | // For Ref it is okay to make the TensorHandle memory managed as it can also store a pointer |
| 104 | // to unmanaged memory. This also ensures memory alignment. |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 105 | boost::ignore_unused(isMemoryManaged); |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 106 | return std::make_unique<RefTensorHandle>(tensorInfo, m_MemoryManager); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Francis Murtagh | 351d13d | 2018-09-24 15:01:18 +0100 | [diff] [blame] | 109 | std::unique_ptr<ITensorHandle> RefWorkloadFactory::CreateTensorHandle(const TensorInfo& tensorInfo, |
David Monahan | 3fb7e10 | 2019-08-20 11:25:29 +0100 | [diff] [blame] | 110 | DataLayout dataLayout, |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 111 | const bool isMemoryManaged) const |
Francis Murtagh | 351d13d | 2018-09-24 15:01:18 +0100 | [diff] [blame] | 112 | { |
David Monahan | 3fb7e10 | 2019-08-20 11:25:29 +0100 | [diff] [blame] | 113 | // For Ref it is okay to make the TensorHandle memory managed as it can also store a pointer |
| 114 | // to unmanaged memory. This also ensures memory alignment. |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 115 | boost::ignore_unused(isMemoryManaged, dataLayout); |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 116 | return std::make_unique<RefTensorHandle>(tensorInfo, m_MemoryManager); |
Francis Murtagh | 351d13d | 2018-09-24 15:01:18 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 119 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateAbs(const AbsQueueDescriptor& descriptor, |
| 120 | const WorkloadInfo& info) const |
| 121 | { |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 122 | boost::ignore_unused(descriptor); |
| 123 | ElementwiseUnaryQueueDescriptor elementwiseUnaryDescriptor; |
| 124 | elementwiseUnaryDescriptor.m_Parameters.m_Operation = UnaryOperation::Abs; |
| 125 | |
| 126 | return CreateElementwiseUnary(elementwiseUnaryDescriptor, info); |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateActivation(const ActivationQueueDescriptor& descriptor, |
| 130 | const WorkloadInfo& info) const |
| 131 | { |
| 132 | return std::make_unique<RefActivationWorkload>(descriptor, info); |
| 133 | } |
| 134 | |
| 135 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateAddition(const AdditionQueueDescriptor& descriptor, |
| 136 | const WorkloadInfo& info) const |
| 137 | { |
| 138 | return std::make_unique<RefAdditionWorkload>(descriptor, info); |
| 139 | } |
| 140 | |
| 141 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateArgMinMax(const ArgMinMaxQueueDescriptor& descriptor, |
| 142 | const WorkloadInfo& info) const |
| 143 | { |
| 144 | return std::make_unique<RefArgMinMaxWorkload>(descriptor, info); |
| 145 | } |
| 146 | |
| 147 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateBatchNormalization( |
| 148 | const BatchNormalizationQueueDescriptor& descriptor, |
| 149 | const WorkloadInfo& info) const |
| 150 | { |
| 151 | return std::make_unique<RefBatchNormalizationWorkload>(descriptor, info); |
| 152 | } |
| 153 | |
| 154 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateBatchToSpaceNd(const BatchToSpaceNdQueueDescriptor& descriptor, |
| 155 | const WorkloadInfo& info) const |
| 156 | { |
| 157 | return std::make_unique<RefBatchToSpaceNdWorkload>(descriptor, info); |
| 158 | } |
| 159 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 160 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateComparison(const ComparisonQueueDescriptor& descriptor, |
| 161 | const WorkloadInfo& info) const |
| 162 | { |
| 163 | return std::make_unique<RefComparisonWorkload>(descriptor, info); |
| 164 | } |
| 165 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 166 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateConcat(const ConcatQueueDescriptor& descriptor, |
| 167 | const WorkloadInfo& info) const |
| 168 | { |
| 169 | return std::make_unique<RefConcatWorkload>(descriptor, info); |
| 170 | } |
| 171 | |
| 172 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateConstant(const ConstantQueueDescriptor& descriptor, |
| 173 | const WorkloadInfo& info) const |
| 174 | { |
| 175 | return std::make_unique<RefConstantWorkload>(descriptor, info); |
| 176 | } |
| 177 | |
| 178 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateConvertFp16ToFp32( |
| 179 | const ConvertFp16ToFp32QueueDescriptor& descriptor, |
| 180 | const WorkloadInfo& info) const |
| 181 | { |
| 182 | return std::make_unique<RefConvertFp16ToFp32Workload>(descriptor, info); |
| 183 | } |
| 184 | |
| 185 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateConvertFp32ToFp16( |
| 186 | const ConvertFp32ToFp16QueueDescriptor& descriptor, |
| 187 | const WorkloadInfo& info) const |
| 188 | { |
| 189 | return std::make_unique<RefConvertFp32ToFp16Workload>(descriptor, info); |
| 190 | } |
| 191 | |
| 192 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateConvolution2d(const Convolution2dQueueDescriptor& descriptor, |
| 193 | const WorkloadInfo& info) const |
| 194 | { |
| 195 | return std::make_unique<RefConvolution2dWorkload>(descriptor, info); |
| 196 | } |
| 197 | |
| 198 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateDebug(const DebugQueueDescriptor& descriptor, |
| 199 | const WorkloadInfo& info) const |
| 200 | { |
Aron Virginas-Tar | db1a283 | 2019-11-12 16:15:11 +0000 | [diff] [blame] | 201 | if (IsFloat16(info)) |
| 202 | { |
| 203 | return std::make_unique<RefDebugFloat16Workload>(descriptor, info); |
| 204 | } |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 205 | if (IsQSymmS16(info)) |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 206 | { |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 207 | return std::make_unique<RefDebugQSymmS16Workload>(descriptor, info); |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 208 | } |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 209 | if (IsQSymmS8(info)) |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 210 | { |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 211 | return std::make_unique<RefDebugQSymmS8Workload>(descriptor, info); |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 212 | } |
Keith Davis | 67e6c54 | 2020-02-19 10:08:33 +0000 | [diff] [blame] | 213 | if (IsQAsymmU8(info)) |
| 214 | { |
| 215 | return std::make_unique<RefDebugQAsymmU8Workload>(descriptor, info); |
| 216 | } |
| 217 | if (IsQAsymmS8(info)) |
| 218 | { |
| 219 | return std::make_unique<RefDebugQAsymmS8Workload>(descriptor, info); |
| 220 | } |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 221 | if (IsSigned32(info)) |
Narumol Prangnawarat | d2d917d | 2020-01-09 10:16:39 +0000 | [diff] [blame] | 222 | { |
| 223 | return std::make_unique<RefDebugSigned32Workload>(descriptor, info); |
| 224 | } |
Aron Virginas-Tar | db1a283 | 2019-11-12 16:15:11 +0000 | [diff] [blame] | 225 | |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 226 | return MakeWorkload<RefDebugFloat32Workload, RefDebugQAsymmU8Workload>(descriptor, info); |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateDepthToSpace(const DepthToSpaceQueueDescriptor& descriptor, |
| 230 | const WorkloadInfo& info) const |
| 231 | { |
| 232 | return std::make_unique<RefDepthToSpaceWorkload>(descriptor, info); |
| 233 | } |
| 234 | |
| 235 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateDepthwiseConvolution2d( |
| 236 | const DepthwiseConvolution2dQueueDescriptor& descriptor, |
| 237 | const WorkloadInfo& info) const |
| 238 | { |
| 239 | return std::make_unique<RefDepthwiseConvolution2dWorkload>(descriptor, info); |
| 240 | } |
| 241 | |
| 242 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateDequantize(const DequantizeQueueDescriptor& descriptor, |
| 243 | const WorkloadInfo& info) const |
| 244 | { |
| 245 | return std::make_unique<RefDequantizeWorkload>(descriptor, info); |
| 246 | } |
| 247 | |
| 248 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateDetectionPostProcess( |
| 249 | const DetectionPostProcessQueueDescriptor& descriptor, |
| 250 | const WorkloadInfo& info) const |
| 251 | { |
| 252 | return std::make_unique<RefDetectionPostProcessWorkload>(descriptor, info); |
| 253 | } |
| 254 | |
| 255 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateDivision(const DivisionQueueDescriptor& descriptor, |
| 256 | const WorkloadInfo& info) const |
| 257 | { |
| 258 | return std::make_unique<RefDivisionWorkload>(descriptor, info); |
| 259 | } |
| 260 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 261 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateElementwiseUnary(const ElementwiseUnaryQueueDescriptor& descriptor, |
| 262 | const WorkloadInfo& info) const |
| 263 | { |
| 264 | return std::make_unique<RefElementwiseUnaryWorkload>(descriptor, info); |
| 265 | } |
| 266 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 267 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateEqual(const EqualQueueDescriptor& descriptor, |
| 268 | const WorkloadInfo& info) const |
| 269 | { |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 270 | boost::ignore_unused(descriptor); |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 271 | ComparisonQueueDescriptor comparisonDescriptor; |
| 272 | comparisonDescriptor.m_Parameters.m_Operation = ComparisonOperation::Equal; |
| 273 | |
| 274 | return CreateComparison(comparisonDescriptor, info); |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateFakeQuantization( |
| 278 | const FakeQuantizationQueueDescriptor& descriptor, |
| 279 | const WorkloadInfo& info) const |
| 280 | { |
| 281 | return MakeWorkload<RefFakeQuantizationFloat32Workload, NullWorkload>(descriptor, info); |
| 282 | } |
| 283 | |
| 284 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateFloor(const FloorQueueDescriptor& descriptor, |
| 285 | const WorkloadInfo& info) const |
| 286 | { |
| 287 | return std::make_unique<RefFloorWorkload>(descriptor, info); |
| 288 | } |
| 289 | |
| 290 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateFullyConnected( |
| 291 | const FullyConnectedQueueDescriptor& descriptor, |
| 292 | const WorkloadInfo& info) const |
| 293 | { |
| 294 | return std::make_unique<RefFullyConnectedWorkload>(descriptor, info); |
| 295 | } |
| 296 | |
| 297 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateGather(const GatherQueueDescriptor& descriptor, |
| 298 | const WorkloadInfo& info) const |
| 299 | { |
| 300 | return std::make_unique<RefGatherWorkload>(descriptor, info); |
| 301 | } |
| 302 | |
| 303 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateGreater(const GreaterQueueDescriptor& descriptor, |
| 304 | const WorkloadInfo& info) const |
| 305 | { |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 306 | boost::ignore_unused(descriptor); |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 307 | ComparisonQueueDescriptor comparisonDescriptor; |
| 308 | comparisonDescriptor.m_Parameters.m_Operation = ComparisonOperation::Greater; |
| 309 | |
| 310 | return CreateComparison(comparisonDescriptor, info); |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 311 | } |
| 312 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 313 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateInput(const InputQueueDescriptor& descriptor, |
| 314 | const WorkloadInfo& info) const |
| 315 | { |
| 316 | if (info.m_InputTensorInfos.empty() ) |
| 317 | { |
| 318 | throw InvalidArgumentException("RefWorkloadFactory::CreateInput: Input cannot be zero length"); |
| 319 | } |
| 320 | if (info.m_OutputTensorInfos.empty()) |
| 321 | { |
| 322 | throw InvalidArgumentException("RefWorkloadFactory::CreateInput: Output cannot be zero length"); |
| 323 | } |
| 324 | |
| 325 | if (info.m_InputTensorInfos[0].GetNumBytes() != info.m_OutputTensorInfos[0].GetNumBytes()) |
| 326 | { |
| 327 | throw InvalidArgumentException("RefWorkloadFactory::CreateInput: data input and output differ in byte count."); |
| 328 | } |
| 329 | |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame] | 330 | return std::make_unique<CopyMemGenericWorkload>(descriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 333 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateInstanceNormalization( |
| 334 | const InstanceNormalizationQueueDescriptor& descriptor, |
| 335 | const WorkloadInfo& info) const |
| 336 | { |
| 337 | return std::make_unique<RefInstanceNormalizationWorkload>(descriptor, info); |
| 338 | } |
| 339 | |
| 340 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateL2Normalization(const L2NormalizationQueueDescriptor& descriptor, |
| 341 | const WorkloadInfo& info) const |
| 342 | { |
| 343 | return std::make_unique<RefL2NormalizationWorkload>(descriptor, info); |
| 344 | } |
| 345 | |
| 346 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateLogSoftmax(const LogSoftmaxQueueDescriptor& descriptor, |
| 347 | const WorkloadInfo& info) const |
| 348 | { |
| 349 | return std::make_unique<RefLogSoftmaxWorkload>(descriptor, info); |
| 350 | } |
| 351 | |
| 352 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateLstm(const LstmQueueDescriptor& descriptor, |
| 353 | const WorkloadInfo& info) const |
| 354 | { |
| 355 | return std::make_unique<RefLstmWorkload>(descriptor, info); |
| 356 | } |
| 357 | |
| 358 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateMaximum(const MaximumQueueDescriptor& descriptor, |
| 359 | const WorkloadInfo& info) const |
| 360 | { |
| 361 | return std::make_unique<RefMaximumWorkload>(descriptor, info); |
| 362 | } |
| 363 | |
| 364 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateMean(const MeanQueueDescriptor& descriptor, |
| 365 | const WorkloadInfo& info) const |
| 366 | { |
| 367 | return std::make_unique<RefMeanWorkload>(descriptor, info); |
| 368 | } |
| 369 | |
| 370 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateMemCopy(const MemCopyQueueDescriptor& descriptor, |
| 371 | const WorkloadInfo& info) const |
| 372 | { |
| 373 | if (descriptor.m_Inputs.empty()) |
| 374 | { |
| 375 | throw InvalidArgumentException("RefWorkloadFactory: CreateMemCopy() expected an input tensor."); |
| 376 | } |
| 377 | return std::make_unique<CopyMemGenericWorkload>(descriptor, info); |
| 378 | } |
| 379 | |
| 380 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateMemImport(const MemImportQueueDescriptor& descriptor, |
| 381 | const WorkloadInfo& info) const |
| 382 | { |
| 383 | if (descriptor.m_Inputs.empty()) |
| 384 | { |
| 385 | throw InvalidArgumentException("RefWorkloadFactory: CreateMemImport() expected an input tensor."); |
| 386 | } |
| 387 | return std::make_unique<ImportMemGenericWorkload>(descriptor, info); |
| 388 | } |
| 389 | |
| 390 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateMerger(const MergerQueueDescriptor& descriptor, |
| 391 | const WorkloadInfo& info) const |
| 392 | { |
| 393 | return CreateConcat(descriptor, info); |
| 394 | } |
| 395 | |
| 396 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateMinimum(const MinimumQueueDescriptor& descriptor, |
| 397 | const WorkloadInfo& info) const |
| 398 | { |
| 399 | return std::make_unique<RefMinimumWorkload>(descriptor, info); |
| 400 | } |
| 401 | |
| 402 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateMultiplication(const MultiplicationQueueDescriptor& descriptor, |
| 403 | const WorkloadInfo& info) const |
| 404 | { |
| 405 | return std::make_unique<RefMultiplicationWorkload>(descriptor, info); |
| 406 | } |
| 407 | |
| 408 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateNormalization(const NormalizationQueueDescriptor& descriptor, |
| 409 | const WorkloadInfo& info) const |
| 410 | { |
| 411 | return std::make_unique<RefNormalizationWorkload>(descriptor, info); |
| 412 | } |
| 413 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 414 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateOutput(const OutputQueueDescriptor& descriptor, |
| 415 | const WorkloadInfo& info) const |
| 416 | { |
| 417 | if (info.m_InputTensorInfos.empty() ) |
| 418 | { |
| 419 | throw InvalidArgumentException("RefWorkloadFactory::CreateOutput: Input cannot be zero length"); |
| 420 | } |
| 421 | if (info.m_OutputTensorInfos.empty()) |
| 422 | { |
| 423 | throw InvalidArgumentException("RefWorkloadFactory::CreateOutput: Output cannot be zero length"); |
| 424 | } |
| 425 | if (info.m_InputTensorInfos[0].GetNumBytes() != info.m_OutputTensorInfos[0].GetNumBytes()) |
| 426 | { |
| 427 | throw InvalidArgumentException("RefWorkloadFactory::CreateOutput: data input and output differ in byte count."); |
| 428 | } |
| 429 | |
Narumol Prangnawarat | b6441e4 | 2019-06-04 11:22:00 +0100 | [diff] [blame] | 430 | return std::make_unique<CopyMemGenericWorkload>(descriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 433 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreatePad(const PadQueueDescriptor& descriptor, |
| 434 | const WorkloadInfo& info) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 435 | { |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 436 | if (IsQSymmS16(info)) |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 437 | { |
| 438 | return std::make_unique<RefPadQSymm16Workload>(descriptor, info); |
| 439 | } |
| 440 | else if (IsFloat16(info)) |
| 441 | { |
| 442 | return std::make_unique<RefPadFloat16Workload>(descriptor, info); |
| 443 | } |
| 444 | return MakeWorkload<RefPadFloat32Workload, RefPadQAsymm8Workload>(descriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 447 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreatePermute(const PermuteQueueDescriptor& descriptor, |
| 448 | const WorkloadInfo& info) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 449 | { |
Keith Davis | 0c2eeac | 2020-02-11 16:51:50 +0000 | [diff] [blame] | 450 | if (IsQSymmS16(info)) |
Narumol Prangnawarat | 86bb4e1 | 2019-07-08 11:36:05 +0100 | [diff] [blame] | 451 | { |
| 452 | return std::make_unique<RefPermuteQSymm16Workload>(descriptor, info); |
| 453 | } |
| 454 | return MakeWorkloadHelper<RefPermuteFloat16Workload, RefPermuteFloat32Workload, RefPermuteQAsymm8Workload, |
Keith Davis | 5204aa8 | 2020-01-27 15:24:59 +0000 | [diff] [blame] | 455 | NullWorkload, NullWorkload, NullWorkload>(descriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 458 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreatePooling2d(const Pooling2dQueueDescriptor& descriptor, |
| 459 | const WorkloadInfo& info) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 460 | { |
Teresa Charlin | a3b2047 | 2019-06-06 11:12:32 +0100 | [diff] [blame] | 461 | return std::make_unique<RefPooling2dWorkload>(descriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 464 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreatePreCompiled(const PreCompiledQueueDescriptor& /*descriptor*/, |
| 465 | const WorkloadInfo& /*info*/) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 466 | { |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 467 | return nullptr; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 470 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreatePrelu(const PreluQueueDescriptor& descriptor, |
| 471 | const WorkloadInfo& info) const |
Aron Virginas-Tar | 73f6642 | 2019-09-23 19:11:59 +0100 | [diff] [blame] | 472 | { |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 473 | return std::make_unique<RefPreluWorkload>(descriptor, info); |
Aron Virginas-Tar | 73f6642 | 2019-09-23 19:11:59 +0100 | [diff] [blame] | 474 | } |
| 475 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 476 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateQuantize(const QuantizeQueueDescriptor& descriptor, |
| 477 | const WorkloadInfo& info) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 478 | { |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 479 | return std::make_unique<RefQuantizeWorkload>(descriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 482 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateReshape(const ReshapeQueueDescriptor& descriptor, |
| 483 | const WorkloadInfo& info) const |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 484 | { |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 485 | return std::make_unique<RefReshapeWorkload>(descriptor, info); |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 488 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateResize(const ResizeQueueDescriptor& descriptor, |
| 489 | const WorkloadInfo& info) const |
| 490 | { |
Teresa Charlin | 970f43b | 2019-07-01 13:51:07 +0100 | [diff] [blame] | 491 | return std::make_unique<RefResizeWorkload>(descriptor, info); |
| 492 | } |
| 493 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 494 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateResizeBilinear(const ResizeBilinearQueueDescriptor& descriptor, |
| 495 | const WorkloadInfo& info) const |
| 496 | { |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 497 | ResizeQueueDescriptor resizeDescriptor; |
| 498 | resizeDescriptor.m_Parameters.m_Method = ResizeMethod::Bilinear; |
| 499 | resizeDescriptor.m_Parameters.m_DataLayout = descriptor.m_Parameters.m_DataLayout; |
| 500 | resizeDescriptor.m_Parameters.m_TargetWidth = descriptor.m_Parameters.m_TargetWidth; |
| 501 | resizeDescriptor.m_Parameters.m_TargetHeight = descriptor.m_Parameters.m_TargetHeight; |
| 502 | |
| 503 | return CreateResize(resizeDescriptor, info); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 506 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateRsqrt(const RsqrtQueueDescriptor& descriptor, |
| 507 | const WorkloadInfo& info) const |
| 508 | { |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 509 | boost::ignore_unused(descriptor); |
| 510 | ElementwiseUnaryQueueDescriptor elementwiseUnaryDescriptor; |
| 511 | elementwiseUnaryDescriptor.m_Parameters.m_Operation = UnaryOperation::Rsqrt; |
| 512 | |
| 513 | return CreateElementwiseUnary(elementwiseUnaryDescriptor, info); |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Aron Virginas-Tar | 92b9f87 | 2019-09-17 17:27:04 +0100 | [diff] [blame] | 516 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateSlice(const SliceQueueDescriptor& descriptor, |
| 517 | const WorkloadInfo& info) const |
| 518 | { |
| 519 | return std::make_unique<RefSliceWorkload>(descriptor, info); |
| 520 | } |
| 521 | |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 522 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateSoftmax(const SoftmaxQueueDescriptor& descriptor, |
| 523 | const WorkloadInfo& info) const |
Kevin May | 09ca49c | 2019-10-09 12:37:34 +0100 | [diff] [blame] | 524 | { |
Aron Virginas-Tar | e662a94 | 2019-10-14 15:12:00 +0100 | [diff] [blame] | 525 | return std::make_unique<RefSoftmaxWorkload>(descriptor, info); |
| 526 | } |
| 527 | |
| 528 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateSpaceToBatchNd(const SpaceToBatchNdQueueDescriptor& descriptor, |
| 529 | const WorkloadInfo& info) const |
| 530 | { |
| 531 | return std::make_unique<RefSpaceToBatchNdWorkload>(descriptor, info); |
| 532 | } |
| 533 | |
| 534 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateSpaceToDepth(const SpaceToDepthQueueDescriptor& descriptor, |
| 535 | const WorkloadInfo& info) const |
| 536 | { |
| 537 | return std::make_unique<RefSpaceToDepthWorkload>(descriptor, info); |
| 538 | } |
| 539 | |
| 540 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateSplitter(const SplitterQueueDescriptor& descriptor, |
| 541 | const WorkloadInfo& info) const |
| 542 | { |
| 543 | return std::make_unique<RefSplitterWorkload>(descriptor, info); |
| 544 | } |
| 545 | |
| 546 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateStack(const StackQueueDescriptor& descriptor, |
| 547 | const WorkloadInfo& info) const |
| 548 | { |
| 549 | return std::make_unique<RefStackWorkload>(descriptor, info); |
| 550 | } |
| 551 | |
| 552 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateStridedSlice(const StridedSliceQueueDescriptor& descriptor, |
| 553 | const WorkloadInfo& info) const |
| 554 | { |
| 555 | return std::make_unique<RefStridedSliceWorkload>(descriptor, info); |
| 556 | } |
| 557 | |
| 558 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateSubtraction(const SubtractionQueueDescriptor& descriptor, |
| 559 | const WorkloadInfo& info) const |
| 560 | { |
| 561 | return std::make_unique<RefSubtractionWorkload>(descriptor, info); |
| 562 | } |
| 563 | |
| 564 | std::unique_ptr<IWorkload> RefWorkloadFactory::CreateTransposeConvolution2d( |
| 565 | const TransposeConvolution2dQueueDescriptor& descriptor, |
| 566 | const WorkloadInfo& info) const |
| 567 | { |
| 568 | return std::make_unique<RefTransposeConvolution2dWorkload>(descriptor, info); |
Kevin May | 09ca49c | 2019-10-09 12:37:34 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 571 | } // namespace armnn |