Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | |
| 7 | #include <armnn/Optional.hpp> |
| 8 | #include <armnn/Types.hpp> |
| 9 | #include <tosaReference/TosaRefLayerSupport.hpp> |
| 10 | |
| 11 | #include <doctest/doctest.h> |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | TEST_SUITE("TosaRefLayerSupported") |
| 16 | { |
| 17 | |
| 18 | TEST_CASE("IsLayerSupportedTosaReferenceAddition") |
| 19 | { |
| 20 | armnn::TensorShape shape0 = {1,1,3,4}; |
| 21 | armnn::TensorShape shape1 = {4}; |
| 22 | armnn::TensorShape outShape = {1,1,3,4}; |
| 23 | armnn::TensorInfo in0(shape0, armnn::DataType::Float32); |
| 24 | armnn::TensorInfo in1(shape1, armnn::DataType::Float32); |
| 25 | armnn::TensorInfo out(outShape, armnn::DataType::Float32); |
| 26 | |
| 27 | armnn::BaseDescriptor desc; |
| 28 | armnn::TosaRefLayerSupport supportChecker; |
| 29 | std::string reasonIfNotSupported; |
| 30 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Addition, |
| 31 | {in0, in1, out}, |
| 32 | desc, |
| 33 | armnn::EmptyOptional(), |
| 34 | armnn::EmptyOptional(), |
| 35 | reasonIfNotSupported); |
| 36 | |
| 37 | CHECK(supported); |
| 38 | } |
| 39 | |
| 40 | TEST_CASE("IsLayerSupportedTosaReferenceAdditionUnsupported") |
| 41 | { |
| 42 | armnn::TensorShape shape0 = {1,1,3,4}; |
| 43 | armnn::TensorShape shape1 = {4}; |
| 44 | armnn::TensorShape outShape = {1,1,3,4}; |
| 45 | armnn::TensorInfo in0(shape0, armnn::DataType::Signed64); |
| 46 | armnn::TensorInfo in1(shape1, armnn::DataType::Signed64); |
| 47 | armnn::TensorInfo out(outShape, armnn::DataType::Signed64); |
| 48 | |
| 49 | armnn::BaseDescriptor desc; |
| 50 | armnn::TosaRefLayerSupport supportChecker; |
| 51 | std::string reasonIfNotSupported; |
| 52 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Addition, |
| 53 | {in0, in1, out}, |
| 54 | desc, |
| 55 | armnn::EmptyOptional(), |
| 56 | armnn::EmptyOptional(), |
| 57 | reasonIfNotSupported); |
| 58 | |
| 59 | CHECK(!supported); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 60 | REQUIRE(reasonIfNotSupported.find( |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame^] | 61 | "TOSA Reference Operator: Op_ADD for input: input0_") != std::string::npos); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 62 | REQUIRE(reasonIfNotSupported.find( |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame^] | 63 | "TOSA Reference Operator: Op_ADD for input: input1_") != std::string::npos); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 64 | REQUIRE(reasonIfNotSupported.find( |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame^] | 65 | "TOSA Reference Operator: Op_ADD for output: output0_") != std::string::npos); |
| 66 | } |
| 67 | |
| 68 | TEST_CASE("IsLayerSupportedTosaReferenceConstant") |
| 69 | { |
| 70 | armnn::TensorInfo outputInfo({1,1,3,4}, armnn::DataType::Float32); |
| 71 | |
| 72 | armnn::TosaRefLayerSupport supportChecker; |
| 73 | std::string reasonIfNotSupported; |
| 74 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Constant, |
| 75 | {outputInfo}, |
| 76 | armnn::BaseDescriptor(), |
| 77 | armnn::EmptyOptional(), |
| 78 | armnn::EmptyOptional(), |
| 79 | reasonIfNotSupported); |
| 80 | |
| 81 | CHECK(supported); |
| 82 | } |
| 83 | |
| 84 | TEST_CASE("IsLayerSupportedTosaReferenceConstantUnsupported") |
| 85 | { |
| 86 | armnn::TensorInfo outputInfo({1,1,3,4}, armnn::DataType::Signed64); |
| 87 | |
| 88 | armnn::TosaRefLayerSupport supportChecker; |
| 89 | std::string reasonIfNotSupported; |
| 90 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Constant, |
| 91 | {outputInfo}, |
| 92 | armnn::BaseDescriptor(), |
| 93 | armnn::EmptyOptional(), |
| 94 | armnn::EmptyOptional(), |
| 95 | reasonIfNotSupported); |
| 96 | |
| 97 | CHECK(!supported); |
| 98 | REQUIRE(reasonIfNotSupported.find( |
| 99 | "TOSA Reference Operator: Op_CONST for output: constant_") != std::string::npos); |
| 100 | } |
| 101 | |
| 102 | TEST_CASE("IsLayerSupportedTosaReferenceConv2d") |
| 103 | { |
| 104 | armnn::TensorInfo inputInfo ({ 1, 5, 5, 1 }, armnn::DataType::Float32); |
| 105 | armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32); |
| 106 | armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32); |
| 107 | armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32); |
| 108 | |
| 109 | armnn::Convolution2dDescriptor desc; |
| 110 | desc.m_BiasEnabled = true; |
| 111 | |
| 112 | armnn::TosaRefLayerSupport supportChecker; |
| 113 | std::string reasonIfNotSupported; |
| 114 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Convolution2d, |
| 115 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 116 | desc, |
| 117 | armnn::EmptyOptional(), |
| 118 | armnn::EmptyOptional(), |
| 119 | reasonIfNotSupported); |
| 120 | |
| 121 | CHECK(supported); |
| 122 | } |
| 123 | |
| 124 | TEST_CASE("IsLayerSupportedTosaReferenceConv2dUnsupported") |
| 125 | { |
| 126 | // If inputs and weights are Fp32, output must match. |
| 127 | armnn::TensorInfo inputInfo ({ 1, 5, 5, 1 }, armnn::DataType::Float32); |
| 128 | armnn::TensorInfo outputInfo({ 1, 3, 3, 1 }, armnn::DataType::Signed64); |
| 129 | armnn::TensorInfo weightsInfo({ 1, 3, 3, 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 130 | armnn::TensorInfo biasesInfo ({ 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
| 131 | |
| 132 | armnn::Convolution2dDescriptor desc; |
| 133 | desc.m_BiasEnabled = true; |
| 134 | |
| 135 | armnn::TosaRefLayerSupport supportChecker; |
| 136 | std::string reasonIfNotSupported; |
| 137 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Convolution2d, |
| 138 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 139 | desc, |
| 140 | armnn::EmptyOptional(), |
| 141 | armnn::EmptyOptional(), |
| 142 | reasonIfNotSupported); |
| 143 | |
| 144 | CHECK(!supported); |
| 145 | REQUIRE(reasonIfNotSupported.find( |
| 146 | "TOSA Reference Operator: Op_CONV2D for input 0: input0_") != std::string::npos); |
| 147 | REQUIRE(reasonIfNotSupported.find( |
| 148 | "input 1: input1_") != std::string::npos); |
| 149 | REQUIRE(reasonIfNotSupported.find( |
| 150 | "and output: output0_") != std::string::npos); |
| 151 | REQUIRE(reasonIfNotSupported.find( |
| 152 | "has an unsupported input data type combination.") != std::string::npos); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d") |
| 156 | { |
| 157 | armnn::TensorShape inShape = {1,1,3,4}; |
| 158 | armnn::TensorShape outShape = {1,1,3,4}; |
| 159 | armnn::TensorInfo in(inShape, armnn::DataType::Float32); |
| 160 | armnn::TensorInfo out(outShape, armnn::DataType::Float32); |
| 161 | |
| 162 | armnn::Pooling2dDescriptor desc; |
| 163 | armnn::TosaRefLayerSupport supportChecker; |
| 164 | std::string reasonIfNotSupported; |
| 165 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 166 | {in, out}, |
| 167 | desc, |
| 168 | armnn::EmptyOptional(), |
| 169 | armnn::EmptyOptional(), |
| 170 | reasonIfNotSupported); |
| 171 | |
| 172 | CHECK(supported); |
| 173 | } |
| 174 | |
| 175 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue") |
| 176 | { |
| 177 | armnn::TensorShape inShape = {1,1,3,4}; |
| 178 | armnn::TensorShape outShape = {1,1,3,4}; |
| 179 | armnn::TensorInfo in(inShape, armnn::DataType::Float32); |
| 180 | armnn::TensorInfo out(outShape, armnn::DataType::Float32); |
| 181 | |
| 182 | armnn::Pooling2dDescriptor desc; |
| 183 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 184 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 185 | |
| 186 | armnn::TosaRefLayerSupport supportChecker; |
| 187 | std::string reasonIfNotSupported; |
| 188 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 189 | {in, out}, |
| 190 | desc, |
| 191 | armnn::EmptyOptional(), |
| 192 | armnn::EmptyOptional(), |
| 193 | reasonIfNotSupported); |
| 194 | |
| 195 | CHECK(supported); |
| 196 | } |
| 197 | |
| 198 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_InputOutputDatatypeDifferent") |
| 199 | { |
| 200 | armnn::TensorShape inShape = {1,1,3,4}; |
| 201 | armnn::TensorShape outShape = {1,1,3,4}; |
| 202 | armnn::TensorInfo in(inShape, armnn::DataType::QAsymmS8); |
| 203 | armnn::TensorInfo out(outShape, armnn::DataType::Signed32); |
| 204 | |
| 205 | armnn::Pooling2dDescriptor desc; |
| 206 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 207 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 208 | |
| 209 | armnn::TosaRefLayerSupport supportChecker; |
| 210 | std::string reasonIfNotSupported; |
| 211 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 212 | {in, out}, |
| 213 | desc, |
| 214 | armnn::EmptyOptional(), |
| 215 | armnn::EmptyOptional(), |
| 216 | reasonIfNotSupported); |
| 217 | |
| 218 | CHECK(supported); |
| 219 | } |
| 220 | |
| 221 | TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported") |
| 222 | { |
| 223 | armnn::TensorShape inShape = {1,1,3,4}; |
| 224 | armnn::TensorShape outShape = {1,1,3,4}; |
| 225 | armnn::TensorInfo in(inShape, armnn::DataType::Signed64); |
| 226 | armnn::TensorInfo out(outShape, armnn::DataType::Signed64); |
| 227 | |
| 228 | armnn::Pooling2dDescriptor desc; |
| 229 | armnn::TosaRefLayerSupport supportChecker; |
| 230 | std::string reasonIfNotSupported; |
| 231 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 232 | {in, out}, |
| 233 | desc, |
| 234 | armnn::EmptyOptional(), |
| 235 | armnn::EmptyOptional(), |
| 236 | reasonIfNotSupported); |
| 237 | |
| 238 | CHECK(!supported); |
| 239 | REQUIRE(reasonIfNotSupported.find( |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame^] | 240 | "TOSA Reference Operator: Op_MAX_POOL2D for input: input0_") != std::string::npos); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 241 | REQUIRE(reasonIfNotSupported.find( |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame^] | 242 | "TOSA Reference Operator: Op_MAX_POOL2D for output: output0_") != std::string::npos); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent") |
| 246 | { |
| 247 | armnn::TensorShape inShape = {1,1,3,4}; |
| 248 | armnn::TensorShape outShape = {1,1,3,4}; |
| 249 | armnn::TensorInfo in(inShape, armnn::DataType::Float32); |
| 250 | armnn::TensorInfo out(outShape, armnn::DataType::Float16); |
| 251 | |
| 252 | armnn::Pooling2dDescriptor desc; |
| 253 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 254 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 255 | |
| 256 | armnn::TosaRefLayerSupport supportChecker; |
| 257 | std::string reasonIfNotSupported; |
| 258 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 259 | {in, out}, |
| 260 | desc, |
| 261 | armnn::EmptyOptional(), |
| 262 | armnn::EmptyOptional(), |
| 263 | reasonIfNotSupported); |
| 264 | |
| 265 | CHECK(!supported); |
| 266 | REQUIRE(reasonIfNotSupported.find( |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame^] | 267 | "TOSA Reference Operator: Op_AVG_POOL2D for input: intermediate0_") != std::string::npos); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 268 | REQUIRE(reasonIfNotSupported.find( |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame^] | 269 | " and output: output0_") != std::string::npos); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 270 | REQUIRE(reasonIfNotSupported.find( |
| 271 | " has an unsupported input data type: 8 to output data type: 10") != std::string::npos); |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | } |