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 | |
| 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" |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 9 | |
Derek Lamberti | 859f9ce | 2019-12-10 22:05:21 +0000 | [diff] [blame] | 10 | #include <boost/core/ignore_unused.hpp> |
| 11 | |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <iostream> |
| 14 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 15 | BOOST_AUTO_TEST_SUITE(Deserializer) |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 16 | |
| 17 | struct MultiplicationFixture : public ParserFlatbuffersSerializeFixture |
| 18 | { |
| 19 | explicit MultiplicationFixture(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 | { |
Derek Lamberti | 859f9ce | 2019-12-10 22:05:21 +0000 | [diff] [blame] | 25 | boost::ignore_unused(activation); |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +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: "MultiplicationLayer", |
| 77 | layer : { |
| 78 | base: { |
| 79 | index:2, |
| 80 | layerName: "MultiplicationLayer", |
| 81 | layerType: "Multiplication", |
| 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, |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +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 SimpleMultiplicationFixture : MultiplicationFixture |
| 131 | { |
| 132 | SimpleMultiplicationFixture() : MultiplicationFixture("[ 2, 2 ]", |
| 133 | "[ 2, 2 ]", |
| 134 | "[ 2, 2 ]", |
| 135 | "QuantisedAsymm8") {} |
| 136 | }; |
| 137 | |
| 138 | struct SimpleMultiplicationFixture2 : MultiplicationFixture |
| 139 | { |
| 140 | SimpleMultiplicationFixture2() : MultiplicationFixture("[ 2, 2, 1, 1 ]", |
| 141 | "[ 2, 2, 1, 1 ]", |
| 142 | "[ 2, 2, 1, 1 ]", |
| 143 | "Float32") {} |
| 144 | }; |
| 145 | |
| 146 | BOOST_FIXTURE_TEST_CASE(MultiplicationQuantisedAsymm8, SimpleMultiplicationFixture) |
| 147 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 148 | RunTest<2, armnn::DataType::QAsymmU8>( |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 149 | 0, |
| 150 | {{"InputLayer1", { 0, 1, 2, 3 }}, |
| 151 | {"InputLayer2", { 4, 5, 6, 7 }}}, |
| 152 | {{"OutputLayer", { 0, 5, 12, 21 }}}); |
| 153 | } |
| 154 | |
| 155 | BOOST_FIXTURE_TEST_CASE(MultiplicationFloat32, SimpleMultiplicationFixture2) |
| 156 | { |
| 157 | RunTest<4, armnn::DataType::Float32>( |
| 158 | 0, |
| 159 | {{"InputLayer1", { 100, 40, 226, 9 }}, |
| 160 | {"InputLayer2", { 5, 8, 1, 12 }}}, |
| 161 | {{"OutputLayer", { 500, 320, 226, 108 }}}); |
| 162 | } |
| 163 | |
| 164 | BOOST_AUTO_TEST_SUITE_END() |