David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 1 | // |
Tracy Narine | e7d2785 | 2024-01-26 09:13:19 +0000 | [diff] [blame] | 2 | // Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved. |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include <armnn/Optional.hpp> |
| 7 | #include <armnn/Types.hpp> |
| 8 | |
| 9 | #include <gpuFsa/GpuFsaLayerSupport.hpp> |
| 10 | |
| 11 | #include <doctest/doctest.h> |
| 12 | |
| 13 | #include <iostream> |
| 14 | |
| 15 | using namespace armnn; |
| 16 | |
| 17 | TEST_SUITE("GpuFsaLayerSupport") |
| 18 | { |
| 19 | |
Teresa Charlin | ddbda6a | 2024-02-07 22:58:29 +0000 | [diff] [blame] | 20 | TEST_CASE("IsLayerSupportedGpuFsaActivation") |
| 21 | { |
| 22 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 23 | TensorInfo outputInfo({ 1, 5, 5, 1 }, DataType::Float32); |
| 24 | |
| 25 | ActivationDescriptor desc{}; |
| 26 | |
| 27 | GpuFsaLayerSupport supportChecker; |
| 28 | std::string reasonIfNotSupported; |
| 29 | auto supported = supportChecker.IsLayerSupported(LayerType::Activation, |
| 30 | {inputInfo, outputInfo}, |
| 31 | desc, |
| 32 | EmptyOptional(), |
| 33 | EmptyOptional(), |
| 34 | reasonIfNotSupported); |
| 35 | CHECK(supported); |
| 36 | } |
| 37 | |
Teresa Charlin | 5bda973 | 2024-02-08 18:46:38 +0000 | [diff] [blame] | 38 | TEST_CASE("IsLayerSupportedGpuFsaBatchMatMul") |
| 39 | { |
| 40 | TensorInfo input0Info({ 2, 2 }, DataType::Float32); |
| 41 | TensorInfo input1Info({ 2, 2 }, DataType::Float32); |
| 42 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 43 | |
| 44 | BatchMatMulDescriptor desc{}; |
| 45 | |
| 46 | GpuFsaLayerSupport supportChecker; |
| 47 | std::string reasonIfNotSupported; |
| 48 | auto supported = supportChecker.IsLayerSupported(LayerType::BatchMatMul, |
| 49 | {input0Info, input1Info, outputInfo}, |
| 50 | desc, |
| 51 | EmptyOptional(), |
| 52 | EmptyOptional(), |
| 53 | reasonIfNotSupported); |
| 54 | CHECK(supported); |
| 55 | } |
| 56 | |
Tracy Narine | bc5a5d5 | 2024-02-06 15:22:41 +0000 | [diff] [blame] | 57 | TEST_CASE("IsLayerSupportedCast") |
| 58 | { |
| 59 | armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float32); |
| 60 | armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float16); |
| 61 | |
| 62 | BaseDescriptor desc; |
| 63 | |
| 64 | GpuFsaLayerSupport supportChecker; |
| 65 | std::string reasonIfNotSupported; |
| 66 | auto supported = supportChecker.IsLayerSupported(LayerType::Cast, |
| 67 | {inputTensorInfo, outputTensorInfo}, |
| 68 | desc, |
| 69 | EmptyOptional(), |
| 70 | EmptyOptional(), |
| 71 | reasonIfNotSupported); |
| 72 | CHECK(supported); |
| 73 | } |
| 74 | |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 75 | TEST_CASE("IsLayerSupportedGpuFsaConv2d") |
| 76 | { |
| 77 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 78 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 79 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 80 | TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true); |
| 81 | |
| 82 | Convolution2dDescriptor desc; |
| 83 | desc.m_BiasEnabled = true; |
| 84 | desc.m_DataLayout = DataLayout::NHWC; |
| 85 | |
| 86 | GpuFsaLayerSupport supportChecker; |
| 87 | std::string reasonIfNotSupported; |
| 88 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
| 89 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 90 | desc, |
| 91 | EmptyOptional(), |
| 92 | EmptyOptional(), |
| 93 | reasonIfNotSupported); |
| 94 | CHECK(supported); |
| 95 | } |
| 96 | |
| 97 | TEST_CASE("IsLayerSupportedGpuFsaConv2dUnsupported") |
| 98 | { |
| 99 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 100 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 101 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 102 | |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 103 | Convolution2dDescriptor desc; |
| 104 | desc.m_DataLayout = DataLayout::NCHW; |
| 105 | |
| 106 | GpuFsaLayerSupport supportChecker; |
| 107 | std::string reasonIfNotSupported; |
| 108 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
| 109 | {inputInfo, outputInfo, weightsInfo, TensorInfo()}, |
| 110 | desc, |
| 111 | EmptyOptional(), |
| 112 | EmptyOptional(), |
| 113 | reasonIfNotSupported); |
| 114 | CHECK(!supported); |
| 115 | REQUIRE(reasonIfNotSupported.find("NCHW not supported by this kernel") != std::string::npos); |
| 116 | } |
| 117 | |
Teresa Charlin | 20dda37 | 2024-02-08 16:23:25 +0000 | [diff] [blame] | 118 | TEST_CASE("IsLayerSupportedGpuFsaElementWiseBinary") |
Tracy Narine | e7d2785 | 2024-01-26 09:13:19 +0000 | [diff] [blame] | 119 | { |
| 120 | TensorInfo input0Info({ 2, 2 }, DataType::Float32); |
| 121 | TensorInfo input1Info({ 2, 2 }, DataType::Float32); |
| 122 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 123 | |
| 124 | ElementwiseBinaryDescriptor desc; |
Teresa Charlin | 20dda37 | 2024-02-08 16:23:25 +0000 | [diff] [blame] | 125 | SUBCASE("Add") |
| 126 | { |
| 127 | desc.m_Operation = BinaryOperation::Add; |
| 128 | } |
| 129 | SUBCASE("Mul") |
| 130 | { |
| 131 | desc.m_Operation = BinaryOperation::Mul; |
| 132 | } |
| 133 | SUBCASE("Sub") |
| 134 | { |
| 135 | desc.m_Operation = BinaryOperation::Sub; |
| 136 | } |
John Mcloughlin | 829e13e | 2024-01-31 11:00:27 +0000 | [diff] [blame] | 137 | |
| 138 | GpuFsaLayerSupport supportChecker; |
| 139 | std::string reasonIfNotSupported; |
| 140 | auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseBinary, |
| 141 | {input0Info, input1Info, outputInfo}, |
| 142 | desc, |
| 143 | EmptyOptional(), |
| 144 | EmptyOptional(), |
| 145 | reasonIfNotSupported); |
| 146 | CHECK(supported); |
| 147 | } |
| 148 | |
Teresa Charlin | a52bca2 | 2024-02-01 17:36:48 +0000 | [diff] [blame] | 149 | TEST_CASE("IsLayerSupportedGpuFsaPooling2d") |
| 150 | { |
| 151 | TensorInfo inputInfo({ 1, 3, 4, 1 }, DataType::Float32); |
| 152 | TensorInfo outputInfo({ 1, 2, 2, 1 }, DataType::Float32); |
| 153 | |
| 154 | Pooling2dDescriptor desc{}; |
| 155 | desc.m_PoolType = PoolingAlgorithm::Max; |
| 156 | desc.m_PadLeft = 0; |
| 157 | desc.m_PadRight = 0; |
| 158 | desc.m_PadTop = 0; |
| 159 | desc.m_PadBottom = 0; |
| 160 | desc.m_PoolWidth = 2; |
| 161 | desc.m_PoolHeight = 2; |
| 162 | desc.m_StrideX = 1; |
| 163 | desc.m_StrideY = 1; |
| 164 | desc.m_OutputShapeRounding = OutputShapeRounding::Floor; |
| 165 | desc.m_PaddingMethod = PaddingMethod::Exclude; |
| 166 | desc.m_DataLayout = DataLayout::NHWC; |
| 167 | |
| 168 | GpuFsaLayerSupport supportChecker; |
| 169 | std::string reasonIfNotSupported; |
| 170 | auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d, |
| 171 | {inputInfo, outputInfo}, |
| 172 | desc, |
| 173 | EmptyOptional(), |
| 174 | EmptyOptional(), |
| 175 | reasonIfNotSupported); |
| 176 | CHECK(supported); |
| 177 | } |
| 178 | |
Declan-ARM | 5e90b83 | 2024-02-07 13:07:31 +0000 | [diff] [blame^] | 179 | TEST_CASE("UNSUPPORTED_IsLayerSupportedGpuFsaReshape") |
| 180 | { |
| 181 | TensorInfo inputInfo{}; |
| 182 | TensorInfo outputInfo{}; |
| 183 | |
| 184 | SUBCASE("Float32") |
| 185 | { |
| 186 | inputInfo = { { 2, 3 }, DataType::Float32 }; |
| 187 | outputInfo = { { 6 } , DataType::Float32 }; |
| 188 | } |
| 189 | |
| 190 | SUBCASE("Float16") |
| 191 | { |
| 192 | inputInfo = { { 2, 3 }, DataType::Float16 }; |
| 193 | outputInfo = { { 6 } , DataType::Float16 }; |
| 194 | } |
| 195 | |
| 196 | SUBCASE("Int32") |
| 197 | { |
| 198 | inputInfo = { { 2, 3 }, DataType::Signed32 }; |
| 199 | outputInfo = { { 6 } , DataType::Signed32 }; |
| 200 | } |
| 201 | |
| 202 | SUBCASE("Int16") |
| 203 | { |
| 204 | inputInfo = { { 2, 3 }, DataType::QSymmS16 }; |
| 205 | outputInfo = { { 6 } , DataType::QSymmS16 }; |
| 206 | } |
| 207 | |
| 208 | SUBCASE("UInt8") |
| 209 | { |
| 210 | inputInfo = { { 2, 3 }, DataType::QAsymmU8 }; |
| 211 | outputInfo = { { 6 } , DataType::QAsymmU8 }; |
| 212 | } |
| 213 | |
| 214 | SUBCASE("Int8") |
| 215 | { |
| 216 | inputInfo = { { 2, 3 }, DataType::QAsymmS8 }; |
| 217 | outputInfo = { { 6 } , DataType::QAsymmS8 }; |
| 218 | } |
| 219 | |
| 220 | ReshapeDescriptor desc; |
| 221 | desc.m_TargetShape = outputInfo.GetShape(); |
| 222 | |
| 223 | GpuFsaLayerSupport supportChecker; |
| 224 | std::string reasonIfNotSupported; |
| 225 | |
| 226 | auto supported = supportChecker.IsLayerSupported(LayerType::Reshape, |
| 227 | { inputInfo, outputInfo }, |
| 228 | desc, |
| 229 | EmptyOptional(), |
| 230 | EmptyOptional(), |
| 231 | reasonIfNotSupported); |
| 232 | |
| 233 | CHECK(!supported); |
| 234 | } |
| 235 | |
Teresa Charlin | 1d6b731 | 2024-02-07 22:02:48 +0000 | [diff] [blame] | 236 | TEST_CASE("IsLayerSupportedGpuFsaResize") |
| 237 | { |
| 238 | TensorInfo inputInfo({ 1, 5, 5, 1 }, DataType::Float32); |
| 239 | TensorInfo outputInfo({ 1, 10, 10, 1 }, DataType::Float32); |
| 240 | |
| 241 | ResizeDescriptor desc{}; |
| 242 | desc.m_Method = ResizeMethod::NearestNeighbor; |
| 243 | desc.m_TargetHeight = 10; |
| 244 | desc.m_TargetWidth = 10; |
| 245 | desc.m_DataLayout = DataLayout::NHWC; |
| 246 | |
| 247 | GpuFsaLayerSupport supportChecker; |
| 248 | std::string reasonIfNotSupported; |
| 249 | auto supported = supportChecker.IsLayerSupported(LayerType::Resize, |
| 250 | {inputInfo, outputInfo}, |
| 251 | desc, |
| 252 | EmptyOptional(), |
| 253 | EmptyOptional(), |
| 254 | reasonIfNotSupported); |
| 255 | CHECK(supported); |
| 256 | } |
| 257 | |
John Mcloughlin | 3375390 | 2024-02-07 15:00:57 +0000 | [diff] [blame] | 258 | TEST_CASE("UNSUPPORTED_IsLayerSupportedGpuFsaSoftmax") |
| 259 | { |
| 260 | TensorInfo inputInfo({ 2, 2 }, DataType::Float32); |
| 261 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 262 | |
| 263 | SoftmaxDescriptor desc; |
| 264 | desc.m_Axis = 1; |
| 265 | desc.m_Beta = 1.0f; |
| 266 | |
| 267 | GpuFsaLayerSupport supportChecker; |
| 268 | std::string reasonIfNotSupported; |
| 269 | auto supported = supportChecker.IsLayerSupported(LayerType::Softmax, |
| 270 | {inputInfo, outputInfo}, |
| 271 | desc, |
| 272 | EmptyOptional(), |
| 273 | EmptyOptional(), |
| 274 | reasonIfNotSupported); |
| 275 | |
| 276 | CHECK(!supported); |
| 277 | } |
| 278 | |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 279 | } |