blob: 39aed055af83d689b2aa7f55a1d074d2f8dcd889 [file] [log] [blame]
John Mcloughlin0ec00872023-05-15 17:03:49 +01001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ParserFlatbuffersSerializeFixture.hpp"
7#include <armnnDeserializer/IDeserializer.hpp>
8
9#include <string>
10
11TEST_SUITE("ElementWiseBinary_Deserializer")
12{
13 struct ElementwiseBinaryFixture : public ParserFlatbuffersSerializeFixture {
14 explicit ElementwiseBinaryFixture(const std::string & inputShape1,
15 const std::string & inputShape2,
16 const std::string & outputShape,
17 const std::string & dataType,
18 const std::string &binaryOperation) {
19 m_JsonString = R"(
20 {
21 inputIds: [0, 1],
22 outputIds: [3],
23 layers: [
24 {
25 layer_type: "InputLayer",
26 layer: {
27 base: {
28 layerBindingId: 0,
29 base: {
30 index: 0,
31 layerName: "InputLayer1",
32 layerType: "Input",
33 inputSlots: [{
34 index: 0,
35 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
36 }],
37 outputSlots: [ {
38 index: 0,
39 tensorInfo: {
40 dimensions: )" + inputShape1 + R"(,
41 dataType: )" + dataType + R"(
42 },
43 }],
44 },}},
45 },
46 {
47 layer_type: "InputLayer",
48 layer: {
49 base: {
50 layerBindingId: 1,
51 base: {
52 index:1,
53 layerName: "InputLayer2",
54 layerType: "Input",
55 inputSlots: [{
56 index: 0,
57 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
58 }],
59 outputSlots: [ {
60 index: 0,
61 tensorInfo: {
62 dimensions: )" + inputShape2 + R"(,
63 dataType: )" + dataType + R"(
64 },
65 }],
66 },}},
67 },
68 {
69 layer_type: "ElementwiseBinaryLayer",
70 layer: {
71 base: {
72 index: 2,
73 layerName: "ElementwiseBinaryLayer",
74 layerType: "ElementwiseBinary",
75 inputSlots: [ {
76 index: 0,
77 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
78 },
79 {
80 index: 1,
81 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
82 }],
83 outputSlots: [{
84 index: 0,
85 tensorInfo: {
86 dimensions: )" + outputShape + R"(,
87 dataType: )" + dataType + R"(
88 }
89 }]
90 },
91 descriptor: {
92 operation: )" + binaryOperation + R"(
93 },
94 }
95 },
96 {
97 layer_type: "OutputLayer",
98 layer: {
99 base:{
100 layerBindingId: 0,
101 base: {
102 index: 3,
103 layerName: "OutputLayer",
104 layerType: "Output",
105 inputSlots: [{
106 index: 0,
107 connection: {sourceLayerIndex:2, outputSlotIndex:0 },
108 }],
109 outputSlots: [{
110 index: 0,
111 tensorInfo: {
112 dimensions: )" + outputShape + R"(,
113 dataType: )" + dataType + R"(
114 },
115 }],
116 }
117 }
118 },
119 }
120 ]
121 }
122 )";
123 Setup();
124 }
125 };
126
127struct SimplePowerFixture : ElementwiseBinaryFixture
128{
129 SimplePowerFixture() : ElementwiseBinaryFixture("[ 2, 2 ]",
130 "[ 2, 2 ]",
131 "[ 2, 2 ]",
132 "QuantisedAsymm8",
133 "Power") {}
134};
135
136TEST_CASE_FIXTURE(SimplePowerFixture, "PowerQuantisedAsymm8")
137{
138 RunTest<2, armnn::DataType::QAsymmU8>(
139 0,
140 {{"InputLayer1", { 0, 1, 2, 3 }},
141 {"InputLayer2", { 4, 5, 3, 2 }}},
142 {{"OutputLayer", { 0, 1, 8, 9 }}});
143}
144
145struct SimpleSquaredDifferenceFixture : ElementwiseBinaryFixture
146{
147 SimpleSquaredDifferenceFixture() : ElementwiseBinaryFixture("[ 2, 2 ]",
148 "[ 2, 2 ]",
149 "[ 2, 2 ]",
150 "QuantisedAsymm8",
151 "SqDiff") {}
152};
153
154TEST_CASE_FIXTURE(SimpleSquaredDifferenceFixture, "SquaredDifferenceQuantisedAsymm8")
155{
156 RunTest<2, armnn::DataType::QAsymmU8>(
157 0,
158 {{"InputLayer1", { 5, 1, 7, 9 }},
159 {"InputLayer2", { 4, 5, 2, 1 }}},
160 {{"OutputLayer", { 1, 16, 25, 64 }}});
161}
162
163}