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 | 5bda973 | 2024-02-08 18:46:38 +0000 | [diff] [blame] | 20 | TEST_CASE("IsLayerSupportedGpuFsaBatchMatMul") |
| 21 | { |
| 22 | TensorInfo input0Info({ 2, 2 }, DataType::Float32); |
| 23 | TensorInfo input1Info({ 2, 2 }, DataType::Float32); |
| 24 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 25 | |
| 26 | BatchMatMulDescriptor desc{}; |
| 27 | |
| 28 | GpuFsaLayerSupport supportChecker; |
| 29 | std::string reasonIfNotSupported; |
| 30 | auto supported = supportChecker.IsLayerSupported(LayerType::BatchMatMul, |
| 31 | {input0Info, input1Info, outputInfo}, |
| 32 | desc, |
| 33 | EmptyOptional(), |
| 34 | EmptyOptional(), |
| 35 | reasonIfNotSupported); |
| 36 | CHECK(supported); |
| 37 | } |
| 38 | |
Tracy Narine | bc5a5d5 | 2024-02-06 15:22:41 +0000 | [diff] [blame] | 39 | TEST_CASE("IsLayerSupportedCast") |
| 40 | { |
| 41 | armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float32); |
| 42 | armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float16); |
| 43 | |
| 44 | BaseDescriptor desc; |
| 45 | |
| 46 | GpuFsaLayerSupport supportChecker; |
| 47 | std::string reasonIfNotSupported; |
| 48 | auto supported = supportChecker.IsLayerSupported(LayerType::Cast, |
| 49 | {inputTensorInfo, outputTensorInfo}, |
| 50 | desc, |
| 51 | EmptyOptional(), |
| 52 | EmptyOptional(), |
| 53 | reasonIfNotSupported); |
| 54 | CHECK(supported); |
| 55 | } |
| 56 | |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 57 | TEST_CASE("IsLayerSupportedGpuFsaConv2d") |
| 58 | { |
| 59 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 60 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 61 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 62 | TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true); |
| 63 | |
| 64 | Convolution2dDescriptor desc; |
| 65 | desc.m_BiasEnabled = true; |
| 66 | desc.m_DataLayout = DataLayout::NHWC; |
| 67 | |
| 68 | GpuFsaLayerSupport supportChecker; |
| 69 | std::string reasonIfNotSupported; |
| 70 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
| 71 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 72 | desc, |
| 73 | EmptyOptional(), |
| 74 | EmptyOptional(), |
| 75 | reasonIfNotSupported); |
| 76 | CHECK(supported); |
| 77 | } |
| 78 | |
| 79 | TEST_CASE("IsLayerSupportedGpuFsaConv2dUnsupported") |
| 80 | { |
| 81 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 82 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 83 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 84 | |
| 85 | // NCHW is unsupported. |
| 86 | Convolution2dDescriptor desc; |
| 87 | desc.m_DataLayout = DataLayout::NCHW; |
| 88 | |
| 89 | GpuFsaLayerSupport supportChecker; |
| 90 | std::string reasonIfNotSupported; |
| 91 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
| 92 | {inputInfo, outputInfo, weightsInfo, TensorInfo()}, |
| 93 | desc, |
| 94 | EmptyOptional(), |
| 95 | EmptyOptional(), |
| 96 | reasonIfNotSupported); |
| 97 | CHECK(!supported); |
| 98 | REQUIRE(reasonIfNotSupported.find("NCHW not supported by this kernel") != std::string::npos); |
| 99 | } |
| 100 | |
Teresa Charlin | 20dda37 | 2024-02-08 16:23:25 +0000 | [diff] [blame] | 101 | TEST_CASE("IsLayerSupportedGpuFsaElementWiseBinary") |
Tracy Narine | e7d2785 | 2024-01-26 09:13:19 +0000 | [diff] [blame] | 102 | { |
| 103 | TensorInfo input0Info({ 2, 2 }, DataType::Float32); |
| 104 | TensorInfo input1Info({ 2, 2 }, DataType::Float32); |
| 105 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 106 | |
| 107 | ElementwiseBinaryDescriptor desc; |
Teresa Charlin | 20dda37 | 2024-02-08 16:23:25 +0000 | [diff] [blame] | 108 | SUBCASE("Add") |
| 109 | { |
| 110 | desc.m_Operation = BinaryOperation::Add; |
| 111 | } |
| 112 | SUBCASE("Mul") |
| 113 | { |
| 114 | desc.m_Operation = BinaryOperation::Mul; |
| 115 | } |
| 116 | SUBCASE("Sub") |
| 117 | { |
| 118 | desc.m_Operation = BinaryOperation::Sub; |
| 119 | } |
John Mcloughlin | 829e13e | 2024-01-31 11:00:27 +0000 | [diff] [blame] | 120 | |
| 121 | GpuFsaLayerSupport supportChecker; |
| 122 | std::string reasonIfNotSupported; |
| 123 | auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseBinary, |
| 124 | {input0Info, input1Info, outputInfo}, |
| 125 | desc, |
| 126 | EmptyOptional(), |
| 127 | EmptyOptional(), |
| 128 | reasonIfNotSupported); |
| 129 | CHECK(supported); |
| 130 | } |
| 131 | |
Teresa Charlin | a52bca2 | 2024-02-01 17:36:48 +0000 | [diff] [blame] | 132 | TEST_CASE("IsLayerSupportedGpuFsaPooling2d") |
| 133 | { |
| 134 | TensorInfo inputInfo({ 1, 3, 4, 1 }, DataType::Float32); |
| 135 | TensorInfo outputInfo({ 1, 2, 2, 1 }, DataType::Float32); |
| 136 | |
| 137 | Pooling2dDescriptor desc{}; |
| 138 | desc.m_PoolType = PoolingAlgorithm::Max; |
| 139 | desc.m_PadLeft = 0; |
| 140 | desc.m_PadRight = 0; |
| 141 | desc.m_PadTop = 0; |
| 142 | desc.m_PadBottom = 0; |
| 143 | desc.m_PoolWidth = 2; |
| 144 | desc.m_PoolHeight = 2; |
| 145 | desc.m_StrideX = 1; |
| 146 | desc.m_StrideY = 1; |
| 147 | desc.m_OutputShapeRounding = OutputShapeRounding::Floor; |
| 148 | desc.m_PaddingMethod = PaddingMethod::Exclude; |
| 149 | desc.m_DataLayout = DataLayout::NHWC; |
| 150 | |
| 151 | GpuFsaLayerSupport supportChecker; |
| 152 | std::string reasonIfNotSupported; |
| 153 | auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d, |
| 154 | {inputInfo, outputInfo}, |
| 155 | desc, |
| 156 | EmptyOptional(), |
| 157 | EmptyOptional(), |
| 158 | reasonIfNotSupported); |
| 159 | CHECK(supported); |
| 160 | } |
| 161 | |
Teresa Charlin | 1d6b731 | 2024-02-07 22:02:48 +0000 | [diff] [blame] | 162 | TEST_CASE("IsLayerSupportedGpuFsaResize") |
| 163 | { |
| 164 | TensorInfo inputInfo({ 1, 5, 5, 1 }, DataType::Float32); |
| 165 | TensorInfo outputInfo({ 1, 10, 10, 1 }, DataType::Float32); |
| 166 | |
| 167 | ResizeDescriptor desc{}; |
| 168 | desc.m_Method = ResizeMethod::NearestNeighbor; |
| 169 | desc.m_TargetHeight = 10; |
| 170 | desc.m_TargetWidth = 10; |
| 171 | desc.m_DataLayout = DataLayout::NHWC; |
| 172 | |
| 173 | GpuFsaLayerSupport supportChecker; |
| 174 | std::string reasonIfNotSupported; |
| 175 | auto supported = supportChecker.IsLayerSupported(LayerType::Resize, |
| 176 | {inputInfo, outputInfo}, |
| 177 | desc, |
| 178 | EmptyOptional(), |
| 179 | EmptyOptional(), |
| 180 | reasonIfNotSupported); |
| 181 | CHECK(supported); |
| 182 | } |
| 183 | |
John Mcloughlin | 3375390 | 2024-02-07 15:00:57 +0000 | [diff] [blame^] | 184 | TEST_CASE("UNSUPPORTED_IsLayerSupportedGpuFsaSoftmax") |
| 185 | { |
| 186 | TensorInfo inputInfo({ 2, 2 }, DataType::Float32); |
| 187 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 188 | |
| 189 | SoftmaxDescriptor desc; |
| 190 | desc.m_Axis = 1; |
| 191 | desc.m_Beta = 1.0f; |
| 192 | |
| 193 | GpuFsaLayerSupport supportChecker; |
| 194 | std::string reasonIfNotSupported; |
| 195 | auto supported = supportChecker.IsLayerSupported(LayerType::Softmax, |
| 196 | {inputInfo, outputInfo}, |
| 197 | desc, |
| 198 | EmptyOptional(), |
| 199 | EmptyOptional(), |
| 200 | reasonIfNotSupported); |
| 201 | |
| 202 | CHECK(!supported); |
| 203 | } |
| 204 | |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 205 | } |