1 // 2 // Copyright © 2020 Samsung Electronics Co Ltd and Contributors. All rights reserved. 3 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved. 4 // SPDX-License-Identifier: MIT 5 // 6 7 #include "ParserFlatbuffersSerializeFixture.hpp" 8 #include "../Deserializer.hpp" 9 10 #include <string> 11 12 TEST_SUITE("Deserializer_ReduceSum") 13 { 14 struct ReduceSumFixture : public ParserFlatbuffersSerializeFixture 15 { ReduceSumFixtureReduceSumFixture16 explicit ReduceSumFixture(const std::string& inputShape, 17 const std::string& outputShape, 18 const std::string& axis, 19 const std::string& dataType) 20 { 21 m_JsonString = R"( 22 { 23 inputIds: [0], 24 outputIds: [2], 25 layers: [ 26 { 27 layer_type: "InputLayer", 28 layer: { 29 base: { 30 layerBindingId: 0, 31 base: { 32 index: 0, 33 layerName: "InputLayer", 34 layerType: "Input", 35 inputSlots: [{ 36 index: 0, 37 connection: {sourceLayerIndex:0, outputSlotIndex:0 }, 38 }], 39 outputSlots: [{ 40 index: 0, 41 tensorInfo: { 42 dimensions: )" + inputShape + R"(, 43 dataType: )" + dataType + R"( 44 } 45 }] 46 } 47 } 48 } 49 }, 50 { 51 layer_type: "ReduceLayer", 52 layer: { 53 base: { 54 index: 1, 55 layerName: "ReduceSumLayer", 56 layerType: "Reduce", 57 inputSlots: [{ 58 index: 0, 59 connection: {sourceLayerIndex:0, outputSlotIndex:0 }, 60 }], 61 outputSlots: [{ 62 index: 0, 63 tensorInfo: { 64 dimensions: )" + outputShape + R"(, 65 dataType: )" + dataType + R"( 66 } 67 }] 68 }, 69 descriptor: { 70 axis: )" + axis + R"(, 71 keepDims: true, 72 reduceOperation: Sum 73 } 74 } 75 }, 76 { 77 layer_type: "OutputLayer", 78 layer: { 79 base:{ 80 layerBindingId: 2, 81 base: { 82 index: 2, 83 layerName: "OutputLayer", 84 layerType: "Output", 85 inputSlots: [{ 86 index: 0, 87 connection: {sourceLayerIndex:1, outputSlotIndex:0 }, 88 }], 89 outputSlots: [{ 90 index: 0, 91 tensorInfo: { 92 dimensions: )" + outputShape + R"(, 93 dataType: )" + dataType + R"( 94 }, 95 }], 96 } 97 } 98 }, 99 } 100 ] 101 } 102 )"; 103 Setup(); 104 } 105 }; 106 107 struct SimpleReduceSumFixture : ReduceSumFixture 108 { SimpleReduceSumFixtureSimpleReduceSumFixture109 SimpleReduceSumFixture() 110 : ReduceSumFixture("[ 1, 1, 3, 2 ]", // inputShape 111 "[ 1, 1, 1, 2 ]", // outputShape 112 "[ 2 ]", // axis 113 "Float32") // dataType 114 {} 115 }; 116 117 TEST_CASE_FIXTURE(SimpleReduceSumFixture, "SimpleReduceSum") 118 { 119 RunTest<4, armnn::DataType::Float32>( 120 0, 121 {{"InputLayer", { 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f }}}, 122 {{"OutputLayer", { 6.0f, 6.0f }}}); 123 } 124 125 } 126