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