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