blob: bd4019a68661e5d6ed130b94f0183b7fd72d3428 [file] [log] [blame]
Sadik Armagan67e95f22020-10-29 16:14:54 +00001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ElementwiseBinaryTestHelper.hpp"
7
8#include <armnn_delegate.hpp>
9
10#include <flatbuffers/flatbuffers.h>
11#include <tensorflow/lite/interpreter.h>
12#include <tensorflow/lite/kernels/register.h>
13#include <tensorflow/lite/model.h>
14#include <tensorflow/lite/schema/schema_generated.h>
15#include <tensorflow/lite/version.h>
16
17#include <doctest/doctest.h>
18
19namespace armnnDelegate
20{
21
22TEST_SUITE("ElementwiseBinaryTest")
23{
24
25TEST_CASE ("Add_Float32_GpuAcc_Test")
26{
27 // Create the ArmNN Delegate
28 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
29 armnn::Compute::CpuRef };
30 // Set input data
31 std::vector<int32_t> input0Shape { 2, 2, 2, 3 };
32 std::vector<int32_t> input1Shape { 2, 2, 2, 3 };
33 std::vector<int32_t> outputShape { 2, 2, 2, 3 };
34
35 std::vector<float> input0Values =
36 {
37 0.0f, 2.0f, 1.0f,
38 0.2f, 1.0f, 2.0f,
39
40 1.0f, 2.0f, 1.0f,
41 0.2f, 1.0f, 2.0f,
42
43 0.0f, 2.0f, 1.0f,
44 4.2f, 1.0f, 2.0f,
45
46 0.0f, 0.0f, 1.0f,
47 0.2f, 1.0f, 2.0f,
48
49 };
50
51 std::vector<float> input1Values =
52 {
53 1.0f, 2.0f, 1.0f,
54 0.0f, 1.0f, 2.0f,
55
56 1.0f, 2.0f, -2.0f,
57 0.2f, 1.0f, 2.0f,
58
59 0.0f, 2.0f, 1.0f,
60 4.2f, 0.0f, -3.0f,
61
62 0.0f, 0.0f, 1.0f,
63 0.7f, 1.0f, 5.0f,
64 };
65
66 std::vector<float> expectedOutputValues =
67 {
68 1.0f, 4.0f, 2.0f,
69 0.2f, 2.0f, 4.0f,
70
71 2.0f, 4.0f, -1.0f,
72 0.4f, 2.0f, 4.0f,
73
74 0.0f, 4.0f, 2.0f,
75 8.4f, 1.0f, -1.0f,
76
77 0.0f, 0.0f, 2.0f,
78 0.9f, 2.0f, 7.0f,
79 };
80
81
82 ElementwiseBinaryFP32Test(tflite::BuiltinOperator_ADD,
83 tflite::ActivationFunctionType_NONE,
84 backends,
85 input0Shape,
86 input1Shape,
87 outputShape,
88 input0Values,
89 input1Values,
90 expectedOutputValues);
91}
92
93TEST_CASE ("Add_Broadcast_Float32_GpuAcc_Test")
94{
95 // Create the ArmNN Delegate
96 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
97 armnn::Compute::CpuRef };
98 // Set input data
99 std::vector<int32_t> input0Shape { 1, 3, 2, 1 };
100 std::vector<int32_t> input1Shape { 1, 1, 2, 3 };
101 std::vector<int32_t> outputShape { 1, 3, 2, 3 };
102
103 std::vector<float> input0Values
104 {
105 0.0f,
106 1.0f,
107
108 2.0f,
109 3.0f,
110
111 4.0f,
112 5.0f,
113 };
114 std::vector<float> input1Values
115 {
116 0.5f, 1.5f, 2.5f,
117 3.5f, 4.5f, 5.5f,
118 };
119 // Set output data
120 std::vector<float> expectedOutputValues
121 {
122 0.5f, 1.5f, 2.5f,
123 4.5f, 5.5f, 6.5f,
124
125 2.5f, 3.5f, 4.5f,
126 6.5f, 7.5f, 8.5f,
127
128 4.5f, 5.5f, 6.5f,
129 8.5f, 9.5f, 10.5f,
130 };
131 ElementwiseBinaryFP32Test(tflite::BuiltinOperator_ADD,
132 tflite::ActivationFunctionType_NONE,
133 backends,
134 input0Shape,
135 input1Shape,
136 outputShape,
137 input0Values,
138 input1Values,
139 expectedOutputValues);
140}
141
142TEST_CASE ("Add_ActivationRELU_Float32_GpuAcc_Test")
143{
144 // Create the ArmNN Delegate
145 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc,
146 armnn::Compute::CpuRef };
147 // Set input data
148 std::vector<int32_t> input0Shape { 1, 2, 2, 1 };
149 std::vector<int32_t> input1Shape { 1, 2, 2, 1 };
150 std::vector<int32_t> outputShape { 1, 2, 2, 1 };
151
152 std::vector<float> input0Values { 4.0f, 0.8f, 0.7f, -0.8f };
153 std::vector<float> input1Values { 0.7f, -1.2f, 0.8f, 0.5f };
154 // Set output data
155 std::vector<float> expectedOutputValues { 4.7f, 0.0f, 1.5f, 0.0f };
156 ElementwiseBinaryFP32Test(tflite::BuiltinOperator_ADD,
157 tflite::ActivationFunctionType_RELU,
158 backends,
159 input0Shape,
160 input1Shape,
161 outputShape,
162 input0Values,
163 input1Values,
164 expectedOutputValues);
165}
166
167}
168
169} // namespace armnnDelegate