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