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> |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 10 | #include <armnn/BackendRegistry.hpp> |
| 11 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 12 | #include <InternalTypes.hpp> |
| 13 | #include <LayerSupportCommon.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | |
| 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> |
Aron Virginas-Tar | 710f664 | 2019-11-27 14:48:32 +0000 | [diff] [blame] | 19 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Aron Virginas-Tar | 8204694 | 2019-09-09 15:18:29 +0100 | [diff] [blame] | 20 | #include "workloads/ClAbsWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 21 | #include "workloads/ClAdditionWorkload.hpp" |
Nattapat Chaimanowong | e06757e | 2018-10-11 15:39:18 +0100 | [diff] [blame] | 22 | #include "workloads/ClActivationWorkload.hpp" |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 23 | #include "workloads/ClArgMinMaxWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 24 | #include "workloads/ClBatchNormalizationFloatWorkload.hpp" |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 25 | #include "workloads/ClBatchToSpaceNdWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 26 | #include "workloads/ClConvertFp16ToFp32Workload.hpp" |
| 27 | #include "workloads/ClConvertFp32ToFp16Workload.hpp" |
Matthew Bentham | d806792 | 2018-10-03 17:18:04 +0100 | [diff] [blame] | 28 | #include "workloads/ClConvolution2dWorkload.hpp" |
Aron Virginas-Tar | b280196 | 2019-09-30 11:24:53 +0100 | [diff] [blame] | 29 | #include "workloads/ClDepthToSpaceWorkload.hpp" |
Matthew Bentham | d877739 | 2018-10-08 09:38:55 +0100 | [diff] [blame] | 30 | #include "workloads/ClDepthwiseConvolutionWorkload.hpp" |
Aron Virginas-Tar | b280196 | 2019-09-30 11:24:53 +0100 | [diff] [blame] | 31 | #include "workloads/ClDequantizeWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 32 | #include "workloads/ClDivisionFloatWorkload.hpp" |
Sadik Armagan | 9be4916 | 2019-10-30 16:15:26 +0000 | [diff] [blame] | 33 | #include "workloads/ClFloorFloatWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 34 | #include "workloads/ClFullyConnectedWorkload.hpp" |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 35 | #include "workloads/ClGreaterWorkload.hpp" |
Aron Virginas-Tar | 8168f40 | 2019-10-04 13:10:16 +0100 | [diff] [blame] | 36 | #include "workloads/ClInstanceNormalizationWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 37 | #include "workloads/ClL2NormalizationFloatWorkload.hpp" |
| 38 | #include "workloads/ClLstmFloatWorkload.hpp" |
keidav01 | a959ee5 | 2018-12-19 10:04:58 +0000 | [diff] [blame] | 39 | #include "workloads/ClMaximumWorkload.hpp" |
Matteo Martincigh | 28dcab6 | 2018-10-19 16:40:03 +0100 | [diff] [blame] | 40 | #include "workloads/ClMeanWorkload.hpp" |
Jim Flynn | 6905941 | 2019-05-17 13:03:57 +0100 | [diff] [blame] | 41 | #include "workloads/ClConcatWorkload.hpp" |
saoste01 | 9292aa3 | 2019-01-08 13:55:59 +0000 | [diff] [blame] | 42 | #include "workloads/ClMinimumWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 43 | #include "workloads/ClMultiplicationWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 44 | #include "workloads/ClNormalizationFloatWorkload.hpp" |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 45 | #include "workloads/ClPadWorkload.hpp" |
| 46 | #include "workloads/ClPermuteWorkload.hpp" |
Nattapat Chaimanowong | ac9e096 | 2018-10-10 17:18:35 +0100 | [diff] [blame] | 47 | #include "workloads/ClPooling2dWorkload.hpp" |
Nikhil Raj | 91e4c6d | 2019-07-05 12:22:58 +0100 | [diff] [blame] | 48 | #include "workloads/ClPreluWorkload.hpp" |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 49 | #include "workloads/ClResizeWorkload.hpp" |
Aron Virginas-Tar | 1a763dd | 2019-09-10 12:32:08 +0100 | [diff] [blame] | 50 | #include "workloads/ClRsqrtWorkload.hpp" |
Ferran Balaguer | 737d9ff | 2019-08-01 09:58:08 +0100 | [diff] [blame] | 51 | #include "workloads/ClQuantizedLstmWorkload.hpp" |
Sadik Armagan | 20ec249 | 2019-05-31 09:09:44 +0100 | [diff] [blame] | 52 | #include "workloads/ClQuantizeWorkload.hpp" |
Aron Virginas-Tar | 94c4fef | 2019-11-25 15:37:08 +0000 | [diff] [blame] | 53 | #include "workloads/ClSliceWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 54 | #include "workloads/ClSoftmaxBaseWorkload.hpp" |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 55 | #include "workloads/ClSpaceToBatchNdWorkload.hpp" |
James Conroy | d2aa85e | 2019-07-01 17:12:40 +0100 | [diff] [blame] | 56 | #include "workloads/ClSpaceToDepthWorkload.hpp" |
Narumol Prangnawarat | 7413583 | 2019-05-23 15:07:33 +0100 | [diff] [blame] | 57 | #include "workloads/ClSplitterWorkload.hpp" |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 58 | #include "workloads/ClStackWorkload.hpp" |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 59 | #include "workloads/ClStridedSliceWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 60 | #include "workloads/ClSubtractionWorkload.hpp" |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 61 | #include "workloads/ClTransposeConvolution2dWorkload.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
| 64 | using namespace boost; |
| 65 | |
| 66 | namespace armnn |
| 67 | { |
arovir01 | 7c22c70 | 2018-10-09 11:16:46 +0100 | [diff] [blame] | 68 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 69 | namespace |
| 70 | { |
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 | template<unsigned int FilterSize> |
| 73 | bool IsMatchingSize2d(const TensorInfo& weightInfo) |
| 74 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 75 | // Width & Height must match. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 76 | return (weightInfo.GetShape()[3] == FilterSize) && (weightInfo.GetShape()[2] == FilterSize); |
| 77 | } |
| 78 | |
| 79 | template<uint32_t ValidStride> |
| 80 | bool IsMatchingStride(uint32_t actualStride) |
| 81 | { |
| 82 | return ValidStride == actualStride; |
| 83 | } |
| 84 | |
| 85 | template<uint32_t FirstStride, uint32_t SecondStride, uint32_t... ValidStrides> |
| 86 | bool IsMatchingStride(uint32_t actualStride) |
| 87 | { |
| 88 | return IsMatchingStride<FirstStride>(actualStride) || IsMatchingStride<SecondStride, ValidStrides...>(actualStride); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 89 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 90 | |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 91 | template<typename ... Args> |
| 92 | bool IsClBackendSupported(Optional<std::string&> reasonIfUnsupported, Args... args) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | { |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 94 | boost::ignore_unused(reasonIfUnsupported, (args)...); |
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 | return true; |
| 97 | #else |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 98 | if (reasonIfUnsupported) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 99 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 100 | reasonIfUnsupported.value() = "The armnn library has been built without CL support"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 101 | } |
| 102 | return false; |
| 103 | #endif |
| 104 | } |
| 105 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 106 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 107 | #define FORWARD_CL_LAYER_SUPPORT_FUNC(expr) (expr) |
| 108 | #else |
| 109 | #define FORWARD_CL_LAYER_SUPPORT_FUNC(expr) IsClBackendSupported(reasonIfUnsupported) |
| 110 | #endif |
| 111 | |
Matteo Martincigh | d95e906 | 2019-01-31 15:35:59 +0000 | [diff] [blame] | 112 | #if defined(ARMCOMPUTECL_ENABLED) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 113 | template<class FuncType, class... Args> |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 114 | inline bool IsWorkloadSupported(FuncType&& func, Optional<std::string&> reasonIfUnsupported, Args&&... args) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 115 | { |
| 116 | arm_compute::Status aclStatus = func(std::forward<Args>(args)...); |
| 117 | const bool supported = (aclStatus.error_code() == arm_compute::ErrorCode::OK); |
| 118 | if (!supported && reasonIfUnsupported) |
| 119 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 120 | reasonIfUnsupported.value() = aclStatus.error_description(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 121 | } |
| 122 | return supported; |
| 123 | } |
| 124 | |
| 125 | #define FORWARD_WORKLOAD_VALIDATE_FUNC(func, reasonIfUnsupported, ...) \ |
| 126 | return IsWorkloadSupported(func, reasonIfUnsupported, __VA_ARGS__); |
| 127 | #else |
| 128 | #define FORWARD_WORKLOAD_VALIDATE_FUNC(func, reasonIfUnsupported, ...) \ |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 129 | return IsClBackendSupported(reasonIfUnsupported, __VA_ARGS__); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 130 | #endif |
| 131 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 132 | template<typename FloatFunc, typename Uint8Func, typename ... Params> |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 133 | bool IsSupportedForDataTypeCl(Optional<std::string&> reasonIfUnsupported, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 134 | DataType dataType, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 135 | FloatFunc floatFuncPtr, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 136 | Uint8Func uint8FuncPtr, |
| 137 | Params&&... params) |
| 138 | { |
| 139 | return IsClBackendSupported(reasonIfUnsupported) && |
| 140 | IsSupportedForDataTypeGeneric(reasonIfUnsupported, |
| 141 | dataType, |
| 142 | floatFuncPtr, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 143 | floatFuncPtr, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 144 | uint8FuncPtr, |
narpra01 | db2b160 | 2019-01-23 15:23:11 +0000 | [diff] [blame] | 145 | &FalseFunc<>, |
kevmay01 | 2b4d88e | 2019-01-24 14:05:09 +0000 | [diff] [blame] | 146 | &FalseFunc<>, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 147 | std::forward<Params>(params)...); |
| 148 | } |
| 149 | |
Aron Virginas-Tar | 710f664 | 2019-11-27 14:48:32 +0000 | [diff] [blame] | 150 | #if defined(ARMCOMPUTECL_ENABLED) |
| 151 | #define IS_QUANT_MULTIPLIER_SUPPORTED(input, output, weights) \ |
| 152 | armcomputetensorutils::IsQuantMultiplierSupported(input, output, weights) |
| 153 | #else |
| 154 | #define IS_QUANT_MULTIPLIER_SUPPORTED(input, output, weights) true |
| 155 | #endif |
| 156 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 157 | } // anonymous namespace |
| 158 | |
Aron Virginas-Tar | 8204694 | 2019-09-09 15:18:29 +0100 | [diff] [blame] | 159 | bool ClLayerSupport::IsAbsSupported(const TensorInfo& input, |
| 160 | const TensorInfo& output, |
| 161 | Optional<std::string&> reasonIfUnsupported) const |
| 162 | { |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 163 | ElementwiseUnaryDescriptor descriptor(UnaryOperation::Abs); |
| 164 | return IsElementwiseUnarySupported(input, output, descriptor, reasonIfUnsupported); |
Aron Virginas-Tar | 8204694 | 2019-09-09 15:18:29 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 167 | bool ClLayerSupport::IsActivationSupported(const TensorInfo& input, |
| 168 | const TensorInfo& output, |
| 169 | const ActivationDescriptor& descriptor, |
| 170 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 171 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 172 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClActivationWorkloadValidate, |
| 173 | reasonIfUnsupported, |
| 174 | input, |
| 175 | output, |
| 176 | descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 179 | bool ClLayerSupport::IsAdditionSupported(const TensorInfo& input0, |
| 180 | const TensorInfo& input1, |
| 181 | const TensorInfo& output, |
| 182 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 183 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 184 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClAdditionValidate, |
| 185 | reasonIfUnsupported, |
| 186 | input0, |
| 187 | input1, |
| 188 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 189 | } |
| 190 | |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 191 | bool ClLayerSupport::IsArgMinMaxSupported(const TensorInfo& input, |
| 192 | const TensorInfo& output, |
| 193 | const ArgMinMaxDescriptor& descriptor, |
| 194 | Optional<std::string&> reasonIfUnsupported) const |
| 195 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 196 | if (input.GetDataType() == DataType::QAsymmU8) |
Francis Murtagh | 52ec346 | 2019-11-19 12:24:19 +0000 | [diff] [blame] | 197 | { |
| 198 | return false; |
| 199 | } |
| 200 | |
James Conroy | 2dc0572 | 2019-09-19 17:00:31 +0100 | [diff] [blame] | 201 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClArgMinMaxWorkloadValidate, |
| 202 | reasonIfUnsupported, |
| 203 | input, |
| 204 | output, |
| 205 | descriptor); |
| 206 | } |
| 207 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 208 | bool ClLayerSupport::IsBatchNormalizationSupported(const TensorInfo& input, |
| 209 | const TensorInfo& output, |
| 210 | const TensorInfo& mean, |
| 211 | const TensorInfo& var, |
| 212 | const TensorInfo& beta, |
| 213 | const TensorInfo& gamma, |
| 214 | const BatchNormalizationDescriptor& descriptor, |
| 215 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 216 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 217 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClBatchNormalizationValidate, |
| 218 | reasonIfUnsupported, |
| 219 | input, |
| 220 | output, |
| 221 | mean, |
| 222 | var, |
| 223 | beta, |
| 224 | gamma, |
| 225 | descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Mike Kelly | 831faed | 2018-11-28 11:52:08 +0000 | [diff] [blame] | 228 | bool ClLayerSupport::IsBatchToSpaceNdSupported(const TensorInfo& input, |
| 229 | const TensorInfo& output, |
| 230 | const BatchToSpaceNdDescriptor& descriptor, |
| 231 | Optional<std::string&> reasonIfUnsupported) const |
| 232 | { |
| 233 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClBatchToSpaceNdWorkloadValidate, |
| 234 | reasonIfUnsupported, |
| 235 | input, |
| 236 | output, |
| 237 | descriptor); |
| 238 | } |
| 239 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 240 | bool ClLayerSupport::IsComparisonSupported(const TensorInfo& input0, |
| 241 | const TensorInfo& input1, |
| 242 | const TensorInfo& output, |
| 243 | const ComparisonDescriptor& descriptor, |
| 244 | Optional<std::string&> reasonIfUnsupported) const |
| 245 | { |
| 246 | if (descriptor.m_Operation == ComparisonOperation::Greater) |
| 247 | { |
| 248 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClGreaterWorkloadValidate, |
| 249 | reasonIfUnsupported, |
| 250 | input0, |
| 251 | input1, |
| 252 | output); |
| 253 | } |
| 254 | |
| 255 | return false; |
| 256 | } |
| 257 | |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 258 | bool ClLayerSupport::IsConcatSupported(const std::vector<const TensorInfo*> inputs, |
| 259 | const TensorInfo& output, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 260 | const ConcatDescriptor& descriptor, |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 261 | Optional<std::string&> reasonIfUnsupported) const |
| 262 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 263 | if (descriptor.GetNumDimensions() <= descriptor.GetConcatAxis()) |
| 264 | { |
| 265 | SetValueChecked(reasonIfUnsupported, "Cl Concat: Concat axis > Number of dimensions."); |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | unsigned int concatInnerAxis = (descriptor.GetNumDimensions() - descriptor.GetConcatAxis()) - 1; |
| 270 | if(concatInnerAxis < 3) // Width, height, or channels |
| 271 | { |
| 272 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConcatWorkloadValidate, |
| 273 | reasonIfUnsupported, |
| 274 | inputs, |
| 275 | output, |
| 276 | descriptor); |
| 277 | } |
| 278 | else if (concatInnerAxis == 3) |
| 279 | { |
| 280 | // We rely on the sub-tensor optimization to handle the batch dimension for 4D tensors. If we can't use |
| 281 | // sub-tensors for this then we can't support it. Here is where we check that the sub-tensors will work. |
| 282 | for (auto& input : inputs) |
| 283 | { |
| 284 | if (input && !output.IsTypeSpaceMatch(*input)) // Cannot use sub-tensors if the types are not same space |
| 285 | { |
| 286 | SetValueChecked(reasonIfUnsupported, "Cl Concat: Types and quantization parameters must match."); |
| 287 | return false; |
| 288 | } |
| 289 | } |
| 290 | return true; // Sub-tensors support concat along batch |
| 291 | } |
| 292 | else // > 4 dimensions not supported. |
| 293 | { |
| 294 | SetValueChecked(reasonIfUnsupported, "Cl Concat: Maximum of 4 dimensions supported."); |
| 295 | return false; |
| 296 | } |
Jim Flynn | 906f946 | 2019-05-10 13:55:21 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 299 | bool ClLayerSupport::IsConstantSupported(const TensorInfo& output, |
| 300 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 301 | { |
| 302 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 303 | output.GetDataType(), |
| 304 | &TrueFunc<>, |
Francis Murtagh | ec33a91 | 2019-11-05 14:26:23 +0000 | [diff] [blame] | 305 | &TrueFunc<>); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 308 | bool ClLayerSupport::IsConvertFp16ToFp32Supported(const TensorInfo& input, |
| 309 | const TensorInfo& output, |
| 310 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 311 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 312 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp16ToFp32WorkloadValidate, |
| 313 | reasonIfUnsupported, |
| 314 | input, |
| 315 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 318 | bool ClLayerSupport::IsConvertFp32ToFp16Supported(const TensorInfo& input, |
| 319 | const TensorInfo& output, |
| 320 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 321 | { |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 322 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvertFp32ToFp16WorkloadValidate, |
| 323 | reasonIfUnsupported, |
| 324 | input, |
| 325 | output); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 328 | bool ClLayerSupport::IsConvolution2dSupported(const TensorInfo& input, |
| 329 | const TensorInfo& output, |
| 330 | const Convolution2dDescriptor& descriptor, |
| 331 | const TensorInfo& weights, |
| 332 | const Optional<TensorInfo>& biases, |
| 333 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 334 | { |
Aron Virginas-Tar | 710f664 | 2019-11-27 14:48:32 +0000 | [diff] [blame] | 335 | if (!IS_QUANT_MULTIPLIER_SUPPORTED(input, output, weights)) |
James Conroy | b86a382 | 2019-11-19 15:28:58 +0000 | [diff] [blame] | 336 | { |
| 337 | return false; |
| 338 | } |
| 339 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 340 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClConvolution2dWorkloadValidate, |
| 341 | reasonIfUnsupported, |
| 342 | input, |
| 343 | output, |
| 344 | descriptor, |
| 345 | weights, |
| 346 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Jim Flynn | 983daec | 2019-05-29 16:20:16 +0100 | [diff] [blame] | 349 | bool ClLayerSupport::IsDequantizeSupported(const TensorInfo& input, |
| 350 | const TensorInfo& output, |
| 351 | Optional<std::string&> reasonIfUnsupported) const |
| 352 | { |
| 353 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDequantizeWorkloadValidate, |
| 354 | reasonIfUnsupported, |
| 355 | input, |
| 356 | output); |
| 357 | } |
| 358 | |
Aron Virginas-Tar | b280196 | 2019-09-30 11:24:53 +0100 | [diff] [blame] | 359 | bool ClLayerSupport::IsDepthToSpaceSupported(const TensorInfo& input, |
| 360 | const TensorInfo& output, |
| 361 | const DepthToSpaceDescriptor& descriptor, |
| 362 | Optional<std::string&> reasonIfUnsupported) const |
| 363 | { |
| 364 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthToSpaceWorkloadValidate, |
| 365 | reasonIfUnsupported, |
| 366 | input, |
| 367 | output, |
| 368 | descriptor); |
| 369 | } |
| 370 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 371 | bool ClLayerSupport::IsDepthwiseConvolutionSupported(const TensorInfo& input, |
| 372 | const TensorInfo& output, |
| 373 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 374 | const TensorInfo& weights, |
| 375 | const Optional<TensorInfo>& biases, |
| 376 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 377 | { |
Aron Virginas-Tar | 710f664 | 2019-11-27 14:48:32 +0000 | [diff] [blame] | 378 | if (!IS_QUANT_MULTIPLIER_SUPPORTED(input, output, weights)) |
James Conroy | b86a382 | 2019-11-19 15:28:58 +0000 | [diff] [blame] | 379 | { |
| 380 | return false; |
| 381 | } |
| 382 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 383 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 384 | reasonIfUnsupported, |
| 385 | input, |
| 386 | output, |
| 387 | descriptor, |
| 388 | weights, |
| 389 | biases); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 392 | bool ClLayerSupport::IsDilatedDepthwiseConvolutionSupported(const TensorInfo& input, |
| 393 | const TensorInfo& output, |
| 394 | const DepthwiseConvolution2dDescriptor& descriptor, |
| 395 | const TensorInfo& weights, |
| 396 | const Optional<TensorInfo>& biases, |
| 397 | Optional<std::string&> reasonIfUnsupported) const |
| 398 | { |
Aron Virginas-Tar | 710f664 | 2019-11-27 14:48:32 +0000 | [diff] [blame] | 399 | if (!IS_QUANT_MULTIPLIER_SUPPORTED(input, output, weights)) |
James Conroy | b86a382 | 2019-11-19 15:28:58 +0000 | [diff] [blame] | 400 | { |
| 401 | return false; |
| 402 | } |
| 403 | |
Pablo Tello | f0bd683 | 2019-04-26 17:58:13 +0100 | [diff] [blame] | 404 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDepthwiseConvolutionWorkloadValidate, |
| 405 | reasonIfUnsupported, |
| 406 | input, |
| 407 | output, |
| 408 | descriptor, |
| 409 | weights, |
| 410 | biases); |
| 411 | } |
| 412 | |
| 413 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 414 | bool ClLayerSupport::IsDivisionSupported(const TensorInfo& input0, |
| 415 | const TensorInfo& input1, |
| 416 | const TensorInfo& output, |
| 417 | Optional<std::string&> reasonIfUnsupported) const |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 418 | { |
| 419 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClDivisionWorkloadValidate, |
| 420 | reasonIfUnsupported, |
| 421 | input0, |
| 422 | input1, |
| 423 | output); |
| 424 | } |
| 425 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 426 | bool ClLayerSupport::IsElementwiseUnarySupported(const TensorInfo& input, |
| 427 | const TensorInfo& output, |
| 428 | const ElementwiseUnaryDescriptor& descriptor, |
| 429 | Optional<std::string&> reasonIfUnsupported) const |
| 430 | { |
| 431 | if (descriptor.m_Operation == UnaryOperation::Abs) |
| 432 | { |
| 433 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClAbsWorkloadValidate, |
| 434 | reasonIfUnsupported, |
| 435 | input, |
| 436 | output); |
| 437 | } |
| 438 | else if (descriptor.m_Operation == UnaryOperation::Rsqrt) |
| 439 | { |
| 440 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClRsqrtWorkloadValidate, |
| 441 | reasonIfUnsupported, |
| 442 | input, |
| 443 | output); |
| 444 | } |
| 445 | |
| 446 | return false; |
| 447 | } |
| 448 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 449 | bool ClLayerSupport::IsFloorSupported(const TensorInfo& input, |
| 450 | const TensorInfo& output, |
| 451 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 452 | { |
Sadik Armagan | 9be4916 | 2019-10-30 16:15:26 +0000 | [diff] [blame] | 453 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClFloorWorkloadValidate, |
| 454 | reasonIfUnsupported, |
| 455 | input, |
| 456 | output); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 459 | bool ClLayerSupport::IsFullyConnectedSupported(const TensorInfo& input, |
| 460 | const TensorInfo& output, |
| 461 | const TensorInfo& weights, |
| 462 | const TensorInfo& biases, |
| 463 | const FullyConnectedDescriptor& descriptor, |
| 464 | Optional<std::string&> reasonIfUnsupported) const |
| 465 | { |
| 466 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClFullyConnectedWorkloadValidate, |
| 467 | reasonIfUnsupported, |
| 468 | input, |
| 469 | output, |
| 470 | weights, |
| 471 | biases, |
| 472 | descriptor); |
| 473 | } |
| 474 | |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 475 | bool ClLayerSupport::IsGreaterSupported(const TensorInfo& input0, |
| 476 | const TensorInfo& input1, |
| 477 | const TensorInfo& output, |
| 478 | Optional<std::string&> reasonIfUnsupported) const |
| 479 | { |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 480 | ComparisonDescriptor descriptor(ComparisonOperation::Greater); |
| 481 | return IsComparisonSupported(input0, input1, output, descriptor, reasonIfUnsupported); |
Nattapat Chaimanowong | c6a41ff | 2019-01-29 09:56:02 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 484 | bool ClLayerSupport::IsInputSupported(const TensorInfo& input, |
| 485 | Optional<std::string&> reasonIfUnsupported) const |
| 486 | { |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 487 | return IsClBackendSupported(reasonIfUnsupported, input); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 488 | } |
| 489 | |
Aron Virginas-Tar | 8168f40 | 2019-10-04 13:10:16 +0100 | [diff] [blame] | 490 | bool ClLayerSupport::IsInstanceNormalizationSupported(const TensorInfo& input, |
| 491 | const TensorInfo& output, |
| 492 | const InstanceNormalizationDescriptor& descriptor, |
| 493 | Optional<std::string&> reasonIfUnsupported) const |
| 494 | { |
| 495 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClInstanceNormalizationWorkloadValidate, |
| 496 | reasonIfUnsupported, |
| 497 | input, |
| 498 | output, |
| 499 | descriptor); |
| 500 | } |
| 501 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 502 | bool ClLayerSupport::IsL2NormalizationSupported(const TensorInfo& input, |
| 503 | const TensorInfo& output, |
| 504 | const L2NormalizationDescriptor& descriptor, |
| 505 | Optional<std::string&> reasonIfUnsupported) const |
| 506 | { |
| 507 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClL2NormalizationWorkloadValidate, |
| 508 | reasonIfUnsupported, |
| 509 | input, |
| 510 | output, |
| 511 | descriptor); |
| 512 | } |
| 513 | |
| 514 | bool ClLayerSupport::IsLstmSupported(const TensorInfo& input, |
| 515 | const TensorInfo& outputStateIn, |
| 516 | const TensorInfo& cellStateIn, |
| 517 | const TensorInfo& scratchBuffer, |
| 518 | const TensorInfo& outputStateOut, |
| 519 | const TensorInfo& cellStateOut, |
| 520 | const TensorInfo& output, |
| 521 | const LstmDescriptor& descriptor, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 522 | const LstmInputParamsInfo& paramsInfo, |
| 523 | Optional<std::string&> reasonIfUnsupported) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 524 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 525 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClLstmFloatWorkloadValidate, |
| 526 | reasonIfUnsupported, |
| 527 | input, |
| 528 | outputStateIn, |
| 529 | cellStateIn, |
| 530 | scratchBuffer, |
| 531 | outputStateOut, |
| 532 | cellStateOut, |
| 533 | output, |
| 534 | descriptor, |
Jan Eilers | d01a83c | 2019-07-03 18:20:40 +0100 | [diff] [blame] | 535 | paramsInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 536 | } |
| 537 | |
keidav01 | a959ee5 | 2018-12-19 10:04:58 +0000 | [diff] [blame] | 538 | bool ClLayerSupport::IsMaximumSupported(const TensorInfo& input0, |
| 539 | const TensorInfo& input1, |
| 540 | const TensorInfo& output, |
| 541 | Optional<std::string&> reasonIfUnsupported) const |
| 542 | { |
| 543 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMaximumWorkloadValidate, |
| 544 | reasonIfUnsupported, |
| 545 | input0, |
| 546 | input1, |
| 547 | output); |
| 548 | } |
| 549 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 550 | bool ClLayerSupport::IsMeanSupported(const TensorInfo& input, |
| 551 | const TensorInfo& output, |
| 552 | const MeanDescriptor& descriptor, |
| 553 | Optional<std::string&> reasonIfUnsupported) const |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 554 | { |
Matteo Martincigh | 28dcab6 | 2018-10-19 16:40:03 +0100 | [diff] [blame] | 555 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMeanValidate, |
| 556 | reasonIfUnsupported, |
| 557 | input, |
| 558 | output, |
| 559 | descriptor); |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 560 | } |
| 561 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 562 | bool ClLayerSupport::IsMergerSupported(const std::vector<const TensorInfo*> inputs, |
Nikhil Raj | 8599a41 | 2018-11-19 14:51:07 +0000 | [diff] [blame] | 563 | const TensorInfo& output, |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 564 | const MergerDescriptor& descriptor, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 565 | Optional<std::string&> reasonIfUnsupported) const |
| 566 | { |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 567 | return IsConcatSupported(inputs, output, descriptor, reasonIfUnsupported); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 568 | } |
| 569 | |
saoste01 | 9292aa3 | 2019-01-08 13:55:59 +0000 | [diff] [blame] | 570 | bool ClLayerSupport::IsMinimumSupported(const TensorInfo& input0, |
| 571 | const TensorInfo& input1, |
| 572 | const TensorInfo& output, |
| 573 | Optional<std::string&> reasonIfUnsupported) const |
| 574 | { |
| 575 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMinimumWorkloadValidate, |
| 576 | reasonIfUnsupported, |
| 577 | input0, |
| 578 | input1, |
| 579 | output); |
| 580 | } |
| 581 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 582 | bool ClLayerSupport::IsMultiplicationSupported(const TensorInfo& input0, |
| 583 | const TensorInfo& input1, |
| 584 | const TensorInfo& output, |
| 585 | Optional<std::string&> reasonIfUnsupported) const |
| 586 | { |
| 587 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClMultiplicationWorkloadValidate, |
| 588 | reasonIfUnsupported, |
| 589 | input0, |
| 590 | input1, |
| 591 | output); |
| 592 | } |
| 593 | |
| 594 | bool ClLayerSupport::IsNormalizationSupported(const TensorInfo& input, |
| 595 | const TensorInfo& output, |
| 596 | const NormalizationDescriptor& descriptor, |
| 597 | Optional<std::string&> reasonIfUnsupported) const |
| 598 | { |
| 599 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClNormalizationWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
| 600 | } |
| 601 | |
| 602 | bool ClLayerSupport::IsOutputSupported(const TensorInfo& output, |
| 603 | Optional<std::string&> reasonIfUnsupported) const |
| 604 | { |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 605 | return IsClBackendSupported(reasonIfUnsupported, output); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | bool ClLayerSupport::IsPadSupported(const TensorInfo& input, |
| 609 | const TensorInfo& output, |
| 610 | const PadDescriptor& descriptor, |
| 611 | Optional<std::string&> reasonIfUnsupported) const |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 612 | { |
| 613 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPadValidate, |
| 614 | reasonIfUnsupported, |
| 615 | input, |
| 616 | output, |
| 617 | descriptor); |
| 618 | } |
| 619 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 620 | bool ClLayerSupport::IsPermuteSupported(const TensorInfo& input, |
| 621 | const TensorInfo& output, |
| 622 | const PermuteDescriptor& descriptor, |
| 623 | Optional<std::string&> reasonIfUnsupported) const |
| 624 | { |
Matthew Bentham | 9820d30 | 2019-11-27 17:24:47 +0000 | [diff] [blame] | 625 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPermuteWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 626 | } |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 627 | |
| 628 | bool ClLayerSupport::IsPooling2dSupported(const TensorInfo& input, |
| 629 | const TensorInfo& output, |
| 630 | const Pooling2dDescriptor& descriptor, |
| 631 | Optional<std::string&> reasonIfUnsupported) const |
| 632 | { |
| 633 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPooling2dWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
| 634 | } |
| 635 | |
Nikhil Raj | 91e4c6d | 2019-07-05 12:22:58 +0100 | [diff] [blame] | 636 | bool ClLayerSupport::IsPreluSupported(const armnn::TensorInfo &input, |
| 637 | const armnn::TensorInfo &alpha, |
| 638 | const armnn::TensorInfo &output, |
| 639 | armnn::Optional<std::string &> reasonIfUnsupported) const |
| 640 | { |
| 641 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClPreluWorkloadValidate, reasonIfUnsupported, input, alpha, output); |
| 642 | } |
| 643 | |
Ferran Balaguer | 737d9ff | 2019-08-01 09:58:08 +0100 | [diff] [blame] | 644 | bool ClLayerSupport::IsQuantizedLstmSupported(const TensorInfo& input, |
| 645 | const TensorInfo& previousCellStateIn, |
| 646 | const TensorInfo& previousOutputIn, |
| 647 | const TensorInfo& cellStateOut, |
| 648 | const TensorInfo& output, |
| 649 | const QuantizedLstmInputParamsInfo& paramsInfo, |
| 650 | Optional<std::string&> reasonIfUnsupported) const |
| 651 | { |
| 652 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClQuantizedLstmWorkloadValidate, |
| 653 | reasonIfUnsupported, |
| 654 | input, |
| 655 | previousCellStateIn, |
| 656 | previousOutputIn, |
| 657 | cellStateOut, |
| 658 | output, |
| 659 | paramsInfo); |
| 660 | } |
| 661 | |
Sadik Armagan | 20ec249 | 2019-05-31 09:09:44 +0100 | [diff] [blame] | 662 | bool ClLayerSupport::IsQuantizeSupported(const TensorInfo& input, |
| 663 | const TensorInfo& output, |
| 664 | Optional<std::string&> reasonIfUnsupported) const |
| 665 | { |
| 666 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClQuantizeWorkloadValidate, |
| 667 | reasonIfUnsupported, |
| 668 | input, |
| 669 | output); |
| 670 | } |
| 671 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 672 | bool ClLayerSupport::IsReshapeSupported(const TensorInfo& input, |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 673 | const ReshapeDescriptor& descriptor, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 674 | Optional<std::string&> reasonIfUnsupported) const |
| 675 | { |
| 676 | ignore_unused(input); |
Matteo Martincigh | 992d6dc | 2019-01-10 17:34:20 +0000 | [diff] [blame] | 677 | ignore_unused(descriptor); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 678 | ignore_unused(reasonIfUnsupported); |
| 679 | return true; |
| 680 | } |
| 681 | |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 682 | bool ClLayerSupport::IsResizeSupported(const TensorInfo& input, |
| 683 | const TensorInfo& output, |
| 684 | const ResizeDescriptor& descriptor, |
| 685 | Optional<std::string&> reasonIfUnsupported) const |
| 686 | { |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 687 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClResizeWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
Aron Virginas-Tar | 169d2f1 | 2019-07-01 19:01:44 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 690 | bool ClLayerSupport::IsResizeBilinearSupported(const TensorInfo& input, |
Sadik Armagan | c625f00 | 2018-12-17 11:32:16 +0000 | [diff] [blame] | 691 | const TensorInfo& output, |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 692 | Optional<std::string&> reasonIfUnsupported) const |
| 693 | { |
Aron Virginas-Tar | cc0cefb | 2019-07-02 17:25:47 +0100 | [diff] [blame] | 694 | ResizeDescriptor descriptor; |
| 695 | descriptor.m_Method = ResizeMethod::Bilinear; |
| 696 | descriptor.m_DataLayout = DataLayout::NCHW; |
| 697 | |
| 698 | const TensorShape& outputShape = output.GetShape(); |
| 699 | descriptor.m_TargetHeight = outputShape[2]; |
| 700 | descriptor.m_TargetWidth = outputShape[3]; |
| 701 | |
| 702 | return IsResizeSupported(input, output, descriptor, reasonIfUnsupported); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 703 | } |
| 704 | |
Aron Virginas-Tar | 1a763dd | 2019-09-10 12:32:08 +0100 | [diff] [blame] | 705 | bool ClLayerSupport::IsRsqrtSupported(const TensorInfo& input, |
| 706 | const TensorInfo& output, |
| 707 | Optional<std::string&> reasonIfUnsupported) const |
| 708 | { |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 709 | ElementwiseUnaryDescriptor descriptor(UnaryOperation::Rsqrt); |
| 710 | return IsElementwiseUnarySupported(input, output, descriptor, reasonIfUnsupported); |
Aron Virginas-Tar | 1a763dd | 2019-09-10 12:32:08 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Aron Virginas-Tar | 94c4fef | 2019-11-25 15:37:08 +0000 | [diff] [blame] | 713 | bool ClLayerSupport::IsSliceSupported(const TensorInfo& input, |
| 714 | const TensorInfo& output, |
| 715 | const SliceDescriptor& descriptor, |
| 716 | Optional<std::string&> reasonIfUnsupported) const |
| 717 | { |
| 718 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSliceWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
| 719 | } |
| 720 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 721 | bool ClLayerSupport::IsSoftmaxSupported(const TensorInfo& input, |
| 722 | const TensorInfo& output, |
| 723 | const SoftmaxDescriptor& descriptor, |
| 724 | Optional<std::string&> reasonIfUnsupported) const |
| 725 | { |
Francis Murtagh | 3b93835 | 2019-07-26 15:44:17 +0100 | [diff] [blame] | 726 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSoftmaxWorkloadValidate, reasonIfUnsupported, input, output, descriptor); |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 727 | } |
| 728 | |
Sadik Armagan | f446432 | 2018-12-20 16:19:12 +0000 | [diff] [blame] | 729 | bool ClLayerSupport::IsSpaceToBatchNdSupported(const TensorInfo& input, |
| 730 | const TensorInfo& output, |
| 731 | const SpaceToBatchNdDescriptor& descriptor, |
| 732 | Optional<std::string&> reasonIfUnsupported) const |
| 733 | { |
| 734 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSpaceToBatchNdWorkloadValidate, |
| 735 | reasonIfUnsupported, |
| 736 | input, |
| 737 | output, |
| 738 | descriptor); |
| 739 | } |
| 740 | |
James Conroy | d2aa85e | 2019-07-01 17:12:40 +0100 | [diff] [blame] | 741 | bool ClLayerSupport::IsSpaceToDepthSupported(const TensorInfo& input, |
| 742 | const TensorInfo& output, |
| 743 | const SpaceToDepthDescriptor& descriptor, |
| 744 | Optional<std::string&> reasonIfUnsupported) const |
| 745 | { |
| 746 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSpaceToDepthWorkloadValidate, |
| 747 | reasonIfUnsupported, |
| 748 | input, |
| 749 | output, |
| 750 | descriptor); |
| 751 | } |
| 752 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 753 | bool ClLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 754 | const ViewsDescriptor& descriptor, |
| 755 | Optional<std::string&> reasonIfUnsupported) const |
| 756 | { |
| 757 | ignore_unused(descriptor); |
| 758 | return IsSupportedForDataTypeCl(reasonIfUnsupported, |
| 759 | input.GetDataType(), |
| 760 | &TrueFunc<>, |
| 761 | &TrueFunc<>); |
| 762 | } |
| 763 | |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 764 | bool ClLayerSupport::IsSplitterSupported(const TensorInfo& input, |
| 765 | const std::vector<std::reference_wrapper<TensorInfo>>& outputs, |
| 766 | const ViewsDescriptor& descriptor, |
| 767 | Optional<std::string&> reasonIfUnsupported) const |
| 768 | { |
Narumol Prangnawarat | 7413583 | 2019-05-23 15:07:33 +0100 | [diff] [blame] | 769 | #if defined(ARMCOMPUTECL_ENABLED) |
| 770 | // Split along the last dimension, cannot use sub-tensors |
| 771 | // as width and height of the sub-tensors do not match |
| 772 | // the width and height of the parent tensor |
| 773 | // in case of input with more than 2D. |
| 774 | std::set<unsigned int> splitAxis = ComputeSplitAxis(descriptor, input.GetShape()); |
| 775 | if (descriptor.GetNumDimensions() > 2 && splitAxis.size() == 1 && |
| 776 | *splitAxis.begin() == descriptor.GetNumDimensions() - 1 ) |
| 777 | { |
| 778 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSplitterWorkloadValidate, |
| 779 | reasonIfUnsupported, |
| 780 | input, |
| 781 | outputs, |
| 782 | *splitAxis.begin()); |
| 783 | } |
| 784 | #endif |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 785 | boost::ignore_unused(descriptor); |
Narumol Prangnawarat | 7413583 | 2019-05-23 15:07:33 +0100 | [diff] [blame] | 786 | for (auto output : outputs) |
| 787 | { |
| 788 | if (!input.IsTypeSpaceMatch(output)) // Cannot use sub-tensors if the types are not same space |
| 789 | { |
| 790 | SetValueChecked(reasonIfUnsupported, "Cl Splitter: Types and quantization parameters must match."); |
| 791 | return false; |
| 792 | } |
| 793 | } |
| 794 | return true; |
Narumol Prangnawarat | 15eb583 | 2019-05-20 15:31:05 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Matthew Jackson | d516610 | 2019-07-31 14:06:28 +0100 | [diff] [blame] | 797 | bool ClLayerSupport::IsStackSupported(const std::vector<const TensorInfo*>& inputs, |
| 798 | const TensorInfo& output, |
| 799 | const StackDescriptor& descriptor, |
| 800 | Optional<std::string&> reasonIfUnsupported) const |
| 801 | { |
| 802 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClStackWorkloadValidate, |
| 803 | reasonIfUnsupported, |
| 804 | inputs, |
| 805 | output, |
| 806 | descriptor); |
| 807 | } |
| 808 | |
keidav01 | d74dc91 | 2018-12-10 18:16:07 +0000 | [diff] [blame] | 809 | bool ClLayerSupport::IsStridedSliceSupported(const TensorInfo& input, |
| 810 | const TensorInfo& output, |
| 811 | const StridedSliceDescriptor& descriptor, |
| 812 | Optional<std::string&> reasonIfUnsupported) const |
| 813 | { |
| 814 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClStridedSliceWorkloadValidate, |
| 815 | reasonIfUnsupported, |
| 816 | input, |
| 817 | output, |
| 818 | descriptor); |
| 819 | } |
| 820 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 821 | bool ClLayerSupport::IsSubtractionSupported(const TensorInfo& input0, |
| 822 | const TensorInfo& input1, |
| 823 | const TensorInfo& output, |
| 824 | Optional<std::string&> reasonIfUnsupported) const |
| 825 | { |
| 826 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClSubtractionValidate, |
| 827 | reasonIfUnsupported, |
| 828 | input0, |
| 829 | input1, |
| 830 | output); |
| 831 | } |
| 832 | |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 833 | bool ClLayerSupport::IsTransposeConvolution2dSupported(const TensorInfo& input, |
| 834 | const TensorInfo& output, |
| 835 | const TransposeConvolution2dDescriptor& descriptor, |
| 836 | const TensorInfo& weights, |
| 837 | const Optional<TensorInfo>& biases, |
| 838 | Optional<std::string&> reasonIfUnsupported) const |
| 839 | { |
Aron Virginas-Tar | 710f664 | 2019-11-27 14:48:32 +0000 | [diff] [blame] | 840 | if (!IS_QUANT_MULTIPLIER_SUPPORTED(input, output, weights)) |
James Conroy | b86a382 | 2019-11-19 15:28:58 +0000 | [diff] [blame] | 841 | { |
| 842 | return false; |
| 843 | } |
| 844 | |
Aron Virginas-Tar | 7a3e2fe | 2019-06-27 18:54:47 +0100 | [diff] [blame] | 845 | FORWARD_WORKLOAD_VALIDATE_FUNC(ClTransposeConvolution2dWorkloadValidate, |
| 846 | reasonIfUnsupported, |
| 847 | input, |
| 848 | output, |
| 849 | descriptor, |
| 850 | weights, |
| 851 | biases); |
| 852 | } |
| 853 | |
Aron Virginas-Tar | bcf9f16 | 2018-10-15 11:47:37 +0100 | [diff] [blame] | 854 | } // namespace armnn |