Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "AvgPool2DIgnoreValueChecker.hpp" |
| 7 | |
| 8 | using namespace armnn; |
| 9 | using namespace tosa; |
| 10 | |
| 11 | TEST_SUITE("TosaOperatorMappingOneToManyTests") |
| 12 | { |
| 13 | TEST_CASE("GetTosaMapping_AvgPool2DIgnoreValueLayer") |
| 14 | { |
| 15 | armnn::Pooling2dDescriptor descriptor; |
| 16 | descriptor.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 17 | descriptor.m_PoolWidth = descriptor.m_PoolHeight = 2; |
| 18 | descriptor.m_StrideX = descriptor.m_StrideY = 2; |
| 19 | descriptor.m_PadLeft = 1; |
| 20 | descriptor.m_PadRight = 1; |
| 21 | descriptor.m_PadTop = 1; |
| 22 | descriptor.m_PadBottom = 1; |
| 23 | descriptor.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 24 | |
| 25 | armnn::TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32); |
| 26 | armnn::TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32); |
| 27 | |
| 28 | std::vector<std::vector<int32_t>> inputShape = {{ 1, 1, 4, 4 }}; |
| 29 | std::vector<std::vector<int32_t>> intermediateShape = {{ 1, 1, 6, 6 }}; |
| 30 | std::vector<std::vector<int32_t>> outputShape = {{ 1, 1, 3, 3 }}; |
| 31 | |
| 32 | TosaSerializationBasicBlock* basicBlock = |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 33 | GetTosaMapping(nullptr, LayerType::Pooling2d, {&inputTensorInfo}, {&outputTensorInfo}, descriptor); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 34 | VerifyAvgPool2DIgnoreValue(basicBlock, |
| 35 | inputShape, |
| 36 | outputShape, |
| 37 | intermediateShape, |
| 38 | descriptor); |
| 39 | } |
| 40 | |
| 41 | TEST_CASE("GetTosaMappingFromLayer_AvgPool2DIgnoreValueLayer") |
| 42 | { |
| 43 | IRuntime::CreationOptions options; |
| 44 | IRuntimePtr runtime(IRuntime::Create(options)); |
| 45 | |
| 46 | // Builds up the structure of the network. |
| 47 | INetworkPtr net(INetwork::Create()); |
| 48 | |
| 49 | armnn::Pooling2dDescriptor descriptor; |
| 50 | descriptor.m_PoolType = armnn::PoolingAlgorithm::Average; |
| 51 | descriptor.m_PoolWidth = descriptor.m_PoolHeight = 2; |
| 52 | descriptor.m_StrideX = descriptor.m_StrideY = 2; |
| 53 | descriptor.m_PadLeft = 1; |
| 54 | descriptor.m_PadRight = 1; |
| 55 | descriptor.m_PadTop = 1; |
| 56 | descriptor.m_PadBottom = 1; |
| 57 | descriptor.m_PaddingMethod = armnn::PaddingMethod::IgnoreValue; |
| 58 | |
| 59 | IConnectableLayer* input0 = net->AddInputLayer(0, "input0"); |
| 60 | IConnectableLayer* pool = net->AddPooling2dLayer(descriptor, "pool"); |
| 61 | IConnectableLayer* output = net->AddOutputLayer(0, "output"); |
| 62 | |
| 63 | input0->GetOutputSlot(0).Connect(pool->GetInputSlot(0)); |
| 64 | pool->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 65 | |
| 66 | armnn::TensorInfo inputTensorInfo({ 1, 1, 4, 4 }, DataType::Float32); |
| 67 | armnn::TensorInfo outputTensorInfo({ 1, 1, 3, 3 }, DataType::Float32); |
| 68 | |
| 69 | std::vector<std::vector<int32_t>> inputShape = {{ 1, 1, 4, 4 }}; |
| 70 | std::vector<std::vector<int32_t>> intermediateShape = {{ 1, 1, 6, 6 }}; |
| 71 | std::vector<std::vector<int32_t>> outputShape = {{ 1, 1, 3, 3 }}; |
| 72 | |
| 73 | input0->GetOutputSlot(0).SetTensorInfo(inputTensorInfo); |
| 74 | pool->GetOutputSlot(0).SetTensorInfo(outputTensorInfo); |
| 75 | |
| 76 | TosaSerializationBasicBlock* basicBlock = |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 77 | GetTosaMappingFromLayer(PolymorphicDowncast<Layer*>(pool)); |
Cathal Corbett | bd18eab | 2022-11-15 12:56:16 +0000 | [diff] [blame] | 78 | VerifyAvgPool2DIgnoreValue(basicBlock, |
| 79 | inputShape, |
| 80 | outputShape, |
| 81 | intermediateShape, |
| 82 | descriptor); |
| 83 | } |
| 84 | } |