blob: b261474e99042e0ca0e63f6c720d8a494233c623 [file] [log] [blame]
Tracy Narine7306bbe2023-07-17 16:06:26 +01001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ReverseV2TestHelper.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 <schema_generated.h>
15#include <tensorflow/lite/version.h>
16
17#include <doctest/doctest.h>
18
19namespace armnnDelegate
20{
21
22 void ReverseV2Float32Test(std::vector<armnn::BackendId>& backends)
23 {
24 // Set input data
25 std::vector<float> inputValues =
26 {
27 1.0f, 2.0f, 3.0f,
28 4.0f, 5.0f, 6.0f,
29 7.0f, 8.0f, 9.0f,
30
31 11.0f, 12.0f, 13.0f,
32 14.0f, 15.0f, 16.0f,
33 17.0f, 18.0f, 19.0f,
34
35 21.0f, 22.0f, 23.0f,
36 24.0f, 25.0f, 26.0f,
37 27.0f, 28.0f, 29.0f
38 };
39
40 // The output data
41 std::vector<float> expectedOutputValues =
42 {
43 3.0f, 2.0f, 1.0f,
44 6.0f, 5.0f, 4.0f,
45 9.0f, 8.0f, 7.0f,
46
47 13.0f, 12.0f, 11.0f,
48 16.0f, 15.0f, 14.0f,
49 19.0f, 18.0f, 17.0f,
50
51 23.0f, 22.0f, 21.0f,
52 26.0f, 25.0f, 24.0f,
53 29.0f, 28.0f, 27.0f
54 };
55
56 // The axis to reverse
57 const std::vector<int32_t> axisValues = {2};
58
59 // Shapes
60 const std::vector<int32_t> inputShape = {3, 3, 3};
61 const std::vector<int32_t> axisShapeDims = {1};
62 const std::vector<int32_t> expectedOutputShape = {3, 3, 3};
63
64 ReverseV2FP32TestImpl(tflite::BuiltinOperator_REVERSE_V2,
65 backends,
66 inputValues,
67 inputShape,
68 axisValues,
69 axisShapeDims,
70 expectedOutputValues,
71 expectedOutputShape);
72 }
73
74 void ReverseV2NegativeAxisFloat32Test(std::vector<armnn::BackendId>& backends)
75 {
76 // Set input data
77 std::vector<float> inputValues =
78 {
79 1.0f, 2.0f, 3.0f,
80 4.0f, 5.0f, 6.0f,
81 7.0f, 8.0f, 9.0f,
82
83 11.0f, 12.0f, 13.0f,
84 14.0f, 15.0f, 16.0f,
85 17.0f, 18.0f, 19.0f,
86
87 21.0f, 22.0f, 23.0f,
88 24.0f, 25.0f, 26.0f,
89 27.0f, 28.0f, 29.0f
90 };
91
92 // The output data
93 std::vector<float> expectedOutputValues =
94 {
95 7.0f, 8.0f, 9.0f,
96 4.0f, 5.0f, 6.0f,
97 1.0f, 2.0f, 3.0f,
98
99 17.0f, 18.0f, 19.0f,
100 14.0f, 15.0f, 16.0f,
101 11.0f, 12.0f, 13.0f,
102
103 27.0f, 28.0f, 29.0f,
104 24.0f, 25.0f, 26.0f,
105 21.0f, 22.0f, 23.0f
106 };
107
108 // The axis to reverse
109 const std::vector<int32_t> axisValues = {-2};
110
111 // Shapes
112 const std::vector<int32_t> inputShape = {3, 3, 3};
113 const std::vector<int32_t> axisShapeDims = {1};
114 const std::vector<int32_t> expectedOutputShape = {3, 3, 3};
115
116 ReverseV2FP32TestImpl(tflite::BuiltinOperator_REVERSE_V2,
117 backends,
118 inputValues,
119 inputShape,
120 axisValues,
121 axisShapeDims,
122 expectedOutputValues,
123 expectedOutputShape);
124 }
125
126#if defined(REVERSEV2_GPUACC)
127 TEST_SUITE("ReverseV2Tests_GpuAccTests")
128 {
129
130 TEST_CASE ("ReverseV2_Float32_GpuAcc_Test")
131 {
132 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
133 ReverseV2Float32Test(backends);
134 }
135
136 TEST_CASE ("ReverseV2_NegativeAxis_Float32_GpuAcc_Test")
137 {
138 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
139 ReverseV2NegativeAxisFloat32Test(backends);
140 }
141
142 } // TEST_SUITE("ReverseV2Tests_GpuAccTests")
143#endif
144
145
146#if defined(REVERSEV2_CPUACC)
147 TEST_SUITE("ReverseV2Tests_CpuAccTests")
148 {
149
150 TEST_CASE ("ReverseV2_Float32_CpuAcc_Test")
151 {
152 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
153 ReverseV2Float32Test(backends);
154 }
155
156 TEST_CASE ("ReverseV2_NegativeAxis_Float32_CpuAcc_Test")
157 {
158 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
159 ReverseV2NegativeAxisFloat32Test(backends);
160 }
161
162 } // TEST_SUITE("ReverseV2Tests_CpuAccTests")
163#endif
164
165
166 TEST_SUITE("ReverseV2Tests_CpuRefTests")
167 {
168
169 TEST_CASE ("ReverseV2_Float32_CpuRef_Test")
170 {
171 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
172 ReverseV2Float32Test(backends);
173 }
174
175 TEST_CASE ("ReverseV2_NegativeAxis_Float32_CpuRef_Test")
176 {
177 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
178 ReverseV2NegativeAxisFloat32Test(backends);
179 }
180
181 } // TEST_SUITE("ReverseV2Tests_CpuRefTests")
182
183} // namespace armnnDelegate