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, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame^] | 192 | const ConcatDescriptor& descriptor, |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 193 | Optional<std::string&> reasonIfUnsupported) const |
| 194 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame^] | 195 | if (descriptor.GetNumDimensions() <= descriptor.GetConcatAxis()) |
| 196 | { |
| 197 | SetValueChecked(reasonIfUnsupported, "Cl Concat: Concat axis > Number of dimensions."); |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | unsigned int concatInnerAxis = (descriptor.GetNumDimensions() - descriptor.GetConcatAxis()) - 1; |
| 202 | if(concatInnerAxis < 3) // Width, height, or channels |
| 203 | { |
| 204 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConcatWorkloadValidate, |
| 205 | reasonIfUnsupported, |
| 206 | inputs, |
| 207 | output, |
| 208 | descriptor); |
| 209 | } |
| 210 | else if (concatInnerAxis == 3) |
| 211 | { |
| 212 | // We rely on the sub-tensor optimization to handle the batch dimension for 4D tensors. If we can't use |
| 213 | // sub-tensors for this then we can't support it. Here is where we check that the sub-tensors will work. |
| 214 | for (auto& input : inputs) |
| 215 | { |
| 216 | if (input && !output.IsTypeSpaceMatch(*input)) // Cannot use sub-tensors if the types are not same space |
| 217 | { |
| 218 | SetValueChecked(reasonIfUnsupported, "Cl Concat: Types and quantization parameters must match."); |
| 219 | return false; |
| 220 | } |
| 221 | } |
| 222 | return true; // Sub-tensors support concat along batch |
| 223 | } |
| 224 | else // > 4 dimensions not supported. |
| 225 | { |
| 226 | SetValueChecked(reasonIfUnsupported, "Cl Concat: Maximum of 4 dimensions supported."); |
| 227 | return false; |
| 228 | } |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 231 | bool ClLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 232 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 233 | { |
| 234 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 235 | output.GetDataType(), |
| 236 | &TrueFunc<>, |
| 237 | &FalseFuncU8<>); |
| 238 | } |
| 239 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 240 | bool ClLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, |
| 241 | const TensorInfo& output, |
| 242 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 243 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 244 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp16ToFp32WorkloadValidate, |
| 245 | reasonIfUnsupported, |
| 246 | input, |
| 247 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 250 | bool ClLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 251 | const TensorInfo& output, |
| 252 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 253 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 254 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp32ToFp16WorkloadValidate, |
| 255 | reasonIfUnsupported, |
| 256 | input, |
| 257 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 260 | bool ClLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 261 | const TensorInfo& output, |
| 262 | const Convolution2dDescriptor& descriptor, |
| 263 | const TensorInfo& weights, |
| 264 | const Optional<TensorInfo>& biases, |
| 265 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 266 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 267 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvolution2dWorkloadValidate, |
| 268 | reasonIfUnsupported, |
| 269 | input, |
| 270 | output, |
| 271 | descriptor, |
| 272 | weights, |
| 273 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 276 | bool ClLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 277 | const TensorInfo& output, |
| 278 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 279 | const TensorInfo& weights, |
| 280 | const Optional<TensorInfo>& biases, |
| 281 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 282 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 283 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 284 | reasonIfUnsupported, |
| 285 | input, |
| 286 | output, |
| 287 | descriptor, |
| 288 | weights, |
| 289 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 292 | bool ClLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 293 | const TensorInfo& output, |
| 294 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 295 | const TensorInfo& weights, |
| 296 | const Optional<TensorInfo>& biases, |
| 297 | Optional<std::string&> reasonIfUnsupported) const |
| 298 | { |
| 299 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 300 | reasonIfUnsupported, |
| 301 | input, |
| 302 | output, |
| 303 | descriptor, |
| 304 | weights, |
| 305 | biases); |
| 306 | } |
| 307 | |
| 308 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 309 | bool ClLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
| 310 | const TensorInfo& input1, |
| 311 | const TensorInfo& output, |
| 312 | Optional<std::string&> reasonIfUnsupported) const |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 313 | { |
| 314 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDivisionWorkloadValidate, |
| 315 | reasonIfUnsupported, |
| 316 | input0, |
| 317 | input1, |
| 318 | output); |
| 319 | } |
| 320 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 321 | bool ClLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 322 | const TensorInfo& output, |
| 323 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 324 | { |
| 325 | ignore_unused(output); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 326 | return IsClBackendSupported(reasonIfUnsupported) && |
| 327 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 328 | input.GetDataType(), |
| 329 | &FalseFuncF16<>, |
| 330 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 331 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 332 | &FalseFuncI32<>, |
| 333 | &FalseFuncU8<>); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 336 | bool ClLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 337 | const TensorInfo& output, |
| 338 | const TensorInfo& weights, |
| 339 | const TensorInfo& biases, |
| 340 | const FullyConnectedDescriptor& descriptor, |
| 341 | Optional<std::string&> reasonIfUnsupported) const |
| 342 | { |
| 343 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClFullyConnectedWorkloadValidate, |
| 344 | reasonIfUnsupported, |
| 345 | input, |
| 346 | output, |
| 347 | weights, |
| 348 | biases, |
| 349 | descriptor); |
| 350 | } |
| 351 | |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 352 | bool ClLayerSupport::IsGreaterSupported(const TensorInfo& input0, |
| 353 | const TensorInfo& input1, |
| 354 | const TensorInfo& output, |
| 355 | Optional<std::string&> reasonIfUnsupported) const |
| 356 | { |
| 357 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClGreaterWorkloadValidate, |
| 358 | reasonIfUnsupported, |
| 359 | input0, |
| 360 | input1, |
| 361 | output); |
| 362 | } |
| 363 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 364 | bool ClLayerSupport::IsInputSupported(const TensorInfo& input, |
| 365 | Optional<std::string&> reasonIfUnsupported) const |
| 366 | { |
| 367 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 368 | input.GetDataType(), |
| 369 | &TrueFunc<>, |
| 370 | &TrueFunc<>); |
| 371 | } |
| 372 | |
| 373 | bool ClLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 374 | const TensorInfo& output, |
| 375 | const L2NormalizationDescriptor& descriptor, |
| 376 | Optional<std::string&> reasonIfUnsupported) const |
| 377 | { |
| 378 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClL2NormalizationWorkloadValidate, |
| 379 | reasonIfUnsupported, |
| 380 | input, |
| 381 | output, |
| 382 | descriptor); |
| 383 | } |
| 384 | |
| 385 | bool ClLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 386 | const TensorInfo& outputStateIn, |
| 387 | const TensorInfo& cellStateIn, |
| 388 | const TensorInfo& scratchBuffer, |
| 389 | const TensorInfo& outputStateOut, |
| 390 | const TensorInfo& cellStateOut, |
| 391 | const TensorInfo& output, |
| 392 | const LstmDescriptor& descriptor, |
| 393 | const TensorInfo& inputToForgetWeights, |
| 394 | const TensorInfo& inputToCellWeights, |
| 395 | const TensorInfo& inputToOutputWeights, |
| 396 | const TensorInfo& recurrentToForgetWeights, |
| 397 | const TensorInfo& recurrentToCellWeights, |
| 398 | const TensorInfo& recurrentToOutputWeights, |
| 399 | const TensorInfo& forgetGateBias, |
| 400 | const TensorInfo& cellBias, |
| 401 | const TensorInfo& outputGateBias, |
| 402 | const TensorInfo* inputToInputWeights, |
| 403 | const TensorInfo* recurrentToInputWeights, |
| 404 | const TensorInfo* cellToInputWeights, |
| 405 | const TensorInfo* inputGateBias, |
| 406 | const TensorInfo* projectionWeights, |
| 407 | const TensorInfo* projectionBias, |
| 408 | const TensorInfo* cellToForgetWeights, |
| 409 | const TensorInfo* cellToOutputWeights, |
| 410 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 411 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 412 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClLstmFloatWorkloadValidate, |
| 413 | reasonIfUnsupported, |
| 414 | input, |
| 415 | outputStateIn, |
| 416 | cellStateIn, |
| 417 | scratchBuffer, |
| 418 | outputStateOut, |
| 419 | cellStateOut, |
| 420 | output, |
| 421 | descriptor, |
| 422 | inputToForgetWeights, |
| 423 | inputToCellWeights, |
| 424 | inputToOutputWeights, |
| 425 | recurrentToForgetWeights, |
| 426 | recurrentToCellWeights, |
| 427 | recurrentToOutputWeights, |
| 428 | forgetGateBias, |
| 429 | cellBias, |
| 430 | outputGateBias, |
| 431 | inputToInputWeights, |
| 432 | recurrentToInputWeights, |
| 433 | cellToInputWeights, |
| 434 | inputGateBias, |
| 435 | projectionWeights, |
| 436 | projectionBias, |
| 437 | cellToForgetWeights, |
| 438 | cellToOutputWeights); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 439 | } |
| 440 | |
keidav01 | a959ee5 | 2018-12-19 10:04:58 +0000 | [diff] [blame] | 441 | bool ClLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 442 | const TensorInfo& input1, |
| 443 | const TensorInfo& output, |
| 444 | Optional<std::string&> reasonIfUnsupported) const |
| 445 | { |
| 446 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMaximumWorkloadValidate, |
| 447 | reasonIfUnsupported, |
| 448 | input0, |
| 449 | input1, |
| 450 | output); |
| 451 | } |
| 452 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 453 | bool ClLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 454 | const TensorInfo& output, |
| 455 | const MeanDescriptor& descriptor, |
| 456 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 457 | { |
Matteo Martincigh | 28dcab6 | 2018-10-19 16:40:03 +0100 | [diff] [blame] | 458 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMeanValidate, |
| 459 | reasonIfUnsupported, |
| 460 | input, |
| 461 | output, |
| 462 | descriptor); |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 465 | bool ClLayerSupport::IsMemCopySupported(const TensorInfo &input, |
| 466 | const TensorInfo &output, |
| 467 | Optional<std::string &> reasonIfUnsupported) const |
| 468 | { |
| 469 | ignore_unused(input); |
| 470 | ignore_unused(output); |
| 471 | return true; |
| 472 | } |
| 473 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 474 | bool ClLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 475 | const TensorInfo& output, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame^] | 476 | const MergerDescriptor& descriptor, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 477 | Optional<std::string&> reasonIfUnsupported) const |
| 478 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame^] | 479 | return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 480 | } |
| 481 | |
saoste01 | 9292aa3 | 2019-01-08 13:55:59 +0000 | [diff] [blame] | 482 | bool ClLayerSupport::IsMinimumSupported(const TensorInfo& input0, |
| 483 | const TensorInfo& input1, |
| 484 | const TensorInfo& output, |
| 485 | Optional<std::string&> reasonIfUnsupported) const |
| 486 | { |
| 487 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMinimumWorkloadValidate, |
| 488 | reasonIfUnsupported, |
| 489 | input0, |
| 490 | input1, |
| 491 | output); |
| 492 | } |
| 493 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 494 | bool ClLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, |
| 495 | const TensorInfo& input1, |
| 496 | const TensorInfo& output, |
| 497 | Optional<std::string&> reasonIfUnsupported) const |
| 498 | { |
| 499 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMultiplicationWorkloadValidate, |
| 500 | reasonIfUnsupported, |
| 501 | input0, |
| 502 | input1, |
| 503 | output); |
| 504 | } |
| 505 | |
| 506 | bool ClLayerSupport::IsNormalizationSupported(const TensorInfo& input, |
| 507 | const TensorInfo& output, |
| 508 | const NormalizationDescriptor& descriptor, |
| 509 | Optional<std::string&> reasonIfUnsupported) const |
| 510 | { |
| 511 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClNormalizationWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
| 512 | } |
| 513 | |
| 514 | bool ClLayerSupport::IsOutputSupported(const TensorInfo& output, |
| 515 | Optional<std::string&> reasonIfUnsupported) const |
| 516 | { |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 517 | return IsClBackendSupported(reasonIfUnsupported) && |
| 518 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 519 | output.GetDataType(), |
| 520 | &TrueFunc<>, |
| 521 | &TrueFunc<>, |
| 522 | &TrueFunc<>, |
| 523 | &FalseFuncI32<>, |
| 524 | &TrueFunc<>); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | bool ClLayerSupport::IsPadSupported(const TensorInfo& input, |
| 528 | const TensorInfo& output, |
| 529 | const PadDescriptor& descriptor, |
| 530 | Optional<std::string&> reasonIfUnsupported) const |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 531 | { |
| 532 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPadValidate, |
| 533 | reasonIfUnsupported, |
| 534 | input, |
| 535 | output, |
| 536 | descriptor); |
| 537 | } |
| 538 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 539 | bool ClLayerSupport::IsPermuteSupported(const TensorInfo& input, |
| 540 | const TensorInfo& output, |
| 541 | const PermuteDescriptor& descriptor, |
| 542 | Optional<std::string&> reasonIfUnsupported) const |
| 543 | { |
| 544 | ignore_unused(input); |
| 545 | ignore_unused(output); |
| 546 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPermuteWorkloadValidate, reasonIfUnsupported, descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 547 | } |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 548 | |
| 549 | bool ClLayerSupport::IsPooling2dSupported(const TensorInfo& input, |
| 550 | const TensorInfo& output, |
| 551 | const Pooling2dDescriptor& descriptor, |
| 552 | Optional<std::string&> reasonIfUnsupported) const |
| 553 | { |
| 554 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPooling2dWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
| 555 | } |
| 556 | |
| 557 | bool ClLayerSupport::IsReshapeSupported(const TensorInfo& input, |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 558 | const ReshapeDescriptor& descriptor, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 559 | Optional<std::string&> reasonIfUnsupported) const |
| 560 | { |
| 561 | ignore_unused(input); |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 562 | ignore_unused(descriptor); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 563 | ignore_unused(reasonIfUnsupported); |
| 564 | return true; |
| 565 | } |
| 566 | |
| 567 | bool ClLayerSupport::IsResizeBilinearSupported(const TensorInfo& input, |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 568 | const TensorInfo& output, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 569 | Optional<std::string&> reasonIfUnsupported) const |
| 570 | { |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 571 | ignore_unused(output); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 572 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 573 | input.GetDataType(), |
| 574 | &TrueFunc<>, |
| 575 | &FalseFuncU8<>); |
| 576 | } |
| 577 | |
| 578 | bool ClLayerSupport::IsSoftmaxSupported(const TensorInfo& input, |
| 579 | const TensorInfo& output, |
| 580 | const SoftmaxDescriptor& descriptor, |
| 581 | Optional<std::string&> reasonIfUnsupported) const |
| 582 | { |
| 583 | ignore_unused(descriptor); |
| 584 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSoftmaxWorkloadValidate, reasonIfUnsupported, input, output); |
| 585 | } |
| 586 | |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 587 | bool ClLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input, |
| 588 | const TensorInfo& output, |
| 589 | const SpaceToBatchNdDescriptor& descriptor, |
| 590 | Optional<std::string&> reasonIfUnsupported) const |
| 591 | { |
| 592 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSpaceToBatchNdWorkloadValidate, |
| 593 | reasonIfUnsupported, |
| 594 | input, |
| 595 | output, |
| 596 | descriptor); |
| 597 | } |
| 598 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 599 | bool ClLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 600 | const ViewsDescriptor& descriptor, |
| 601 | Optional<std::string&> reasonIfUnsupported) const |
| 602 | { |
| 603 | ignore_unused(descriptor); |
| 604 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 605 | input.GetDataType(), |
| 606 | &TrueFunc<>, |
| 607 | &TrueFunc<>); |
| 608 | } |
| 609 | |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 610 | bool ClLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 611 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 612 | const ViewsDescriptor& descriptor, |
| 613 | Optional<std::string&> reasonIfUnsupported) const |
| 614 | { |
Narumol Prangnawarat | 7413583 | 2019-05-23 15:07:33 +0100 | [diff] [blame] | 615 | #if defined(ARMCOMPUTECL_ENABLED) |
| 616 | // Split along the last dimension, cannot use sub-tensors |
| 617 | // as width and height of the sub-tensors do not match |
| 618 | // the width and height of the parent tensor |
| 619 | // in case of input with more than 2D. |
| 620 | std::set<unsigned int> splitAxis = ComputeSplitAxis(descriptor, input.GetShape()); |
| 621 | if (descriptor.GetNumDimensions() > 2 && splitAxis.size() == 1 && |
| 622 | *splitAxis.begin() == descriptor.GetNumDimensions() - 1 ) |
| 623 | { |
| 624 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSplitterWorkloadValidate, |
| 625 | reasonIfUnsupported, |
| 626 | input, |
| 627 | outputs, |
| 628 | *splitAxis.begin()); |
| 629 | } |
| 630 | #endif |
| 631 | for (auto output : outputs) |
| 632 | { |
| 633 | if (!input.IsTypeSpaceMatch(output)) // Cannot use sub-tensors if the types are not same space |
| 634 | { |
| 635 | SetValueChecked(reasonIfUnsupported, "Cl Splitter: Types and quantization parameters must match."); |
| 636 | return false; |
| 637 | } |
| 638 | } |
| 639 | return true; |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 640 | } |
| 641 | |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 642 | bool ClLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 643 | const TensorInfo& output, |
| 644 | const StridedSliceDescriptor& descriptor, |
| 645 | Optional<std::string&> reasonIfUnsupported) const |
| 646 | { |
| 647 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClStridedSliceWorkloadValidate, |
| 648 | reasonIfUnsupported, |
| 649 | input, |
| 650 | output, |
| 651 | descriptor); |
| 652 | } |
| 653 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 654 | bool ClLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 655 | const TensorInfo& input1, |
| 656 | const TensorInfo& output, |
| 657 | Optional<std::string&> reasonIfUnsupported) const |
| 658 | { |
| 659 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSubtractionValidate, |
| 660 | reasonIfUnsupported, |
| 661 | input0, |
| 662 | input1, |
| 663 | output); |
| 664 | } |
| 665 | |
| 666 | } // namespace armnn |