blob: 63e7c913c9a2d7daf78ac757160f8c3a1188136a [file] [log] [blame]
Conor Kennedyda1f9752019-03-01 14:37:12 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Conor Kennedyda1f9752019-03-01 14:37:12 +00006#include "ParserFlatbuffersSerializeFixture.hpp"
Finn Williams85d36712021-01-26 22:30:06 +00007#include <armnnDeserializer/IDeserializer.hpp>
Conor Kennedyda1f9752019-03-01 14:37:12 +00008
9#include <string>
Conor Kennedyda1f9752019-03-01 14:37:12 +000010
Sadik Armagan1625efc2021-06-10 18:24:34 +010011TEST_SUITE("Deserializer_Subtraction")
12{
Conor Kennedyda1f9752019-03-01 14:37:12 +000013struct SubtractionFixture : public ParserFlatbuffersSerializeFixture
14{
15 explicit SubtractionFixture(const std::string & inputShape1,
16 const std::string & inputShape2,
17 const std::string & outputShape,
18 const std::string & dataType)
19 {
20 m_JsonString = R"(
21 {
22 inputIds: [0, 1],
23 outputIds: [3],
24 layers: [
25 {
26 layer_type: "InputLayer",
27 layer: {
28 base: {
29 layerBindingId: 0,
30 base: {
31 index: 0,
32 layerName: "inputLayer1",
33 layerType: "Input",
34 inputSlots: [{
35 index: 0,
36 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
37 }],
38 outputSlots: [ {
39 index: 0,
40 tensorInfo: {
41 dimensions: )" + inputShape1 + R"(,
42 dataType: )" + dataType + R"(
43 },
44 }],
45 },
46 }},
47 },
48 {
49 layer_type: "InputLayer",
50 layer: {
51 base: {
52 layerBindingId: 1,
53 base: {
54 index:1,
55 layerName: "inputLayer2",
56 layerType: "Input",
57 inputSlots: [{
58 index: 0,
59 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
60 }],
61 outputSlots: [ {
62 index: 0,
63 tensorInfo: {
64 dimensions: )" + inputShape2 + R"(,
65 dataType: )" + dataType + R"(
66 },
67 }],
68 },
69 }},
70 },
71 {
72 layer_type: "SubtractionLayer",
73 layer : {
74 base: {
75 index:2,
76 layerName: "subtractionLayer",
77 layerType: "Subtraction",
78 inputSlots: [{
79 index: 0,
80 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
81 },
82 {
83 index: 1,
84 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
85 }],
86 outputSlots: [ {
87 index: 0,
88 tensorInfo: {
89 dimensions: )" + outputShape + R"(,
90 dataType: )" + dataType + R"(
91 },
92 }],
93 }},
94 },
95 {
96 layer_type: "OutputLayer",
97 layer: {
98 base:{
99 layerBindingId: 0,
100 base: {
101 index: 3,
102 layerName: "outputLayer",
103 layerType: "Output",
104 inputSlots: [{
105 index: 0,
106 connection: {sourceLayerIndex:2, outputSlotIndex:0 },
107 }],
108 outputSlots: [ {
109 index: 0,
110 tensorInfo: {
111 dimensions: )" + outputShape + R"(,
112 dataType: )" + dataType + R"(
113 },
114 }],
115 }}},
116 }]
117 }
118 )";
119 Setup();
120 }
121};
122
123struct SimpleSubtractionFixture : SubtractionFixture
124{
125 SimpleSubtractionFixture() : SubtractionFixture("[ 1, 4 ]",
126 "[ 1, 4 ]",
127 "[ 1, 4 ]",
128 "QuantisedAsymm8") {}
129};
130
131struct SimpleSubtractionFixture2 : SubtractionFixture
132{
133 SimpleSubtractionFixture2() : SubtractionFixture("[ 1, 4 ]",
134 "[ 1, 4 ]",
135 "[ 1, 4 ]",
136 "Float32") {}
137};
138
139struct SimpleSubtractionFixtureBroadcast : SubtractionFixture
140{
141 SimpleSubtractionFixtureBroadcast() : SubtractionFixture("[ 1, 4 ]",
142 "[ 1, 1 ]",
143 "[ 1, 4 ]",
144 "Float32") {}
145};
146
Sadik Armagan1625efc2021-06-10 18:24:34 +0100147TEST_CASE_FIXTURE(SimpleSubtractionFixture, "SubtractionQuantisedAsymm8")
Conor Kennedyda1f9752019-03-01 14:37:12 +0000148{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000149 RunTest<2, armnn::DataType::QAsymmU8>(
Conor Kennedyda1f9752019-03-01 14:37:12 +0000150 0,
151 {{"inputLayer1", { 4, 5, 6, 7 }},
152 {"inputLayer2", { 3, 2, 1, 0 }}},
153 {{"outputLayer", { 1, 3, 5, 7 }}});
154}
155
Sadik Armagan1625efc2021-06-10 18:24:34 +0100156TEST_CASE_FIXTURE(SimpleSubtractionFixture2, "SubtractionFloat32")
Conor Kennedyda1f9752019-03-01 14:37:12 +0000157{
158 RunTest<2, armnn::DataType::Float32>(
159 0,
160 {{"inputLayer1", { 4, 5, 6, 7 }},
161 {"inputLayer2", { 3, 2, 1, 0 }}},
162 {{"outputLayer", { 1, 3, 5, 7 }}});
163}
164
Sadik Armagan1625efc2021-06-10 18:24:34 +0100165TEST_CASE_FIXTURE(SimpleSubtractionFixtureBroadcast, "SubtractionBroadcast")
Conor Kennedyda1f9752019-03-01 14:37:12 +0000166{
167 RunTest<2, armnn::DataType::Float32>(
168 0,
169 {{"inputLayer1", { 4, 5, 6, 7 }},
170 {"inputLayer2", { 2 }}},
171 {{"outputLayer", { 2, 3, 4, 5 }}});
172}
173
Sadik Armagan1625efc2021-06-10 18:24:34 +0100174}