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