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 | |
Tracy Narine | bc5a5d5 | 2024-02-06 15:22:41 +0000 | [diff] [blame^] | 20 | TEST_CASE("IsLayerSupportedCast") |
| 21 | { |
| 22 | armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float32); |
| 23 | armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, armnn::DataType::Float16); |
| 24 | |
| 25 | BaseDescriptor desc; |
| 26 | |
| 27 | GpuFsaLayerSupport supportChecker; |
| 28 | std::string reasonIfNotSupported; |
| 29 | auto supported = supportChecker.IsLayerSupported(LayerType::Cast, |
| 30 | {inputTensorInfo, outputTensorInfo}, |
| 31 | desc, |
| 32 | EmptyOptional(), |
| 33 | EmptyOptional(), |
| 34 | reasonIfNotSupported); |
| 35 | CHECK(supported); |
| 36 | } |
| 37 | |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 38 | TEST_CASE("IsLayerSupportedGpuFsaConv2d") |
| 39 | { |
| 40 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 41 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 42 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 43 | TensorInfo biasesInfo ({ 1 }, DataType::Float32, 0.0f, 0, true); |
| 44 | |
| 45 | Convolution2dDescriptor desc; |
| 46 | desc.m_BiasEnabled = true; |
| 47 | desc.m_DataLayout = DataLayout::NHWC; |
| 48 | |
| 49 | GpuFsaLayerSupport supportChecker; |
| 50 | std::string reasonIfNotSupported; |
| 51 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
| 52 | {inputInfo, outputInfo, weightsInfo, biasesInfo}, |
| 53 | desc, |
| 54 | EmptyOptional(), |
| 55 | EmptyOptional(), |
| 56 | reasonIfNotSupported); |
| 57 | CHECK(supported); |
| 58 | } |
| 59 | |
| 60 | TEST_CASE("IsLayerSupportedGpuFsaConv2dUnsupported") |
| 61 | { |
| 62 | TensorInfo inputInfo ({ 1, 5, 5, 1 }, DataType::Float32); |
| 63 | TensorInfo outputInfo({ 1, 3, 3, 1 }, DataType::Float32); |
| 64 | TensorInfo weightsInfo({ 1, 3, 3, 1 }, DataType::Float32, 0.0f, 0, true); |
| 65 | |
| 66 | // NCHW is unsupported. |
| 67 | Convolution2dDescriptor desc; |
| 68 | desc.m_DataLayout = DataLayout::NCHW; |
| 69 | |
| 70 | GpuFsaLayerSupport supportChecker; |
| 71 | std::string reasonIfNotSupported; |
| 72 | auto supported = supportChecker.IsLayerSupported(LayerType::Convolution2d, |
| 73 | {inputInfo, outputInfo, weightsInfo, TensorInfo()}, |
| 74 | desc, |
| 75 | EmptyOptional(), |
| 76 | EmptyOptional(), |
| 77 | reasonIfNotSupported); |
| 78 | CHECK(!supported); |
| 79 | REQUIRE(reasonIfNotSupported.find("NCHW not supported by this kernel") != std::string::npos); |
| 80 | } |
| 81 | |
Tracy Narine | e7d2785 | 2024-01-26 09:13:19 +0000 | [diff] [blame] | 82 | TEST_CASE("IsLayerSupportedGpuFsaElementWiseBinaryAdd") |
| 83 | { |
| 84 | TensorInfo input0Info({ 2, 2 }, DataType::Float32); |
| 85 | TensorInfo input1Info({ 2, 2 }, DataType::Float32); |
| 86 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 87 | |
| 88 | ElementwiseBinaryDescriptor desc; |
| 89 | desc.m_Operation = BinaryOperation::Add; |
| 90 | |
| 91 | GpuFsaLayerSupport supportChecker; |
| 92 | std::string reasonIfNotSupported; |
| 93 | auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseBinary, |
| 94 | {input0Info, input1Info, outputInfo}, |
| 95 | desc, |
| 96 | EmptyOptional(), |
| 97 | EmptyOptional(), |
| 98 | reasonIfNotSupported); |
| 99 | CHECK(supported); |
| 100 | } |
| 101 | |
John Mcloughlin | 829e13e | 2024-01-31 11:00:27 +0000 | [diff] [blame] | 102 | TEST_CASE("IsLayerSupportedGpuFsaElementWiseBinarySub") |
| 103 | { |
| 104 | TensorInfo input0Info({ 2, 2 }, DataType::Float32); |
| 105 | TensorInfo input1Info({ 2, 2 }, DataType::Float32); |
| 106 | TensorInfo outputInfo({ 2, 2 }, DataType::Float32); |
| 107 | |
| 108 | ElementwiseBinaryDescriptor desc; |
| 109 | desc.m_Operation = BinaryOperation::Sub; |
| 110 | |
| 111 | GpuFsaLayerSupport supportChecker; |
| 112 | std::string reasonIfNotSupported; |
| 113 | auto supported = supportChecker.IsLayerSupported(LayerType::ElementwiseBinary, |
| 114 | {input0Info, input1Info, outputInfo}, |
| 115 | desc, |
| 116 | EmptyOptional(), |
| 117 | EmptyOptional(), |
| 118 | reasonIfNotSupported); |
| 119 | CHECK(supported); |
| 120 | } |
| 121 | |
Teresa Charlin | a52bca2 | 2024-02-01 17:36:48 +0000 | [diff] [blame] | 122 | TEST_CASE("IsLayerSupportedGpuFsaPooling2d") |
| 123 | { |
| 124 | TensorInfo inputInfo({ 1, 3, 4, 1 }, DataType::Float32); |
| 125 | TensorInfo outputInfo({ 1, 2, 2, 1 }, DataType::Float32); |
| 126 | |
| 127 | Pooling2dDescriptor desc{}; |
| 128 | desc.m_PoolType = PoolingAlgorithm::Max; |
| 129 | desc.m_PadLeft = 0; |
| 130 | desc.m_PadRight = 0; |
| 131 | desc.m_PadTop = 0; |
| 132 | desc.m_PadBottom = 0; |
| 133 | desc.m_PoolWidth = 2; |
| 134 | desc.m_PoolHeight = 2; |
| 135 | desc.m_StrideX = 1; |
| 136 | desc.m_StrideY = 1; |
| 137 | desc.m_OutputShapeRounding = OutputShapeRounding::Floor; |
| 138 | desc.m_PaddingMethod = PaddingMethod::Exclude; |
| 139 | desc.m_DataLayout = DataLayout::NHWC; |
| 140 | |
| 141 | GpuFsaLayerSupport supportChecker; |
| 142 | std::string reasonIfNotSupported; |
| 143 | auto supported = supportChecker.IsLayerSupported(LayerType::Pooling2d, |
| 144 | {inputInfo, outputInfo}, |
| 145 | desc, |
| 146 | EmptyOptional(), |
| 147 | EmptyOptional(), |
| 148 | reasonIfNotSupported); |
| 149 | CHECK(supported); |
| 150 | } |
| 151 | |
David Monahan | 8a57046 | 2023-11-22 13:24:25 +0000 | [diff] [blame] | 152 | } |