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