blob: 8198001f58e49f6c6da442f42aae300831a6da52 [file] [log] [blame]
Sadik Armagan5f450272019-02-12 14:31:45 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Sadik Armagan5f450272019-02-12 14:31:45 +00006#include "ParserFlatbuffersSerializeFixture.hpp"
Derek Lamberti0028d1b2019-02-20 13:57:42 +00007#include "../Deserializer.hpp"
Sadik Armagan5f450272019-02-12 14:31:45 +00008
Jan Eilers8eb25602020-03-09 12:13:48 +00009#include <armnn/utility/IgnoreUnused.hpp>
10
11#include <boost/test/unit_test.hpp>
Derek Lamberti859f9ce2019-12-10 22:05:21 +000012
Sadik Armagan5f450272019-02-12 14:31:45 +000013#include <string>
14#include <iostream>
15
Derek Lamberti0028d1b2019-02-20 13:57:42 +000016BOOST_AUTO_TEST_SUITE(Deserializer)
Sadik Armagan5f450272019-02-12 14:31:45 +000017
18struct 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 Eilers8eb25602020-03-09 12:13:48 +000026 armnn::IgnoreUnused(activation);
Sadik Armagan5f450272019-02-12 14:31:45 +000027 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 Stewart3fcef202019-02-14 14:57:37 +0000106 layerBindingId: 0,
Sadik Armagan5f450272019-02-12 14:31:45 +0000107 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
131struct SimpleMultiplicationFixture : MultiplicationFixture
132{
133 SimpleMultiplicationFixture() : MultiplicationFixture("[ 2, 2 ]",
134 "[ 2, 2 ]",
135 "[ 2, 2 ]",
136 "QuantisedAsymm8") {}
137};
138
139struct SimpleMultiplicationFixture2 : MultiplicationFixture
140{
141 SimpleMultiplicationFixture2() : MultiplicationFixture("[ 2, 2, 1, 1 ]",
142 "[ 2, 2, 1, 1 ]",
143 "[ 2, 2, 1, 1 ]",
144 "Float32") {}
145};
146
147BOOST_FIXTURE_TEST_CASE(MultiplicationQuantisedAsymm8, SimpleMultiplicationFixture)
148{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000149 RunTest<2, armnn::DataType::QAsymmU8>(
Sadik Armagan5f450272019-02-12 14:31:45 +0000150 0,
151 {{"InputLayer1", { 0, 1, 2, 3 }},
152 {"InputLayer2", { 4, 5, 6, 7 }}},
153 {{"OutputLayer", { 0, 5, 12, 21 }}});
154}
155
156BOOST_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
165BOOST_AUTO_TEST_SUITE_END()