blob: 430cf2c7c7e44d946148f862bbab092555a1d6db [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
Tianle Cheng21a9f332023-11-09 13:56:53 +000022void ReverseV2Float32Test(std::vector<armnn::BackendId>& backends)
23{
24 // Set input data
25 std::vector<float> inputValues =
Tracy Narine7306bbe2023-07-17 16:06:26 +010026 {
Tianle Cheng21a9f332023-11-09 13:56:53 +000027 1.0f, 2.0f, 3.0f,
28 4.0f, 5.0f, 6.0f,
29 7.0f, 8.0f, 9.0f,
Tracy Narine7306bbe2023-07-17 16:06:26 +010030
Tianle Cheng21a9f332023-11-09 13:56:53 +000031 11.0f, 12.0f, 13.0f,
32 14.0f, 15.0f, 16.0f,
33 17.0f, 18.0f, 19.0f,
Tracy Narine7306bbe2023-07-17 16:06:26 +010034
Tianle Cheng21a9f332023-11-09 13:56:53 +000035 21.0f, 22.0f, 23.0f,
36 24.0f, 25.0f, 26.0f,
37 27.0f, 28.0f, 29.0f
38 };
Tracy Narine7306bbe2023-07-17 16:06:26 +010039
Tianle Cheng21a9f332023-11-09 13:56:53 +000040 // 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,
Tracy Narine7306bbe2023-07-17 16:06:26 +010046
Tianle Cheng21a9f332023-11-09 13:56:53 +000047 13.0f, 12.0f, 11.0f,
48 16.0f, 15.0f, 14.0f,
49 19.0f, 18.0f, 17.0f,
Tracy Narine7306bbe2023-07-17 16:06:26 +010050
Tianle Cheng21a9f332023-11-09 13:56:53 +000051 23.0f, 22.0f, 21.0f,
52 26.0f, 25.0f, 24.0f,
53 29.0f, 28.0f, 27.0f
54 };
Tracy Narine7306bbe2023-07-17 16:06:26 +010055
Tianle Cheng21a9f332023-11-09 13:56:53 +000056 // The axis to reverse
57 const std::vector<int32_t> axisValues = {2};
Tracy Narine7306bbe2023-07-17 16:06:26 +010058
Tianle Cheng21a9f332023-11-09 13:56:53 +000059 // 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};
Tracy Narine7306bbe2023-07-17 16:06:26 +010063
Tianle Cheng21a9f332023-11-09 13:56:53 +000064 ReverseV2FP32TestImpl(tflite::BuiltinOperator_REVERSE_V2,
65 backends,
66 inputValues,
67 inputShape,
68 axisValues,
69 axisShapeDims,
70 expectedOutputValues,
71 expectedOutputShape);
72}
73
74void 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
126TEST_SUITE("ReverseV2Tests_GpuAccTests")
127{
128
129 TEST_CASE ("ReverseV2_Float32_GpuAcc_Test")
130 {
131 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
132 ReverseV2Float32Test(backends);
Tracy Narine7306bbe2023-07-17 16:06:26 +0100133 }
134
Tianle Cheng21a9f332023-11-09 13:56:53 +0000135 TEST_CASE ("ReverseV2_NegativeAxis_Float32_GpuAcc_Test")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100136 {
Tianle Cheng21a9f332023-11-09 13:56:53 +0000137 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
138 ReverseV2NegativeAxisFloat32Test(backends);
Tracy Narine7306bbe2023-07-17 16:06:26 +0100139 }
140
Tianle Cheng21a9f332023-11-09 13:56:53 +0000141} // TEST_SUITE("ReverseV2Tests_GpuAccTests")
142
143TEST_SUITE("ReverseV2Tests_CpuAccTests")
144{
145
146 TEST_CASE ("ReverseV2_Float32_CpuAcc_Test")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100147 {
Tianle Cheng21a9f332023-11-09 13:56:53 +0000148 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
149 ReverseV2Float32Test(backends);
150 }
Tracy Narine7306bbe2023-07-17 16:06:26 +0100151
Tianle Cheng21a9f332023-11-09 13:56:53 +0000152 TEST_CASE ("ReverseV2_NegativeAxis_Float32_CpuAcc_Test")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100153 {
Tianle Cheng21a9f332023-11-09 13:56:53 +0000154 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
155 ReverseV2NegativeAxisFloat32Test(backends);
156 }
Tracy Narine7306bbe2023-07-17 16:06:26 +0100157
Tianle Cheng21a9f332023-11-09 13:56:53 +0000158} // TEST_SUITE("ReverseV2Tests_CpuAccTests")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100159
Tianle Cheng21a9f332023-11-09 13:56:53 +0000160TEST_SUITE("ReverseV2Tests_CpuRefTests")
161{
Tracy Narine7306bbe2023-07-17 16:06:26 +0100162
Tianle Cheng21a9f332023-11-09 13:56:53 +0000163 TEST_CASE ("ReverseV2_Float32_CpuRef_Test")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100164 {
Tianle Cheng21a9f332023-11-09 13:56:53 +0000165 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
166 ReverseV2Float32Test(backends);
167 }
Tracy Narine7306bbe2023-07-17 16:06:26 +0100168
Tianle Cheng21a9f332023-11-09 13:56:53 +0000169 TEST_CASE ("ReverseV2_NegativeAxis_Float32_CpuRef_Test")
170 {
171 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
172 ReverseV2NegativeAxisFloat32Test(backends);
173 }
Tracy Narine7306bbe2023-07-17 16:06:26 +0100174
Tianle Cheng21a9f332023-11-09 13:56:53 +0000175} // TEST_SUITE("ReverseV2Tests_CpuRefTests")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100176
177} // namespace armnnDelegate