blob: 9fa2d3dde08bf438335fe81501b5f433cb5295ed [file] [log] [blame]
Matthew Sloyanc8eb9552020-11-26 10:54:22 +00001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ElementwiseUnaryTestHelper.hpp"
7#include "LogicalTestHelper.hpp"
8
9#include <armnn_delegate.hpp>
10
11#include <flatbuffers/flatbuffers.h>
12#include <tensorflow/lite/schema/schema_generated.h>
13
14#include <doctest/doctest.h>
15
16namespace armnnDelegate
17{
18
19void LogicalBinaryAndBoolTest(std::vector<armnn::BackendId>& backends)
20{
21 std::vector<int32_t> input0Shape { 1, 2, 2 };
22 std::vector<int32_t> input1Shape { 1, 2, 2 };
23 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
24
25 // Set input and output values
26 std::vector<bool> input0Values { 0, 0, 1, 1 };
27 std::vector<bool> input1Values { 0, 1, 0, 1 };
28 std::vector<bool> expectedOutputValues { 0, 0, 0, 1 };
29
30 LogicalBinaryTest<bool>(tflite::BuiltinOperator_LOGICAL_AND,
31 ::tflite::TensorType_BOOL,
32 backends,
33 input0Shape,
34 input1Shape,
35 expectedOutputShape,
36 input0Values,
37 input1Values,
38 expectedOutputValues);
39}
40
41void LogicalBinaryAndBroadcastTest(std::vector<armnn::BackendId>& backends)
42{
43 std::vector<int32_t> input0Shape { 1, 2, 2 };
44 std::vector<int32_t> input1Shape { 1, 1, 1 };
45 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
46
47 std::vector<bool> input0Values { 0, 1, 0, 1 };
48 std::vector<bool> input1Values { 1 };
49 std::vector<bool> expectedOutputValues { 0, 1, 0, 1 };
50
51 LogicalBinaryTest<bool>(tflite::BuiltinOperator_LOGICAL_AND,
52 ::tflite::TensorType_BOOL,
53 backends,
54 input0Shape,
55 input1Shape,
56 expectedOutputShape,
57 input0Values,
58 input1Values,
59 expectedOutputValues);
60}
61
62void LogicalBinaryOrBoolTest(std::vector<armnn::BackendId>& backends)
63{
64 std::vector<int32_t> input0Shape { 1, 2, 2 };
65 std::vector<int32_t> input1Shape { 1, 2, 2 };
66 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
67
68 std::vector<bool> input0Values { 0, 0, 1, 1 };
69 std::vector<bool> input1Values { 0, 1, 0, 1 };
70 std::vector<bool> expectedOutputValues { 0, 1, 1, 1 };
71
72 LogicalBinaryTest<bool>(tflite::BuiltinOperator_LOGICAL_OR,
73 ::tflite::TensorType_BOOL,
74 backends,
75 input0Shape,
76 input1Shape,
77 expectedOutputShape,
78 input0Values,
79 input1Values,
80 expectedOutputValues);
81}
82
83void LogicalBinaryOrBroadcastTest(std::vector<armnn::BackendId>& backends)
84{
85 std::vector<int32_t> input0Shape { 1, 2, 2 };
86 std::vector<int32_t> input1Shape { 1, 1, 1 };
87 std::vector<int32_t> expectedOutputShape { 1, 2, 2 };
88
89 std::vector<bool> input0Values { 0, 1, 0, 1 };
90 std::vector<bool> input1Values { 1 };
91 std::vector<bool> expectedOutputValues { 1, 1, 1, 1 };
92
93 LogicalBinaryTest<bool>(tflite::BuiltinOperator_LOGICAL_OR,
94 ::tflite::TensorType_BOOL,
95 backends,
96 input0Shape,
97 input1Shape,
98 expectedOutputShape,
99 input0Values,
100 input1Values,
101 expectedOutputValues);
102}
103
104// LogicalNot operator uses ElementwiseUnary unary layer and descriptor but is still classed as logical operator.
105void LogicalNotBoolTest(std::vector<armnn::BackendId>& backends)
106{
107 std::vector<int32_t> inputShape { 1, 2, 2 };
108
109 std::vector<bool> inputValues { 0, 1, 0, 1 };
110 std::vector<bool> expectedOutputValues { 1, 0, 1, 0 };
111
112 ElementwiseUnaryBoolTest(tflite::BuiltinOperator_LOGICAL_NOT,
113 backends,
114 inputShape,
115 inputValues,
116 expectedOutputValues);
117}
118
119TEST_SUITE("LogicalBinaryTests_GpuAccTests")
120{
121
122TEST_CASE ("LogicalBinary_AND_Bool_GpuAcc_Test")
123{
124 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
125 LogicalBinaryAndBoolTest(backends);
126}
127
128TEST_CASE ("LogicalBinary_AND_Broadcast_GpuAcc_Test")
129{
130 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
131 LogicalBinaryAndBroadcastTest(backends);
132}
133
134TEST_CASE ("Logical_NOT_Bool_GpuAcc_Test")
135{
136 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
137 LogicalNotBoolTest(backends);
138}
139
140TEST_CASE ("LogicalBinary_OR_Bool_GpuAcc_Test")
141{
142 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
143 LogicalBinaryOrBoolTest(backends);
144}
145
146TEST_CASE ("LogicalBinary_OR_Broadcast_GpuAcc_Test")
147{
148 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
149 LogicalBinaryOrBroadcastTest(backends);
150}
151
152}
153
154
155TEST_SUITE("LogicalBinaryTests_CpuAccTests")
156{
157
158TEST_CASE ("LogicalBinary_AND_Bool_CpuAcc_Test")
159{
160 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
161 LogicalBinaryAndBoolTest(backends);
162}
163
164TEST_CASE ("LogicalBinary_AND_Broadcast_CpuAcc_Test")
165{
166 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
167 LogicalBinaryAndBroadcastTest(backends);
168}
169
170TEST_CASE ("Logical_NOT_Bool_CpuAcc_Test")
171{
172 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
173 LogicalNotBoolTest(backends);
174}
175
176TEST_CASE ("LogicalBinary_OR_Bool_CpuAcc_Test")
177{
178 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
179 LogicalBinaryOrBoolTest(backends);
180}
181
182TEST_CASE ("LogicalBinary_OR_Broadcast_CpuAcc_Test")
183{
184 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
185 LogicalBinaryOrBroadcastTest(backends);
186}
187
188}
189
190
191TEST_SUITE("LogicalBinaryTests_CpuRefTests")
192{
193
194TEST_CASE ("LogicalBinary_AND_Bool_CpuRef_Test")
195{
196 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
197 LogicalBinaryAndBoolTest(backends);
198}
199
200TEST_CASE ("LogicalBinary_AND_Broadcast_CpuRef_Test")
201{
202 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
203 LogicalBinaryAndBroadcastTest(backends);
204}
205
206TEST_CASE ("Logical_NOT_Bool_CpuRef_Test")
207{
208 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
209 LogicalNotBoolTest(backends);
210}
211
212TEST_CASE ("LogicalBinary_OR_Bool_CpuRef_Test")
213{
214 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
215 LogicalBinaryOrBoolTest(backends);
216}
217
218TEST_CASE ("LogicalBinary_OR_Broadcast_CpuRef_Test")
219{
220 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
221 LogicalBinaryOrBroadcastTest(backends);
222}
223
224}
225
226} // namespace armnnDelegate