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