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 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 15 | using namespace armnn; |
| 16 | |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 17 | TEST_SUITE("TosaRefLayerSupported") |
| 18 | { |
| 19 | |
| 20 | TEST_CASE("IsLayerSupportedTosaReferenceAddition") |
| 21 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 22 | TensorShape shape0 = {1,1,3,4}; |
Matthew Sloyan | 67fd526 | 2022-12-07 19:28:18 +0000 | [diff] [blame] | 23 | TensorShape shape1 = {1,1,3,4}; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 24 | TensorShape outShape = {1,1,3,4}; |
| 25 | TensorInfo in0(shape0, DataType::Float32); |
| 26 | TensorInfo in1(shape1, DataType::Float32); |
| 27 | TensorInfo out(outShape, DataType::Float32); |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 28 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 29 | BaseDescriptor desc; |
| 30 | TosaRefLayerSupport supportChecker; |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 31 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 32 | auto supported = supportChecker.IsLayerSupported(LayerType::Addition, |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 33 | {in0, in1, out}, |
| 34 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 35 | EmptyOptional(), |
| 36 | EmptyOptional(), |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 37 | reasonIfNotSupported); |
| 38 | |
| 39 | CHECK(supported); |
| 40 | } |
| 41 | |
| 42 | TEST_CASE("IsLayerSupportedTosaReferenceAdditionUnsupported") |
| 43 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 44 | TensorShape shape0 = {1,1,3,4}; |
| 45 | TensorShape shape1 = {4}; |
| 46 | TensorShape outShape = {1,1,3,4}; |
| 47 | TensorInfo in0(shape0, DataType::Signed64); |
| 48 | TensorInfo in1(shape1, DataType::Signed64); |
| 49 | TensorInfo out(outShape, DataType::Signed64); |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 50 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 51 | BaseDescriptor desc; |
| 52 | TosaRefLayerSupport supportChecker; |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 53 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 54 | auto supported = supportChecker.IsLayerSupported(LayerType::Addition, |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 55 | {in0, in1, out}, |
| 56 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 57 | EmptyOptional(), |
| 58 | EmptyOptional(), |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 59 | reasonIfNotSupported); |
| 60 | |
| 61 | CHECK(!supported); |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Kevin May | 5b58e31 | 2022-12-15 10:15:21 +0000 | [diff] [blame^] | 64 | TEST_CASE("IsLayerSupportedTosaReferenceConcat") |
| 65 | { |
| 66 | TensorShape input0Shape = { 2, 3, 2, 2 }; |
| 67 | TensorShape input1Shape = { 2, 3, 2, 2 }; |
| 68 | TensorShape outputShape = { 2, 6, 2, 2 }; |
| 69 | TensorInfo input0Info(input0Shape, DataType::Float32); |
| 70 | TensorInfo input1Info(input1Shape, DataType::Float32); |
| 71 | TensorInfo outputInfo(outputShape, DataType::Float32); |
| 72 | |
| 73 | OriginsDescriptor descriptor; |
| 74 | std::vector<TensorShape> shapes = {input0Shape, input1Shape} ; |
| 75 | unsigned int concatAxis = 1; |
| 76 | descriptor = CreateDescriptorForConcatenation(shapes.begin(), shapes.end(), concatAxis); |
| 77 | |
| 78 | TosaRefLayerSupport supportChecker; |
| 79 | std::string reasonIfNotSupported; |
| 80 | auto supported = supportChecker.IsLayerSupported(LayerType::Concat, |
| 81 | {input0Info, input1Info, outputInfo}, |
| 82 | descriptor, |
| 83 | EmptyOptional(), |
| 84 | EmptyOptional(), |
| 85 | reasonIfNotSupported); |
| 86 | |
| 87 | CHECK(supported); |
| 88 | } |
| 89 | |
| 90 | TEST_CASE("IsLayerSupportedTosaReferenceConcatUnsupported") |
| 91 | { |
| 92 | TensorShape input0Shape = { 2, 3, 2, 2 }; |
| 93 | TensorShape input1Shape = { 2, 3, 2, 2 }; |
| 94 | TensorShape outputShape = { 2, 6, 2, 2 }; |
| 95 | TensorInfo input0Info(input0Shape, armnn::DataType::QAsymmU8); |
| 96 | TensorInfo input1Info(input1Shape, armnn::DataType::QAsymmU8); |
| 97 | TensorInfo outputInfo(outputShape, armnn::DataType::QAsymmU8); |
| 98 | |
| 99 | OriginsDescriptor descriptor; |
| 100 | std::vector<armnn::TensorShape> shapes = {input0Shape, input1Shape} ; |
| 101 | unsigned int concatAxis = 1; |
| 102 | descriptor = armnn::CreateDescriptorForConcatenation(shapes.begin(), shapes.end(), concatAxis); |
| 103 | |
| 104 | TosaRefLayerSupport supportChecker; |
| 105 | std::string reasonIfNotSupported; |
| 106 | auto supported = supportChecker.IsLayerSupported(LayerType::Concat, |
| 107 | {input0Info, input1Info, outputInfo}, |
| 108 | descriptor, |
| 109 | EmptyOptional(), |
| 110 | EmptyOptional(), |
| 111 | reasonIfNotSupported); |
| 112 | |
| 113 | CHECK(!supported); |
| 114 | } |
| 115 | |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 116 | TEST_CASE("IsLayerSupportedTosaReferenceConstant") |
| 117 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 118 | TensorInfo outputInfo({1,1,3,4}, DataType::Float32); |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 119 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 120 | TosaRefLayerSupport supportChecker; |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 121 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 122 | auto supported = supportChecker.IsLayerSupported(LayerType::Constant, |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 123 | {outputInfo}, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 124 | BaseDescriptor(), |
| 125 | EmptyOptional(), |
| 126 | EmptyOptional(), |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 127 | reasonIfNotSupported); |
| 128 | |
| 129 | CHECK(supported); |
| 130 | } |
| 131 | |
| 132 | TEST_CASE("IsLayerSupportedTosaReferenceConstantUnsupported") |
| 133 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 134 | TensorInfo outputInfo({1,1,3,4}, DataType::Signed64); |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 135 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 136 | TosaRefLayerSupport supportChecker; |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 137 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 138 | auto supported = supportChecker.IsLayerSupported(LayerType::Constant, |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 139 | {outputInfo}, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 140 | BaseDescriptor(), |
| 141 | EmptyOptional(), |
| 142 | EmptyOptional(), |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 143 | reasonIfNotSupported); |
| 144 | |
| 145 | CHECK(!supported); |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | TEST_CASE("IsLayerSupportedTosaReferenceConv2d") |
| 149 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 150 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 151 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 152 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 153 | TensorInfo biasesInfo ({ 1 }, DataType::Float32); |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 154 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 155 | Convolution2dDescriptor desc; |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 156 | desc.m_BiasEnabled = true; |
| 157 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 158 | TosaRefLayerSupport supportChecker; |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 159 | std::string reasonIfNotSupported; |
Matthew Sloyan | fc9d5e7 | 2022-12-08 13:38:23 +0000 | [diff] [blame] | 160 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 161 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 162 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 163 | EmptyOptional(), |
| 164 | EmptyOptional(), |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 165 | reasonIfNotSupported); |
| 166 | |
| 167 | CHECK(supported); |
| 168 | } |
| 169 | |
| 170 | TEST_CASE("IsLayerSupportedTosaReferenceConv2dUnsupported") |
| 171 | { |
| 172 | // If inputs and weights are Fp32, output must match. |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 173 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 174 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Signed64); |
| 175 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 176 | TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true); |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 177 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 178 | Convolution2dDescriptor desc; |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 179 | desc.m_BiasEnabled = true; |
| 180 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 181 | TosaRefLayerSupport supportChecker; |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 182 | std::string reasonIfNotSupported; |
Matthew Sloyan | fc9d5e7 | 2022-12-08 13:38:23 +0000 | [diff] [blame] | 183 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 184 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 185 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 186 | EmptyOptional(), |
| 187 | EmptyOptional(), |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 188 | reasonIfNotSupported); |
| 189 | |
| 190 | CHECK(!supported); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2d") |
| 194 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 195 | TensorShape inShape = {1,1,3,4}; |
| 196 | TensorShape outShape = {1,1,3,4}; |
| 197 | TensorInfo in(inShape, DataType::Float32); |
| 198 | TensorInfo out(outShape, DataType::Float32); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 199 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 200 | Pooling2dDescriptor desc; |
Matthew Sloyan | 67fd526 | 2022-12-07 19:28:18 +0000 | [diff] [blame] | 201 | desc.m_PoolHeight = 1; |
| 202 | desc.m_PoolWidth = 1; |
| 203 | desc.m_StrideX = 1; |
| 204 | desc.m_StrideY = 1; |
Matthew Sloyan | fc9d5e7 | 2022-12-08 13:38:23 +0000 | [diff] [blame] | 205 | desc.m_PoolType = PoolingAlgorithm::Max; |
Matthew Sloyan | 67fd526 | 2022-12-07 19:28:18 +0000 | [diff] [blame] | 206 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 207 | TosaRefLayerSupport supportChecker; |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 208 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 209 | auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d, |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 210 | {in, out}, |
| 211 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 212 | EmptyOptional(), |
| 213 | EmptyOptional(), |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 214 | reasonIfNotSupported); |
| 215 | |
| 216 | CHECK(supported); |
| 217 | } |
| 218 | |
| 219 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2d_IgnoreValue") |
| 220 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 221 | TensorShape inShape = {1,1,3,4}; |
| 222 | TensorShape outShape = {1,1,3,4}; |
| 223 | TensorInfo in(inShape, DataType::Float32); |
| 224 | TensorInfo out(outShape, DataType::Float32); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 225 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 226 | Pooling2dDescriptor desc; |
Matthew Sloyan | 67fd526 | 2022-12-07 19:28:18 +0000 | [diff] [blame] | 227 | desc.m_PoolHeight = 1; |
| 228 | desc.m_PoolWidth = 1; |
| 229 | desc.m_StrideX = 1; |
| 230 | desc.m_StrideY = 1; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 231 | desc.m_PaddingMethod = PaddingMethod::IgnoreValue; |
| 232 | desc.m_PoolType = PoolingAlgorithm::Average; |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 233 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 234 | TosaRefLayerSupport supportChecker; |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 235 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 236 | auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d, |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 237 | {in, out}, |
| 238 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 239 | EmptyOptional(), |
| 240 | EmptyOptional(), |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 241 | reasonIfNotSupported); |
| 242 | |
| 243 | CHECK(supported); |
| 244 | } |
| 245 | |
| 246 | TEST_CASE("IsLayerSupportedTosaReferenceMaxPooling2dUnsupported") |
| 247 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 248 | TensorShape inShape = {1,1,3,4}; |
| 249 | TensorShape outShape = {1,1,3,4}; |
| 250 | TensorInfo in(inShape, DataType::Signed64); |
| 251 | TensorInfo out(outShape, DataType::Signed64); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 252 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 253 | Pooling2dDescriptor desc; |
| 254 | TosaRefLayerSupport supportChecker; |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 255 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 256 | auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d, |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 257 | {in, out}, |
| 258 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 259 | EmptyOptional(), |
| 260 | EmptyOptional(), |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 261 | reasonIfNotSupported); |
| 262 | |
| 263 | CHECK(!supported); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | TEST_CASE("IsLayerSupportedTosaReferenceAvgPooling2dUnsupported_InputOutputDatatypeDifferent") |
| 267 | { |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 268 | TensorShape inShape = {1,1,3,4}; |
| 269 | TensorShape outShape = {1,1,3,4}; |
| 270 | TensorInfo in(inShape, DataType::Float32); |
| 271 | TensorInfo out(outShape, DataType::Float16); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 272 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 273 | Pooling2dDescriptor desc; |
| 274 | desc.m_PaddingMethod = PaddingMethod::IgnoreValue; |
| 275 | desc.m_PoolType = PoolingAlgorithm::Average; |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 276 | |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 277 | TosaRefLayerSupport supportChecker; |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 278 | std::string reasonIfNotSupported; |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 279 | auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d, |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 280 | {in, out}, |
| 281 | desc, |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 282 | EmptyOptional(), |
| 283 | EmptyOptional(), |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 284 | reasonIfNotSupported); |
| 285 | |
| 286 | CHECK(!supported); |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | TEST_CASE("IsLayerSupportedTosaReferenceReshape") |
| 290 | { |
| 291 | TensorShape inShape = {3,4}; |
| 292 | TensorShape outShape = {12}; |
| 293 | TensorInfo in(inShape, DataType::Float32); |
| 294 | TensorInfo out(outShape, DataType::Float32); |
| 295 | |
| 296 | ReshapeDescriptor desc; |
| 297 | desc.m_TargetShape = {12}; |
| 298 | |
| 299 | TosaRefLayerSupport supportChecker; |
| 300 | std::string reasonIfNotSupported; |
| 301 | auto supported = supportChecker.IsLayerSupported(LayerType::Reshape, |
| 302 | {in, out}, |
| 303 | desc, |
| 304 | EmptyOptional(), |
| 305 | EmptyOptional(), |
| 306 | reasonIfNotSupported); |
| 307 | |
| 308 | CHECK(supported); |
| 309 | } |
| 310 | |
| 311 | TEST_CASE("IsLayerSupportedTosaReferenceReshapeUnsupported") |
| 312 | { |
| 313 | TensorShape inShape = {3,4}; |
| 314 | TensorShape outShape = {12}; |
| 315 | TensorInfo in(inShape, DataType::Signed64); |
| 316 | TensorInfo out(outShape, DataType::Signed64); |
| 317 | |
| 318 | ReshapeDescriptor desc; |
| 319 | desc.m_TargetShape = {12}; |
| 320 | |
| 321 | TosaRefLayerSupport supportChecker; |
| 322 | std::string reasonIfNotSupported; |
| 323 | auto supported = supportChecker.IsLayerSupported(LayerType::Reshape, |
| 324 | {in, out}, |
| 325 | desc, |
| 326 | EmptyOptional(), |
| 327 | EmptyOptional(), |
| 328 | reasonIfNotSupported); |
| 329 | |
| 330 | CHECK(!supported); |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Cathal Corbett | 3b9acd5 | 2022-12-09 12:17:27 +0000 | [diff] [blame] | 333 | TEST_CASE("IsLayerSupportedTosaReferenceSlice") |
| 334 | { |
| 335 | TensorShape inShape = {3,2,3}; |
| 336 | TensorShape outShape = {2,1,3}; |
| 337 | TensorInfo in(inShape, DataType::Float32); |
| 338 | TensorInfo out(outShape, DataType::Float32); |
| 339 | |
| 340 | SliceDescriptor descriptor; |
| 341 | descriptor.m_Begin = {1,0,0 }; |
| 342 | descriptor.m_Size = {2,1,3 }; |
| 343 | |
| 344 | TosaRefLayerSupport supportChecker; |
| 345 | std::string reasonIfNotSupported; |
| 346 | auto supported = supportChecker.IsLayerSupported(LayerType::Slice, |
| 347 | {in, out}, |
| 348 | descriptor, |
| 349 | EmptyOptional(), |
| 350 | EmptyOptional(), |
| 351 | reasonIfNotSupported); |
| 352 | |
| 353 | CHECK(supported); |
| 354 | } |
| 355 | |
| 356 | TEST_CASE("IsLayerSupportedTosaReferenceSliceUnsupported") |
| 357 | { |
| 358 | TensorShape inShape = {3,2,3}; |
| 359 | TensorShape outShape = {2,1,3}; |
| 360 | TensorInfo in(inShape, DataType::Signed64); |
| 361 | TensorInfo out(outShape, DataType::Signed64); |
| 362 | |
| 363 | SliceDescriptor descriptor; |
| 364 | descriptor.m_Begin = {1,0,0}; |
| 365 | descriptor.m_Size = {2,1,3}; |
| 366 | |
| 367 | TosaRefLayerSupport supportChecker; |
| 368 | std::string reasonIfNotSupported; |
| 369 | auto supported = supportChecker.IsLayerSupported(LayerType::Slice, |
| 370 | {in, out}, |
| 371 | descriptor, |
| 372 | EmptyOptional(), |
| 373 | EmptyOptional(), |
| 374 | reasonIfNotSupported); |
| 375 | |
| 376 | CHECK(!supported); |
Cathal Corbett | 3b9acd5 | 2022-12-09 12:17:27 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Matthew Sloyan | fc9d5e7 | 2022-12-08 13:38:23 +0000 | [diff] [blame] | 379 | TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2d") |
| 380 | { |
| 381 | TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32); |
| 382 | TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32); |
| 383 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 384 | TensorInfo biasesInfo ({ 1 }, DataType::Float32); |
| 385 | |
| 386 | TransposeConvolution2dDescriptor desc; |
| 387 | desc.m_StrideX = 1; |
| 388 | desc.m_StrideY = 1; |
| 389 | desc.m_BiasEnabled = true; |
| 390 | |
| 391 | TosaRefLayerSupport supportChecker; |
| 392 | std::string reasonIfNotSupported; |
| 393 | auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d, |
| 394 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 395 | desc, |
| 396 | EmptyOptional(), |
| 397 | EmptyOptional(), |
| 398 | reasonIfNotSupported); |
| 399 | CHECK(supported); |
| 400 | } |
| 401 | |
| 402 | TEST_CASE("IsLayerSupportedTosaReferenceTransposeConv2dUnsupported") |
| 403 | { |
| 404 | // If inputs and weights are Fp32, output must match. |
| 405 | TensorInfo inputInfo ({ 1, 3, 3, 1 }, DataType::Float32); |
| 406 | TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32); |
| 407 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 408 | TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true); |
| 409 | |
| 410 | TransposeConvolution2dDescriptor desc; |
| 411 | desc.m_BiasEnabled = true; |
| 412 | |
| 413 | TosaRefLayerSupport supportChecker; |
| 414 | std::string reasonIfNotSupported; |
| 415 | auto supported = supportChecker.IsLayerSupported(LayerType::TransposeConvolution2d, |
| 416 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 417 | desc, |
| 418 | EmptyOptional(), |
| 419 | EmptyOptional(), |
| 420 | reasonIfNotSupported); |
| 421 | CHECK(!supported); |
| 422 | } |
| 423 | |
Francis Murtagh | 9270d9e | 2022-08-12 13:54:17 +0100 | [diff] [blame] | 424 | } |