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( |
| 61 | "TOSA Reference Operator: Op_ADD for input: Op_ADD_input0_") != std::string::npos); |
| 62 | REQUIRE(reasonIfNotSupported.find( |
| 63 | "TOSA Reference Operator: Op_ADD for input: Op_ADD_input1_") != std::string::npos); |
| 64 | REQUIRE(reasonIfNotSupported.find( |
| 65 | "TOSA Reference Operator: Op_ADD for output: Op_ADD_output0_") != std::string::npos); |
| 66 | } |
| 67 | |
| 68 | TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d") |
| 69 | { |
| 70 | armnn::TensorShape inShape = {1,1,3,4}; |
| 71 | armnn::TensorShape outShape = {1,1,3,4}; |
| 72 | armnn::TensorInfo in(inShape, armnn::DataType::Float32); |
| 73 | armnn::TensorInfo out(outShape, armnn::DataType::Float32); |
| 74 | |
| 75 | armnn::Pooling2dDescriptor desc; |
| 76 | armnn::TosaRefLayerSupport supportChecker; |
| 77 | std::string reasonIfNotSupported; |
| 78 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 79 | {in, out}, |
| 80 | desc, |
| 81 | armnn::EmptyOptional(), |
| 82 | armnn::EmptyOptional(), |
| 83 | reasonIfNotSupported); |
| 84 | |
| 85 | CHECK(supported); |
| 86 | } |
| 87 | |
| 88 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue") |
| 89 | { |
| 90 | armnn::TensorShape inShape = {1,1,3,4}; |
| 91 | armnn::TensorShape outShape = {1,1,3,4}; |
| 92 | armnn::TensorInfo in(inShape, armnn::DataType::Float32); |
| 93 | armnn::TensorInfo out(outShape, armnn::DataType::Float32); |
| 94 | |
| 95 | armnn::Pooling2dDescriptor desc; |
| 96 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 97 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 98 | |
| 99 | armnn::TosaRefLayerSupport supportChecker; |
| 100 | std::string reasonIfNotSupported; |
| 101 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 102 | {in, out}, |
| 103 | desc, |
| 104 | armnn::EmptyOptional(), |
| 105 | armnn::EmptyOptional(), |
| 106 | reasonIfNotSupported); |
| 107 | |
| 108 | CHECK(supported); |
| 109 | } |
| 110 | |
| 111 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_InputOutputDatatypeDifferent") |
| 112 | { |
| 113 | armnn::TensorShape inShape = {1,1,3,4}; |
| 114 | armnn::TensorShape outShape = {1,1,3,4}; |
| 115 | armnn::TensorInfo in(inShape, armnn::DataType::QAsymmS8); |
| 116 | armnn::TensorInfo out(outShape, armnn::DataType::Signed32); |
| 117 | |
| 118 | armnn::Pooling2dDescriptor desc; |
| 119 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 120 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 121 | |
| 122 | armnn::TosaRefLayerSupport supportChecker; |
| 123 | std::string reasonIfNotSupported; |
| 124 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 125 | {in, out}, |
| 126 | desc, |
| 127 | armnn::EmptyOptional(), |
| 128 | armnn::EmptyOptional(), |
| 129 | reasonIfNotSupported); |
| 130 | |
| 131 | CHECK(supported); |
| 132 | } |
| 133 | |
| 134 | TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported") |
| 135 | { |
| 136 | armnn::TensorShape inShape = {1,1,3,4}; |
| 137 | armnn::TensorShape outShape = {1,1,3,4}; |
| 138 | armnn::TensorInfo in(inShape, armnn::DataType::Signed64); |
| 139 | armnn::TensorInfo out(outShape, armnn::DataType::Signed64); |
| 140 | |
| 141 | armnn::Pooling2dDescriptor desc; |
| 142 | armnn::TosaRefLayerSupport supportChecker; |
| 143 | std::string reasonIfNotSupported; |
| 144 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 145 | {in, out}, |
| 146 | desc, |
| 147 | armnn::EmptyOptional(), |
| 148 | armnn::EmptyOptional(), |
| 149 | reasonIfNotSupported); |
| 150 | |
| 151 | CHECK(!supported); |
| 152 | REQUIRE(reasonIfNotSupported.find( |
| 153 | "TOSA Reference Operator: Op_MAX_POOL2D for input: Op_MAX_POOL2D_input0_") != std::string::npos); |
| 154 | REQUIRE(reasonIfNotSupported.find( |
| 155 | "TOSA Reference Operator: Op_MAX_POOL2D for output: Op_MAX_POOL2D_output0_") != std::string::npos); |
| 156 | } |
| 157 | |
| 158 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent") |
| 159 | { |
| 160 | armnn::TensorShape inShape = {1,1,3,4}; |
| 161 | armnn::TensorShape outShape = {1,1,3,4}; |
| 162 | armnn::TensorInfo in(inShape, armnn::DataType::Float32); |
| 163 | armnn::TensorInfo out(outShape, armnn::DataType::Float16); |
| 164 | |
| 165 | armnn::Pooling2dDescriptor desc; |
| 166 | desc.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 167 | desc.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 168 | |
| 169 | armnn::TosaRefLayerSupport supportChecker; |
| 170 | std::string reasonIfNotSupported; |
| 171 | auto supported = supportChecker.IsLayerSupported(armnn::LayerType::Pooling2d, |
| 172 | {in, out}, |
| 173 | desc, |
| 174 | armnn::EmptyOptional(), |
| 175 | armnn::EmptyOptional(), |
| 176 | reasonIfNotSupported); |
| 177 | |
| 178 | CHECK(!supported); |
| 179 | REQUIRE(reasonIfNotSupported.find( |
| 180 | "TOSA Reference Operator: Op_AVG_POOL2D for input: Op_PAD_intermediate0_") != std::string::npos); |
| 181 | REQUIRE(reasonIfNotSupported.find( |
| 182 | " and output: Op_AVG_POOL2D_output0_") != std::string::npos); |
| 183 | REQUIRE(reasonIfNotSupported.find( |
| 184 | " 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] | 185 | } |
| 186 | |
| 187 | } |