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 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 6 | #include "ClLayerSupport.hpp" |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 7 | #include "ClBackendId.hpp" |
arovir01 | 7c22c70 | 2018-10-09 11:16:46 +0100 | [diff] [blame] | 8 | |
David Beck | 3cc9a62 | 2018-10-12 10:38:31 +0100 | [diff] [blame] | 9 | #include <armnn/Descriptors.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <InternalTypes.hpp> |
| 11 | #include <LayerSupportCommon.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
David Beck | 111b5d9 | 2018-11-12 14:59:37 +0000 | [diff] [blame] | 13 | #include <backendsCommon/BackendRegistry.hpp> |
David Beck | 3e9e115 | 2018-10-17 14:17:50 +0100 | [diff] [blame] | 14 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | #include <boost/core/ignore_unused.hpp> |
| 16 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 17 | #if defined(ARMCOMPUTECL_ENABLED) |
Narumol Prangnawarat | 7413583 | 2019-05-23 15:07:33 +0100 | [diff] [blame] | 18 | #include <aclCommon/ArmComputeUtils.hpp> |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 19 | #include "workloads/ClAdditionWorkload.hpp" |
Nattapat Chaimanowong | e06757e | 2018-10-11 15:39:18 +0100 | [diff] [blame] | 20 | #include "workloads/ClActivationWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 21 | #include "workloads/ClBatchNormalizationFloatWorkload.hpp" |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 22 | #include "workloads/ClBatchToSpaceNdWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 23 | #include "workloads/ClConvertFp16ToFp32Workload.hpp" |
| 24 | #include "workloads/ClConvertFp32ToFp16Workload.hpp" |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 25 | #include "workloads/ClConvolution2dWorkload.hpp" |
Matthew Bentham | d877739 | 2018-10-08 09:38:55 +0100 | [diff] [blame] | 26 | #include "workloads/ClDepthwiseConvolutionWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 27 | #include "workloads/ClDivisionFloatWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 28 | #include "workloads/ClFullyConnectedWorkload.hpp" |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 29 | #include "workloads/ClGreaterWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 30 | #include "workloads/ClL2NormalizationFloatWorkload.hpp" |
| 31 | #include "workloads/ClLstmFloatWorkload.hpp" |
keidav01 | a959ee5 | 2018-12-19 10:04:58 +0000 | [diff] [blame] | 32 | #include "workloads/ClMaximumWorkload.hpp" |
Matteo Martincigh | 28dcab6 | 2018-10-19 16:40:03 +0100 | [diff] [blame] | 33 | #include "workloads/ClMeanWorkload.hpp" |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 34 | #include "workloads/ClConcatWorkload.hpp" |
saoste01 | 9292aa3 | 2019-01-08 13:55:59 +0000 | [diff] [blame] | 35 | #include "workloads/ClMinimumWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 36 | #include "workloads/ClMultiplicationWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 37 | #include "workloads/ClNormalizationFloatWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 38 | #include "workloads/ClPadWorkload.hpp" |
| 39 | #include "workloads/ClPermuteWorkload.hpp" |
Nattapat Chaimanowong | ac9e096 | 2018-10-10 17:18:35 +0100 | [diff] [blame] | 40 | #include "workloads/ClPooling2dWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 41 | #include "workloads/ClSoftmaxBaseWorkload.hpp" |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 42 | #include "workloads/ClSpaceToBatchNdWorkload.hpp" |
Narumol Prangnawarat | 7413583 | 2019-05-23 15:07:33 +0100 | [diff] [blame] | 43 | #include "workloads/ClSplitterWorkload.hpp" |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 44 | #include "workloads/ClStridedSliceWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 45 | #include "workloads/ClSubtractionWorkload.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | using namespace boost; |
| 49 | |
| 50 | namespace armnn |
| 51 | { |
arovir01 | 7c22c70 | 2018-10-09 11:16:46 +0100 | [diff] [blame] | 52 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | namespace |
| 54 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 55 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 56 | template<unsigned int FilterSize> |
| 57 | bool IsMatchingSize2d(const TensorInfo& weightInfo) |
| 58 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 59 | // Width & Height must match. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 60 | return (weightInfo.GetShape()[3] == FilterSize) && (weightInfo.GetShape()[2] == FilterSize); |
| 61 | } |
| 62 | |
| 63 | template<uint32_t ValidStride> |
| 64 | bool IsMatchingStride(uint32_t actualStride) |
| 65 | { |
| 66 | return ValidStride == actualStride; |
| 67 | } |
| 68 | |
| 69 | template<uint32_t FirstStride, uint32_t SecondStride, uint32_t... ValidStrides> |
| 70 | bool IsMatchingStride(uint32_t actualStride) |
| 71 | { |
| 72 | return IsMatchingStride<FirstStride>(actualStride) || IsMatchingStride<SecondStride, ValidStrides...>(actualStride); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 73 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 74 | |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 75 | bool IsClBackendSupported(Optional<std::string&> reasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 76 | { |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 77 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 78 | return true; |
| 79 | #else |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 80 | if (reasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 81 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 82 | reasonIfUnsupported.value() = "The armnn library has been built without CL support"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 83 | } |
| 84 | return false; |
| 85 | #endif |
| 86 | } |
| 87 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 88 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 89 | #define FORWARD_CL_LAYER_SUPPORT_FUNC(expr) (expr) |
| 90 | #else |
| 91 | #define FORWARD_CL_LAYER_SUPPORT_FUNC(expr) IsClBackendSupported(reasonIfUnsupported) |
| 92 | #endif |
| 93 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 94 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 95 | template<class FuncType, class... Args> |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 96 | inline bool IsWorkloadSupported(FuncType&& func, Optional<std::string&> reasonIfUnsupported, Args&&... args) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 97 | { |
| 98 | arm_compute::Status aclStatus = func(std::forward<Args>(args)...); |
| 99 | const bool supported = (aclStatus.error_code() == arm_compute::ErrorCode::OK); |
| 100 | if (!supported && reasonIfUnsupported) |
| 101 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 102 | reasonIfUnsupported.value() = aclStatus.error_description(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 103 | } |
| 104 | return supported; |
| 105 | } |
| 106 | |
| 107 | #define FORWARD_WORKLOAD_VALIDATE_FUNC(func, reasonIfUnsupported, ...) \ |
| 108 | return IsWorkloadSupported(func, reasonIfUnsupported, __VA_ARGS__); |
| 109 | #else |
| 110 | #define FORWARD_WORKLOAD_VALIDATE_FUNC(func, reasonIfUnsupported, ...) \ |
| 111 | return IsClBackendSupported(reasonIfUnsupported); |
| 112 | #endif |
| 113 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 114 | template<typename FloatFunc, typename Uint8Func, typename ... Params> |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 115 | bool IsSupportedForDataTypeCl(Optional<std::string&> reasonIfUnsupported, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 116 | DataType dataType, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 117 | FloatFunc floatFuncPtr, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 118 | Uint8Func uint8FuncPtr, |
| 119 | Params&&... params) |
| 120 | { |
| 121 | return IsClBackendSupported(reasonIfUnsupported) && |
| 122 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 123 | dataType, |
| 124 | floatFuncPtr, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 125 | floatFuncPtr, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 126 | uint8FuncPtr, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 127 | &FalseFunc<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 128 | &FalseFunc<>, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 129 | std::forward<Params>(params)...); |
| 130 | } |
| 131 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 132 | } // anonymous namespace |
| 133 | |
| 134 | bool ClLayerSupport::IsActivationSupported(const TensorInfo& input, |
| 135 | const TensorInfo& output, |
| 136 | const ActivationDescriptor& descriptor, |
| 137 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 138 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 139 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClActivationWorkloadValidate, |
| 140 | reasonIfUnsupported, |
| 141 | input, |
| 142 | output, |
| 143 | descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 146 | bool ClLayerSupport::IsAdditionSupported(const TensorInfo& input0, |
| 147 | const TensorInfo& input1, |
| 148 | const TensorInfo& output, |
| 149 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 150 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 151 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClAdditionValidate, |
| 152 | reasonIfUnsupported, |
| 153 | input0, |
| 154 | input1, |
| 155 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 158 | bool ClLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input, |
| 159 | const TensorInfo& output, |
| 160 | const TensorInfo& mean, |
| 161 | const TensorInfo& var, |
| 162 | const TensorInfo& beta, |
| 163 | const TensorInfo& gamma, |
| 164 | const BatchNormalizationDescriptor& descriptor, |
| 165 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 166 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 167 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClBatchNormalizationValidate, |
| 168 | reasonIfUnsupported, |
| 169 | input, |
| 170 | output, |
| 171 | mean, |
| 172 | var, |
| 173 | beta, |
| 174 | gamma, |
| 175 | descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 178 | bool ClLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input, |
| 179 | const TensorInfo& output, |
| 180 | const BatchToSpaceNdDescriptor& descriptor, |
| 181 | Optional<std::string&> reasonIfUnsupported) const |
| 182 | { |
| 183 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClBatchToSpaceNdWorkloadValidate, |
| 184 | reasonIfUnsupported, |
| 185 | input, |
| 186 | output, |
| 187 | descriptor); |
| 188 | } |
| 189 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 190 | bool ClLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs, |
| 191 | const TensorInfo& output, |
| 192 | const OriginsDescriptor& descriptor, |
| 193 | Optional<std::string&> reasonIfUnsupported) const |
| 194 | { |
| 195 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
| 196 | return IsMergerSupported(inputs, output, descriptor, reasonIfUnsupported); |
| 197 | ARMNN_NO_DEPRECATE_WARN_END |
| 198 | } |
| 199 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 200 | bool ClLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 201 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 202 | { |
| 203 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 204 | output.GetDataType(), |
| 205 | &TrueFunc<>, |
| 206 | &FalseFuncU8<>); |
| 207 | } |
| 208 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 209 | bool ClLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, |
| 210 | const TensorInfo& output, |
| 211 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 212 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 213 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp16ToFp32WorkloadValidate, |
| 214 | reasonIfUnsupported, |
| 215 | input, |
| 216 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 219 | bool ClLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 220 | const TensorInfo& output, |
| 221 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 222 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 223 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp32ToFp16WorkloadValidate, |
| 224 | reasonIfUnsupported, |
| 225 | input, |
| 226 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 227 | } |
| 228 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 229 | bool ClLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 230 | const TensorInfo& output, |
| 231 | const Convolution2dDescriptor& descriptor, |
| 232 | const TensorInfo& weights, |
| 233 | const Optional<TensorInfo>& biases, |
| 234 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 235 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 236 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvolution2dWorkloadValidate, |
| 237 | reasonIfUnsupported, |
| 238 | input, |
| 239 | output, |
| 240 | descriptor, |
| 241 | weights, |
| 242 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 245 | bool ClLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 246 | const TensorInfo& output, |
| 247 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 248 | const TensorInfo& weights, |
| 249 | const Optional<TensorInfo>& biases, |
| 250 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 251 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 252 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 253 | reasonIfUnsupported, |
| 254 | input, |
| 255 | output, |
| 256 | descriptor, |
| 257 | weights, |
| 258 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 261 | bool ClLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 262 | const TensorInfo& output, |
| 263 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 264 | const TensorInfo& weights, |
| 265 | const Optional<TensorInfo>& biases, |
| 266 | Optional<std::string&> reasonIfUnsupported) const |
| 267 | { |
| 268 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 269 | reasonIfUnsupported, |
| 270 | input, |
| 271 | output, |
| 272 | descriptor, |
| 273 | weights, |
| 274 | biases); |
| 275 | } |
| 276 | |
| 277 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 278 | bool ClLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
| 279 | const TensorInfo& input1, |
| 280 | const TensorInfo& output, |
| 281 | Optional<std::string&> reasonIfUnsupported) const |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 282 | { |
| 283 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDivisionWorkloadValidate, |
| 284 | reasonIfUnsupported, |
| 285 | input0, |
| 286 | input1, |
| 287 | output); |
| 288 | } |
| 289 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 290 | bool ClLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 291 | const TensorInfo& output, |
| 292 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 293 | { |
| 294 | ignore_unused(output); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 295 | return IsClBackendSupported(reasonIfUnsupported) && |
| 296 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 297 | input.GetDataType(), |
| 298 | &FalseFuncF16<>, |
| 299 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 300 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 301 | &FalseFuncI32<>, |
| 302 | &FalseFuncU8<>); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 305 | bool ClLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 306 | const TensorInfo& output, |
| 307 | const TensorInfo& weights, |
| 308 | const TensorInfo& biases, |
| 309 | const FullyConnectedDescriptor& descriptor, |
| 310 | Optional<std::string&> reasonIfUnsupported) const |
| 311 | { |
| 312 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClFullyConnectedWorkloadValidate, |
| 313 | reasonIfUnsupported, |
| 314 | input, |
| 315 | output, |
| 316 | weights, |
| 317 | biases, |
| 318 | descriptor); |
| 319 | } |
| 320 | |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 321 | bool ClLayerSupport::IsGreaterSupported(const TensorInfo& input0, |
| 322 | const TensorInfo& input1, |
| 323 | const TensorInfo& output, |
| 324 | Optional<std::string&> reasonIfUnsupported) const |
| 325 | { |
| 326 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClGreaterWorkloadValidate, |
| 327 | reasonIfUnsupported, |
| 328 | input0, |
| 329 | input1, |
| 330 | output); |
| 331 | } |
| 332 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 333 | bool ClLayerSupport::IsInputSupported(const TensorInfo& input, |
| 334 | Optional<std::string&> reasonIfUnsupported) const |
| 335 | { |
| 336 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 337 | input.GetDataType(), |
| 338 | &TrueFunc<>, |
| 339 | &TrueFunc<>); |
| 340 | } |
| 341 | |
| 342 | bool ClLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 343 | const TensorInfo& output, |
| 344 | const L2NormalizationDescriptor& descriptor, |
| 345 | Optional<std::string&> reasonIfUnsupported) const |
| 346 | { |
| 347 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClL2NormalizationWorkloadValidate, |
| 348 | reasonIfUnsupported, |
| 349 | input, |
| 350 | output, |
| 351 | descriptor); |
| 352 | } |
| 353 | |
| 354 | bool ClLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 355 | const TensorInfo& outputStateIn, |
| 356 | const TensorInfo& cellStateIn, |
| 357 | const TensorInfo& scratchBuffer, |
| 358 | const TensorInfo& outputStateOut, |
| 359 | const TensorInfo& cellStateOut, |
| 360 | const TensorInfo& output, |
| 361 | const LstmDescriptor& descriptor, |
| 362 | const TensorInfo& inputToForgetWeights, |
| 363 | const TensorInfo& inputToCellWeights, |
| 364 | const TensorInfo& inputToOutputWeights, |
| 365 | const TensorInfo& recurrentToForgetWeights, |
| 366 | const TensorInfo& recurrentToCellWeights, |
| 367 | const TensorInfo& recurrentToOutputWeights, |
| 368 | const TensorInfo& forgetGateBias, |
| 369 | const TensorInfo& cellBias, |
| 370 | const TensorInfo& outputGateBias, |
| 371 | const TensorInfo* inputToInputWeights, |
| 372 | const TensorInfo* recurrentToInputWeights, |
| 373 | const TensorInfo* cellToInputWeights, |
| 374 | const TensorInfo* inputGateBias, |
| 375 | const TensorInfo* projectionWeights, |
| 376 | const TensorInfo* projectionBias, |
| 377 | const TensorInfo* cellToForgetWeights, |
| 378 | const TensorInfo* cellToOutputWeights, |
| 379 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 380 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 381 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClLstmFloatWorkloadValidate, |
| 382 | reasonIfUnsupported, |
| 383 | input, |
| 384 | outputStateIn, |
| 385 | cellStateIn, |
| 386 | scratchBuffer, |
| 387 | outputStateOut, |
| 388 | cellStateOut, |
| 389 | output, |
| 390 | descriptor, |
| 391 | inputToForgetWeights, |
| 392 | inputToCellWeights, |
| 393 | inputToOutputWeights, |
| 394 | recurrentToForgetWeights, |
| 395 | recurrentToCellWeights, |
| 396 | recurrentToOutputWeights, |
| 397 | forgetGateBias, |
| 398 | cellBias, |
| 399 | outputGateBias, |
| 400 | inputToInputWeights, |
| 401 | recurrentToInputWeights, |
| 402 | cellToInputWeights, |
| 403 | inputGateBias, |
| 404 | projectionWeights, |
| 405 | projectionBias, |
| 406 | cellToForgetWeights, |
| 407 | cellToOutputWeights); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 408 | } |
| 409 | |
keidav01 | a959ee5 | 2018-12-19 10:04:58 +0000 | [diff] [blame] | 410 | bool ClLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 411 | const TensorInfo& input1, |
| 412 | const TensorInfo& output, |
| 413 | Optional<std::string&> reasonIfUnsupported) const |
| 414 | { |
| 415 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMaximumWorkloadValidate, |
| 416 | reasonIfUnsupported, |
| 417 | input0, |
| 418 | input1, |
| 419 | output); |
| 420 | } |
| 421 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 422 | bool ClLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 423 | const TensorInfo& output, |
| 424 | const MeanDescriptor& descriptor, |
| 425 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 426 | { |
Matteo Martincigh | 28dcab6 | 2018-10-19 16:40:03 +0100 | [diff] [blame] | 427 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMeanValidate, |
| 428 | reasonIfUnsupported, |
| 429 | input, |
| 430 | output, |
| 431 | descriptor); |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 434 | bool ClLayerSupport::IsMemCopySupported(const TensorInfo &input, |
| 435 | const TensorInfo &output, |
| 436 | Optional<std::string &> reasonIfUnsupported) const |
| 437 | { |
| 438 | ignore_unused(input); |
| 439 | ignore_unused(output); |
| 440 | return true; |
| 441 | } |
| 442 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 443 | bool ClLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 444 | const TensorInfo& output, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 445 | const OriginsDescriptor& descriptor, |
| 446 | Optional<std::string&> reasonIfUnsupported) const |
| 447 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 448 | if (descriptor.GetNumDimensions() <= descriptor.GetConcatAxis()) |
| 449 | { |
| 450 | SetValueChecked(reasonIfUnsupported, "Cl Merger: Concat axis > Number of dimensions."); |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | unsigned int concatInnerAxis = (descriptor.GetNumDimensions() - descriptor.GetConcatAxis()) - 1; |
| 455 | if(concatInnerAxis < 3) // Width, height, or channels |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 456 | { |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 457 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConcatWorkloadValidate, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 458 | reasonIfUnsupported, |
| 459 | inputs, |
| 460 | output, |
| 461 | descriptor); |
| 462 | } |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 463 | else if (concatInnerAxis == 3) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 464 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 465 | // We rely on the sub-tensor optimization to handle the batch dimension for 4D tensors. If we can't use |
| 466 | // sub-tensors for this then we can't support it. Here is where we check that the sub-tensors will work. |
| 467 | for (auto& input : inputs) |
| 468 | { |
| 469 | if (input && !output.IsTypeSpaceMatch(*input)) // Cannot use sub-tensors if the types are not same space |
| 470 | { |
| 471 | SetValueChecked(reasonIfUnsupported, "Cl Merger: Types and quantization parameters must match."); |
| 472 | return false; |
| 473 | } |
| 474 | } |
| 475 | return true; // Sub-tensors support concat along batch |
| 476 | } |
| 477 | else // > 4 dimensions not supported. |
| 478 | { |
| 479 | SetValueChecked(reasonIfUnsupported, "Cl Merger: Maximum of 4 dimensions supported."); |
| 480 | return false; |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 481 | } |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 482 | } |
| 483 | |
saoste01 | 9292aa3 | 2019-01-08 13:55:59 +0000 | [diff] [blame] | 484 | bool ClLayerSupport::IsMinimumSupported(const TensorInfo& input0, |
| 485 | const TensorInfo& input1, |
| 486 | const TensorInfo& output, |
| 487 | Optional<std::string&> reasonIfUnsupported) const |
| 488 | { |
| 489 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMinimumWorkloadValidate, |
| 490 | reasonIfUnsupported, |
| 491 | input0, |
| 492 | input1, |
| 493 | output); |
| 494 | } |
| 495 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 496 | bool ClLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, |
| 497 | const TensorInfo& input1, |
| 498 | const TensorInfo& output, |
| 499 | Optional<std::string&> reasonIfUnsupported) const |
| 500 | { |
| 501 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMultiplicationWorkloadValidate, |
| 502 | reasonIfUnsupported, |
| 503 | input0, |
| 504 | input1, |
| 505 | output); |
| 506 | } |
| 507 | |
| 508 | bool ClLayerSupport::IsNormalizationSupported(const TensorInfo& input, |
| 509 | const TensorInfo& output, |
| 510 | const NormalizationDescriptor& descriptor, |
| 511 | Optional<std::string&> reasonIfUnsupported) const |
| 512 | { |
| 513 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClNormalizationWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
| 514 | } |
| 515 | |
| 516 | bool ClLayerSupport::IsOutputSupported(const TensorInfo& output, |
| 517 | Optional<std::string&> reasonIfUnsupported) const |
| 518 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 519 | return IsClBackendSupported(reasonIfUnsupported) && |
| 520 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 521 | output.GetDataType(), |
| 522 | &TrueFunc<>, |
| 523 | &TrueFunc<>, |
| 524 | &TrueFunc<>, |
| 525 | &FalseFuncI32<>, |
| 526 | &TrueFunc<>); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | bool ClLayerSupport::IsPadSupported(const TensorInfo& input, |
| 530 | const TensorInfo& output, |
| 531 | const PadDescriptor& descriptor, |
| 532 | Optional<std::string&> reasonIfUnsupported) const |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 533 | { |
| 534 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPadValidate, |
| 535 | reasonIfUnsupported, |
| 536 | input, |
| 537 | output, |
| 538 | descriptor); |
| 539 | } |
| 540 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 541 | bool ClLayerSupport::IsPermuteSupported(const TensorInfo& input, |
| 542 | const TensorInfo& output, |
| 543 | const PermuteDescriptor& descriptor, |
| 544 | Optional<std::string&> reasonIfUnsupported) const |
| 545 | { |
| 546 | ignore_unused(input); |
| 547 | ignore_unused(output); |
| 548 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPermuteWorkloadValidate, reasonIfUnsupported, descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 549 | } |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 550 | |
| 551 | bool ClLayerSupport::IsPooling2dSupported(const TensorInfo& input, |
| 552 | const TensorInfo& output, |
| 553 | const Pooling2dDescriptor& descriptor, |
| 554 | Optional<std::string&> reasonIfUnsupported) const |
| 555 | { |
| 556 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPooling2dWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
| 557 | } |
| 558 | |
| 559 | bool ClLayerSupport::IsReshapeSupported(const TensorInfo& input, |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 560 | const ReshapeDescriptor& descriptor, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 561 | Optional<std::string&> reasonIfUnsupported) const |
| 562 | { |
| 563 | ignore_unused(input); |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 564 | ignore_unused(descriptor); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 565 | ignore_unused(reasonIfUnsupported); |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | bool ClLayerSupport::IsResizeBilinearSupported(const TensorInfo& input, |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 570 | const TensorInfo& output, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 571 | Optional<std::string&> reasonIfUnsupported) const |
| 572 | { |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 573 | ignore_unused(output); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 574 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 575 | input.GetDataType(), |
| 576 | &TrueFunc<>, |
| 577 | &FalseFuncU8<>); |
| 578 | } |
| 579 | |
| 580 | bool ClLayerSupport::IsSoftmaxSupported(const TensorInfo& input, |
| 581 | const TensorInfo& output, |
| 582 | const SoftmaxDescriptor& descriptor, |
| 583 | Optional<std::string&> reasonIfUnsupported) const |
| 584 | { |
| 585 | ignore_unused(descriptor); |
| 586 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSoftmaxWorkloadValidate, reasonIfUnsupported, input, output); |
| 587 | } |
| 588 | |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 589 | bool ClLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input, |
| 590 | const TensorInfo& output, |
| 591 | const SpaceToBatchNdDescriptor& descriptor, |
| 592 | Optional<std::string&> reasonIfUnsupported) const |
| 593 | { |
| 594 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSpaceToBatchNdWorkloadValidate, |
| 595 | reasonIfUnsupported, |
| 596 | input, |
| 597 | output, |
| 598 | descriptor); |
| 599 | } |
| 600 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 601 | bool ClLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 602 | const ViewsDescriptor& descriptor, |
| 603 | Optional<std::string&> reasonIfUnsupported) const |
| 604 | { |
| 605 | ignore_unused(descriptor); |
| 606 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 607 | input.GetDataType(), |
| 608 | &TrueFunc<>, |
| 609 | &TrueFunc<>); |
| 610 | } |
| 611 | |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 612 | bool ClLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 613 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 614 | const ViewsDescriptor& descriptor, |
| 615 | Optional<std::string&> reasonIfUnsupported) const |
| 616 | { |
Narumol Prangnawarat | 7413583 | 2019-05-23 15:07:33 +0100 | [diff] [blame] | 617 | #if defined(ARMCOMPUTECL_ENABLED) |
| 618 | // Split along the last dimension, cannot use sub-tensors |
| 619 | // as width and height of the sub-tensors do not match |
| 620 | // the width and height of the parent tensor |
| 621 | // in case of input with more than 2D. |
| 622 | std::set<unsigned int> splitAxis = ComputeSplitAxis(descriptor, input.GetShape()); |
| 623 | if (descriptor.GetNumDimensions() > 2 && splitAxis.size() == 1 && |
| 624 | *splitAxis.begin() == descriptor.GetNumDimensions() - 1 ) |
| 625 | { |
| 626 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSplitterWorkloadValidate, |
| 627 | reasonIfUnsupported, |
| 628 | input, |
| 629 | outputs, |
| 630 | *splitAxis.begin()); |
| 631 | } |
| 632 | #endif |
| 633 | for (auto output : outputs) |
| 634 | { |
| 635 | if (!input.IsTypeSpaceMatch(output)) // Cannot use sub-tensors if the types are not same space |
| 636 | { |
| 637 | SetValueChecked(reasonIfUnsupported, "Cl Splitter: Types and quantization parameters must match."); |
| 638 | return false; |
| 639 | } |
| 640 | } |
| 641 | return true; |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 642 | } |
| 643 | |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 644 | bool ClLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 645 | const TensorInfo& output, |
| 646 | const StridedSliceDescriptor& descriptor, |
| 647 | Optional<std::string&> reasonIfUnsupported) const |
| 648 | { |
| 649 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClStridedSliceWorkloadValidate, |
| 650 | reasonIfUnsupported, |
| 651 | input, |
| 652 | output, |
| 653 | descriptor); |
| 654 | } |
| 655 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 656 | bool ClLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 657 | const TensorInfo& input1, |
| 658 | const TensorInfo& output, |
| 659 | Optional<std::string&> reasonIfUnsupported) const |
| 660 | { |
| 661 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSubtractionValidate, |
| 662 | reasonIfUnsupported, |
| 663 | input0, |
| 664 | input1, |
| 665 | output); |
| 666 | } |
| 667 | |
| 668 | } // namespace armnn |