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) |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 18 | #include "workloads/ClAdditionWorkload.hpp" |
Nattapat Chaimanowong | e06757e | 2018-10-11 15:39:18 +0100 | [diff] [blame] | 19 | #include "workloads/ClActivationWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 20 | #include "workloads/ClBatchNormalizationFloatWorkload.hpp" |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 21 | #include "workloads/ClBatchToSpaceNdWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 22 | #include "workloads/ClConvertFp16ToFp32Workload.hpp" |
| 23 | #include "workloads/ClConvertFp32ToFp16Workload.hpp" |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 24 | #include "workloads/ClConvolution2dWorkload.hpp" |
Matthew Bentham | d877739 | 2018-10-08 09:38:55 +0100 | [diff] [blame] | 25 | #include "workloads/ClDepthwiseConvolutionWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 26 | #include "workloads/ClDivisionFloatWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 27 | #include "workloads/ClFullyConnectedWorkload.hpp" |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 28 | #include "workloads/ClGreaterWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 29 | #include "workloads/ClL2NormalizationFloatWorkload.hpp" |
| 30 | #include "workloads/ClLstmFloatWorkload.hpp" |
keidav01 | a959ee5 | 2018-12-19 10:04:58 +0000 | [diff] [blame] | 31 | #include "workloads/ClMaximumWorkload.hpp" |
Matteo Martincigh | 28dcab6 | 2018-10-19 16:40:03 +0100 | [diff] [blame] | 32 | #include "workloads/ClMeanWorkload.hpp" |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 33 | #include "workloads/ClConcatWorkload.hpp" |
saoste01 | 9292aa3 | 2019-01-08 13:55:59 +0000 | [diff] [blame] | 34 | #include "workloads/ClMinimumWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 35 | #include "workloads/ClMultiplicationWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 36 | #include "workloads/ClNormalizationFloatWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 37 | #include "workloads/ClPadWorkload.hpp" |
| 38 | #include "workloads/ClPermuteWorkload.hpp" |
Nattapat Chaimanowong | ac9e096 | 2018-10-10 17:18:35 +0100 | [diff] [blame] | 39 | #include "workloads/ClPooling2dWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 40 | #include "workloads/ClSoftmaxBaseWorkload.hpp" |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 41 | #include "workloads/ClSpaceToBatchNdWorkload.hpp" |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 42 | #include "workloads/ClStridedSliceWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 43 | #include "workloads/ClSubtractionWorkload.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 44 | #endif |
| 45 | |
| 46 | using namespace boost; |
| 47 | |
| 48 | namespace armnn |
| 49 | { |
arovir01 | 7c22c70 | 2018-10-09 11:16:46 +0100 | [diff] [blame] | 50 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 51 | namespace |
| 52 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 53 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 54 | template<unsigned int FilterSize> |
| 55 | bool IsMatchingSize2d(const TensorInfo& weightInfo) |
| 56 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 57 | // Width & Height must match. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 58 | return (weightInfo.GetShape()[3] == FilterSize) && (weightInfo.GetShape()[2] == FilterSize); |
| 59 | } |
| 60 | |
| 61 | template<uint32_t ValidStride> |
| 62 | bool IsMatchingStride(uint32_t actualStride) |
| 63 | { |
| 64 | return ValidStride == actualStride; |
| 65 | } |
| 66 | |
| 67 | template<uint32_t FirstStride, uint32_t SecondStride, uint32_t... ValidStrides> |
| 68 | bool IsMatchingStride(uint32_t actualStride) |
| 69 | { |
| 70 | return IsMatchingStride<FirstStride>(actualStride) || IsMatchingStride<SecondStride, ValidStrides...>(actualStride); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 71 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 72 | |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 73 | bool IsClBackendSupported(Optional<std::string&> reasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 74 | { |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 75 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 76 | return true; |
| 77 | #else |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 78 | if (reasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 79 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 80 | reasonIfUnsupported.value() = "The armnn library has been built without CL support"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 81 | } |
| 82 | return false; |
| 83 | #endif |
| 84 | } |
| 85 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 86 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 87 | #define FORWARD_CL_LAYER_SUPPORT_FUNC(expr) (expr) |
| 88 | #else |
| 89 | #define FORWARD_CL_LAYER_SUPPORT_FUNC(expr) IsClBackendSupported(reasonIfUnsupported) |
| 90 | #endif |
| 91 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 92 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | template<class FuncType, class... Args> |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 94 | inline bool IsWorkloadSupported(FuncType&& func, Optional<std::string&> reasonIfUnsupported, Args&&... args) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 95 | { |
| 96 | arm_compute::Status aclStatus = func(std::forward<Args>(args)...); |
| 97 | const bool supported = (aclStatus.error_code() == arm_compute::ErrorCode::OK); |
| 98 | if (!supported && reasonIfUnsupported) |
| 99 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 100 | reasonIfUnsupported.value() = aclStatus.error_description(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 101 | } |
| 102 | return supported; |
| 103 | } |
| 104 | |
| 105 | #define FORWARD_WORKLOAD_VALIDATE_FUNC(func, reasonIfUnsupported, ...) \ |
| 106 | return IsWorkloadSupported(func, reasonIfUnsupported, __VA_ARGS__); |
| 107 | #else |
| 108 | #define FORWARD_WORKLOAD_VALIDATE_FUNC(func, reasonIfUnsupported, ...) \ |
| 109 | return IsClBackendSupported(reasonIfUnsupported); |
| 110 | #endif |
| 111 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 112 | template<typename FloatFunc, typename Uint8Func, typename ... Params> |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 113 | bool IsSupportedForDataTypeCl(Optional<std::string&> reasonIfUnsupported, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 114 | DataType dataType, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 115 | FloatFunc floatFuncPtr, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 116 | Uint8Func uint8FuncPtr, |
| 117 | Params&&... params) |
| 118 | { |
| 119 | return IsClBackendSupported(reasonIfUnsupported) && |
| 120 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 121 | dataType, |
| 122 | floatFuncPtr, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 123 | floatFuncPtr, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 124 | uint8FuncPtr, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 125 | &FalseFunc<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 126 | &FalseFunc<>, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 127 | std::forward<Params>(params)...); |
| 128 | } |
| 129 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 130 | } // anonymous namespace |
| 131 | |
| 132 | bool ClLayerSupport::IsActivationSupported(const TensorInfo& input, |
| 133 | const TensorInfo& output, |
| 134 | const ActivationDescriptor& descriptor, |
| 135 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 136 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 137 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClActivationWorkloadValidate, |
| 138 | reasonIfUnsupported, |
| 139 | input, |
| 140 | output, |
| 141 | descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 144 | bool ClLayerSupport::IsAdditionSupported(const TensorInfo& input0, |
| 145 | const TensorInfo& input1, |
| 146 | const TensorInfo& output, |
| 147 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 148 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 149 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClAdditionValidate, |
| 150 | reasonIfUnsupported, |
| 151 | input0, |
| 152 | input1, |
| 153 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 156 | bool ClLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input, |
| 157 | const TensorInfo& output, |
| 158 | const TensorInfo& mean, |
| 159 | const TensorInfo& var, |
| 160 | const TensorInfo& beta, |
| 161 | const TensorInfo& gamma, |
| 162 | const BatchNormalizationDescriptor& descriptor, |
| 163 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 164 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 165 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClBatchNormalizationValidate, |
| 166 | reasonIfUnsupported, |
| 167 | input, |
| 168 | output, |
| 169 | mean, |
| 170 | var, |
| 171 | beta, |
| 172 | gamma, |
| 173 | descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 176 | bool ClLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input, |
| 177 | const TensorInfo& output, |
| 178 | const BatchToSpaceNdDescriptor& descriptor, |
| 179 | Optional<std::string&> reasonIfUnsupported) const |
| 180 | { |
| 181 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClBatchToSpaceNdWorkloadValidate, |
| 182 | reasonIfUnsupported, |
| 183 | input, |
| 184 | output, |
| 185 | descriptor); |
| 186 | } |
| 187 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 188 | bool ClLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs, |
| 189 | const TensorInfo& output, |
| 190 | const OriginsDescriptor& descriptor, |
| 191 | Optional<std::string&> reasonIfUnsupported) const |
| 192 | { |
| 193 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
| 194 | return IsMergerSupported(inputs, output, descriptor, reasonIfUnsupported); |
| 195 | ARMNN_NO_DEPRECATE_WARN_END |
| 196 | } |
| 197 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 198 | bool ClLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 199 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 200 | { |
| 201 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 202 | output.GetDataType(), |
| 203 | &TrueFunc<>, |
| 204 | &FalseFuncU8<>); |
| 205 | } |
| 206 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 207 | bool ClLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, |
| 208 | const TensorInfo& output, |
| 209 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 210 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 211 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp16ToFp32WorkloadValidate, |
| 212 | reasonIfUnsupported, |
| 213 | input, |
| 214 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 217 | bool ClLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 218 | const TensorInfo& output, |
| 219 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 220 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 221 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp32ToFp16WorkloadValidate, |
| 222 | reasonIfUnsupported, |
| 223 | input, |
| 224 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 227 | bool ClLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 228 | const TensorInfo& output, |
| 229 | const Convolution2dDescriptor& descriptor, |
| 230 | const TensorInfo& weights, |
| 231 | const Optional<TensorInfo>& biases, |
| 232 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 233 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 234 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvolution2dWorkloadValidate, |
| 235 | reasonIfUnsupported, |
| 236 | input, |
| 237 | output, |
| 238 | descriptor, |
| 239 | weights, |
| 240 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 243 | bool ClLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 244 | const TensorInfo& output, |
| 245 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 246 | const TensorInfo& weights, |
| 247 | const Optional<TensorInfo>& biases, |
| 248 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 249 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 250 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 251 | reasonIfUnsupported, |
| 252 | input, |
| 253 | output, |
| 254 | descriptor, |
| 255 | weights, |
| 256 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 259 | bool ClLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 260 | const TensorInfo& output, |
| 261 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 262 | const TensorInfo& weights, |
| 263 | const Optional<TensorInfo>& biases, |
| 264 | Optional<std::string&> reasonIfUnsupported) const |
| 265 | { |
| 266 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 267 | reasonIfUnsupported, |
| 268 | input, |
| 269 | output, |
| 270 | descriptor, |
| 271 | weights, |
| 272 | biases); |
| 273 | } |
| 274 | |
| 275 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 276 | bool ClLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
| 277 | const TensorInfo& input1, |
| 278 | const TensorInfo& output, |
| 279 | Optional<std::string&> reasonIfUnsupported) const |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 280 | { |
| 281 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDivisionWorkloadValidate, |
| 282 | reasonIfUnsupported, |
| 283 | input0, |
| 284 | input1, |
| 285 | output); |
| 286 | } |
| 287 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 288 | bool ClLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 289 | const TensorInfo& output, |
| 290 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 291 | { |
| 292 | ignore_unused(output); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 293 | return IsClBackendSupported(reasonIfUnsupported) && |
| 294 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 295 | input.GetDataType(), |
| 296 | &FalseFuncF16<>, |
| 297 | &TrueFunc<>, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 298 | &FalseFuncU8<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 299 | &FalseFuncI32<>, |
| 300 | &FalseFuncU8<>); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 303 | bool ClLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 304 | const TensorInfo& output, |
| 305 | const TensorInfo& weights, |
| 306 | const TensorInfo& biases, |
| 307 | const FullyConnectedDescriptor& descriptor, |
| 308 | Optional<std::string&> reasonIfUnsupported) const |
| 309 | { |
| 310 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClFullyConnectedWorkloadValidate, |
| 311 | reasonIfUnsupported, |
| 312 | input, |
| 313 | output, |
| 314 | weights, |
| 315 | biases, |
| 316 | descriptor); |
| 317 | } |
| 318 | |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 319 | bool ClLayerSupport::IsGreaterSupported(const TensorInfo& input0, |
| 320 | const TensorInfo& input1, |
| 321 | const TensorInfo& output, |
| 322 | Optional<std::string&> reasonIfUnsupported) const |
| 323 | { |
| 324 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClGreaterWorkloadValidate, |
| 325 | reasonIfUnsupported, |
| 326 | input0, |
| 327 | input1, |
| 328 | output); |
| 329 | } |
| 330 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 331 | bool ClLayerSupport::IsInputSupported(const TensorInfo& input, |
| 332 | Optional<std::string&> reasonIfUnsupported) const |
| 333 | { |
| 334 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 335 | input.GetDataType(), |
| 336 | &TrueFunc<>, |
| 337 | &TrueFunc<>); |
| 338 | } |
| 339 | |
| 340 | bool ClLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 341 | const TensorInfo& output, |
| 342 | const L2NormalizationDescriptor& descriptor, |
| 343 | Optional<std::string&> reasonIfUnsupported) const |
| 344 | { |
| 345 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClL2NormalizationWorkloadValidate, |
| 346 | reasonIfUnsupported, |
| 347 | input, |
| 348 | output, |
| 349 | descriptor); |
| 350 | } |
| 351 | |
| 352 | bool ClLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 353 | const TensorInfo& outputStateIn, |
| 354 | const TensorInfo& cellStateIn, |
| 355 | const TensorInfo& scratchBuffer, |
| 356 | const TensorInfo& outputStateOut, |
| 357 | const TensorInfo& cellStateOut, |
| 358 | const TensorInfo& output, |
| 359 | const LstmDescriptor& descriptor, |
| 360 | const TensorInfo& inputToForgetWeights, |
| 361 | const TensorInfo& inputToCellWeights, |
| 362 | const TensorInfo& inputToOutputWeights, |
| 363 | const TensorInfo& recurrentToForgetWeights, |
| 364 | const TensorInfo& recurrentToCellWeights, |
| 365 | const TensorInfo& recurrentToOutputWeights, |
| 366 | const TensorInfo& forgetGateBias, |
| 367 | const TensorInfo& cellBias, |
| 368 | const TensorInfo& outputGateBias, |
| 369 | const TensorInfo* inputToInputWeights, |
| 370 | const TensorInfo* recurrentToInputWeights, |
| 371 | const TensorInfo* cellToInputWeights, |
| 372 | const TensorInfo* inputGateBias, |
| 373 | const TensorInfo* projectionWeights, |
| 374 | const TensorInfo* projectionBias, |
| 375 | const TensorInfo* cellToForgetWeights, |
| 376 | const TensorInfo* cellToOutputWeights, |
| 377 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 378 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 379 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClLstmFloatWorkloadValidate, |
| 380 | reasonIfUnsupported, |
| 381 | input, |
| 382 | outputStateIn, |
| 383 | cellStateIn, |
| 384 | scratchBuffer, |
| 385 | outputStateOut, |
| 386 | cellStateOut, |
| 387 | output, |
| 388 | descriptor, |
| 389 | inputToForgetWeights, |
| 390 | inputToCellWeights, |
| 391 | inputToOutputWeights, |
| 392 | recurrentToForgetWeights, |
| 393 | recurrentToCellWeights, |
| 394 | recurrentToOutputWeights, |
| 395 | forgetGateBias, |
| 396 | cellBias, |
| 397 | outputGateBias, |
| 398 | inputToInputWeights, |
| 399 | recurrentToInputWeights, |
| 400 | cellToInputWeights, |
| 401 | inputGateBias, |
| 402 | projectionWeights, |
| 403 | projectionBias, |
| 404 | cellToForgetWeights, |
| 405 | cellToOutputWeights); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 406 | } |
| 407 | |
keidav01 | a959ee5 | 2018-12-19 10:04:58 +0000 | [diff] [blame] | 408 | bool ClLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 409 | const TensorInfo& input1, |
| 410 | const TensorInfo& output, |
| 411 | Optional<std::string&> reasonIfUnsupported) const |
| 412 | { |
| 413 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMaximumWorkloadValidate, |
| 414 | reasonIfUnsupported, |
| 415 | input0, |
| 416 | input1, |
| 417 | output); |
| 418 | } |
| 419 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 420 | bool ClLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 421 | const TensorInfo& output, |
| 422 | const MeanDescriptor& descriptor, |
| 423 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 424 | { |
Matteo Martincigh | 28dcab6 | 2018-10-19 16:40:03 +0100 | [diff] [blame] | 425 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMeanValidate, |
| 426 | reasonIfUnsupported, |
| 427 | input, |
| 428 | output, |
| 429 | descriptor); |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 430 | } |
| 431 | |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 432 | bool ClLayerSupport::IsMemCopySupported(const TensorInfo &input, |
| 433 | const TensorInfo &output, |
| 434 | Optional<std::string &> reasonIfUnsupported) const |
| 435 | { |
| 436 | ignore_unused(input); |
| 437 | ignore_unused(output); |
| 438 | return true; |
| 439 | } |
| 440 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 441 | bool ClLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 442 | const TensorInfo& output, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 443 | const OriginsDescriptor& descriptor, |
| 444 | Optional<std::string&> reasonIfUnsupported) const |
| 445 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 446 | if (descriptor.GetNumDimensions() <= descriptor.GetConcatAxis()) |
| 447 | { |
| 448 | SetValueChecked(reasonIfUnsupported, "Cl Merger: Concat axis > Number of dimensions."); |
| 449 | return false; |
| 450 | } |
| 451 | |
| 452 | unsigned int concatInnerAxis = (descriptor.GetNumDimensions() - descriptor.GetConcatAxis()) - 1; |
| 453 | if(concatInnerAxis < 3) // Width, height, or channels |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 454 | { |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 455 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConcatWorkloadValidate, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 456 | reasonIfUnsupported, |
| 457 | inputs, |
| 458 | output, |
| 459 | descriptor); |
| 460 | } |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 461 | else if (concatInnerAxis == 3) |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 462 | { |
Derek Lamberti | 0790dce | 2019-04-15 18:37:35 +0100 | [diff] [blame] | 463 | // We rely on the sub-tensor optimization to handle the batch dimension for 4D tensors. If we can't use |
| 464 | // sub-tensors for this then we can't support it. Here is where we check that the sub-tensors will work. |
| 465 | for (auto& input : inputs) |
| 466 | { |
| 467 | if (input && !output.IsTypeSpaceMatch(*input)) // Cannot use sub-tensors if the types are not same space |
| 468 | { |
| 469 | SetValueChecked(reasonIfUnsupported, "Cl Merger: Types and quantization parameters must match."); |
| 470 | return false; |
| 471 | } |
| 472 | } |
| 473 | return true; // Sub-tensors support concat along batch |
| 474 | } |
| 475 | else // > 4 dimensions not supported. |
| 476 | { |
| 477 | SetValueChecked(reasonIfUnsupported, "Cl Merger: Maximum of 4 dimensions supported."); |
| 478 | return false; |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 479 | } |
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 | { |
| 615 | ignore_unused(descriptor); |
| 616 | ignore_unused(outputs); |
| 617 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 618 | input.GetDataType(), |
| 619 | &TrueFunc<>, |
| 620 | &TrueFunc<>); |
| 621 | } |
| 622 | |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 623 | bool ClLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 624 | const TensorInfo& output, |
| 625 | const StridedSliceDescriptor& descriptor, |
| 626 | Optional<std::string&> reasonIfUnsupported) const |
| 627 | { |
| 628 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClStridedSliceWorkloadValidate, |
| 629 | reasonIfUnsupported, |
| 630 | input, |
| 631 | output, |
| 632 | descriptor); |
| 633 | } |
| 634 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 635 | bool ClLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 636 | const TensorInfo& input1, |
| 637 | const TensorInfo& output, |
| 638 | Optional<std::string&> reasonIfUnsupported) const |
| 639 | { |
| 640 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSubtractionValidate, |
| 641 | reasonIfUnsupported, |
| 642 | input0, |
| 643 | input1, |
| 644 | output); |
| 645 | } |
| 646 | |
| 647 | } // namespace armnn |