Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | #include "ParserFlatbuffersSerializeFixture.hpp" |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 8 | #include "../Deserializer.hpp" |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 9 | |
| 10 | #include <string> |
| 11 | #include <iostream> |
| 12 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 13 | BOOST_AUTO_TEST_SUITE(Deserializer) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 14 | |
| 15 | struct AddFixture : public ParserFlatbuffersSerializeFixture |
| 16 | { |
| 17 | explicit AddFixture(const std::string & inputShape1, |
| 18 | const std::string & inputShape2, |
| 19 | const std::string & outputShape, |
| 20 | const std::string & dataType, |
| 21 | const std::string & activation="NONE") |
| 22 | { |
| 23 | m_JsonString = R"( |
| 24 | { |
| 25 | inputIds: [0, 1], |
| 26 | outputIds: [3], |
| 27 | layers: [ |
| 28 | { |
| 29 | layer_type: "InputLayer", |
| 30 | layer: { |
| 31 | base: { |
| 32 | layerBindingId: 0, |
| 33 | base: { |
| 34 | index: 0, |
| 35 | layerName: "InputLayer1", |
| 36 | layerType: "Input", |
| 37 | inputSlots: [{ |
| 38 | index: 0, |
| 39 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 40 | }], |
| 41 | outputSlots: [ { |
| 42 | index: 0, |
| 43 | tensorInfo: { |
| 44 | dimensions: )" + inputShape1 + R"(, |
| 45 | dataType: )" + dataType + R"( |
| 46 | }, |
| 47 | }], |
| 48 | },}}, |
| 49 | }, |
| 50 | { |
| 51 | layer_type: "InputLayer", |
| 52 | layer: { |
| 53 | base: { |
| 54 | layerBindingId: 1, |
| 55 | base: { |
| 56 | index:1, |
| 57 | layerName: "InputLayer2", |
| 58 | layerType: "Input", |
| 59 | inputSlots: [{ |
| 60 | index: 0, |
| 61 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 62 | }], |
| 63 | outputSlots: [ { |
| 64 | index: 0, |
| 65 | tensorInfo: { |
| 66 | dimensions: )" + inputShape2 + R"(, |
| 67 | dataType: )" + dataType + R"( |
| 68 | }, |
| 69 | }], |
| 70 | },}}, |
| 71 | }, |
| 72 | { |
| 73 | layer_type: "AdditionLayer", |
| 74 | layer : { |
| 75 | base: { |
| 76 | index:2, |
| 77 | layerName: "AdditionLayer", |
| 78 | layerType: "Addition", |
| 79 | inputSlots: [ |
| 80 | { |
| 81 | index: 0, |
| 82 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 83 | }, |
| 84 | { |
| 85 | index: 1, |
| 86 | connection: {sourceLayerIndex:1, outputSlotIndex:0 }, |
| 87 | } |
| 88 | ], |
| 89 | outputSlots: [ { |
| 90 | index: 0, |
| 91 | tensorInfo: { |
| 92 | dimensions: )" + outputShape + R"(, |
| 93 | dataType: )" + dataType + R"( |
| 94 | }, |
| 95 | }], |
| 96 | }}, |
| 97 | }, |
| 98 | { |
| 99 | layer_type: "OutputLayer", |
| 100 | layer: { |
| 101 | base:{ |
Saoirse Stewart | 3fcef20 | 2019-02-14 14:57:37 +0000 | [diff] [blame] | 102 | layerBindingId: 0, |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 103 | base: { |
| 104 | index: 3, |
| 105 | layerName: "OutputLayer", |
| 106 | layerType: "Output", |
| 107 | inputSlots: [{ |
| 108 | index: 0, |
| 109 | connection: {sourceLayerIndex:2, outputSlotIndex:0 }, |
| 110 | }], |
| 111 | outputSlots: [ { |
| 112 | index: 0, |
| 113 | tensorInfo: { |
| 114 | dimensions: )" + outputShape + R"(, |
| 115 | dataType: )" + dataType + R"( |
| 116 | }, |
| 117 | }], |
| 118 | }}}, |
| 119 | }] |
| 120 | } |
| 121 | )"; |
| 122 | Setup(); |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | |
| 127 | struct SimpleAddFixture : AddFixture |
| 128 | { |
| 129 | SimpleAddFixture() : AddFixture("[ 2, 2 ]", |
| 130 | "[ 2, 2 ]", |
| 131 | "[ 2, 2 ]", |
| 132 | "QuantisedAsymm8") {} |
| 133 | }; |
| 134 | |
| 135 | struct SimpleAddFixture2 : AddFixture |
| 136 | { |
| 137 | SimpleAddFixture2() : AddFixture("[ 2, 2, 1, 1 ]", |
| 138 | "[ 2, 2, 1, 1 ]", |
| 139 | "[ 2, 2, 1, 1 ]", |
| 140 | "Float32") {} |
| 141 | }; |
| 142 | |
| 143 | BOOST_FIXTURE_TEST_CASE(AddQuantisedAsymm8, SimpleAddFixture) |
| 144 | { |
| 145 | RunTest<2, armnn::DataType::QuantisedAsymm8>( |
| 146 | 0, |
| 147 | {{"InputLayer1", { 0, 1, 2, 3 }}, |
| 148 | {"InputLayer2", { 4, 5, 6, 7 }}}, |
| 149 | {{"OutputLayer", { 4, 6, 8, 10 }}}); |
| 150 | } |
| 151 | |
| 152 | BOOST_FIXTURE_TEST_CASE(AddFloat32, SimpleAddFixture2) |
| 153 | { |
| 154 | RunTest<4, armnn::DataType::Float32>( |
| 155 | 0, |
| 156 | {{"InputLayer1", { 111, 85, 226, 3 }}, |
| 157 | {"InputLayer2", { 5, 8, 10, 12 }}}, |
| 158 | {{"OutputLayer", { 116, 93, 236, 15 }}}); |
| 159 | } |
| 160 | |
| 161 | BOOST_AUTO_TEST_SUITE_END() |