blob: 6cffba33eb9be016d53dfdcb442157e0fd07b537 [file] [log] [blame]
Sadik Armagan89c5a9e2021-01-20 17:48:07 +00001//
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002// Copyright © 2021, 2023 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan89c5a9e2021-01-20 17:48:07 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "SpaceDepthTestHelper.hpp"
7
8#include <armnn_delegate.hpp>
9
10#include <flatbuffers/flatbuffers.h>
Sadik Armagan89c5a9e2021-01-20 17:48:07 +000011
12#include <doctest/doctest.h>
13
14namespace armnnDelegate
15{
16
17void DepthToSpaceFp32Test(std::vector<armnn::BackendId>& backends, int blockSize)
18{
19 // Set input data
20 std::vector<int32_t> inputShape { 1, 2, 2, 4 };
21 std::vector<int32_t> outputShape { 1, 4, 4, 1 };
22
23 std::vector<float> inputValues = { 1.f, 2.f, 3.f, 4.f,
24 5.f, 6.f, 7.f, 8.f,
25 9.f, 10.f, 11.f, 12.f,
26 13.f, 14.f, 15.f, 16.f };
27
28 std::vector<float> expectedOutputValues = { 1.f, 2.f, 5.f, 6.f,
29 3.f, 4.f, 7.f, 8.f,
30 9.f, 10.f, 13.f, 14.f,
31 11.f, 12.f, 15.f, 16.f };
32
33 SpaceDepthTest<float>(tflite::BuiltinOperator_DEPTH_TO_SPACE,
34 ::tflite::TensorType_FLOAT32,
35 backends,
36 inputShape,
37 outputShape,
38 inputValues,
39 expectedOutputValues,
40 blockSize);
41}
42
43void DepthToSpaceUint8Test(std::vector<armnn::BackendId>& backends, int blockSize)
44{
45 // Set input data
46 std::vector<int32_t> inputShape { 2, 1, 1, 4 };
47 std::vector<int32_t> outputShape { 2, 2, 2, 1 };
48
49 std::vector<uint8_t> inputValues = { 1, 2, 3, 4,
50 5, 6, 7, 8 };
51
52 std::vector<uint8_t> expectedOutputValues = { 1, 2, 3, 4,
53 5, 6, 7, 8 };
54
55 SpaceDepthTest<uint8_t>(tflite::BuiltinOperator_DEPTH_TO_SPACE,
56 ::tflite::TensorType_UINT8,
57 backends,
58 inputShape,
59 outputShape,
60 inputValues,
61 expectedOutputValues,
62 blockSize);
63}
64
65void SpaceToDepthFp32Test(std::vector<armnn::BackendId>& backends, int blockSize)
66{
67 // Set input data
68 std::vector<int32_t> inputShape { 1, 2, 2, 2 };
69 std::vector<int32_t> outputShape { 1, 1, 1, 8 };
70
71 std::vector<float> inputValues = { 1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f };
72 std::vector<float> expectedOutputValues = { 1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f };
73
74 SpaceDepthTest<float>(tflite::BuiltinOperator_SPACE_TO_DEPTH,
75 ::tflite::TensorType_FLOAT32,
76 backends,
77 inputShape,
78 outputShape,
79 inputValues,
80 expectedOutputValues,
81 blockSize);
82}
83
84void SpaceToDepthUint8Test(std::vector<armnn::BackendId>& backends, int blockSize)
85{
86 // Set input data
87 std::vector<int32_t> inputShape { 1, 2, 2, 1 };
88 std::vector<int32_t> outputShape { 1, 1, 1, 4 };
89
90 std::vector<uint8_t> inputValues = { 1, 2, 3, 2 };
91 std::vector<uint8_t> expectedOutputValues = { 1, 2, 3, 2 };
92
93 SpaceDepthTest<uint8_t>(tflite::BuiltinOperator_SPACE_TO_DEPTH,
94 ::tflite::TensorType_UINT8,
95 backends,
96 inputShape,
97 outputShape,
98 inputValues,
99 expectedOutputValues,
100 blockSize);
101}
102
103TEST_SUITE("DepthToSpace_CpuRefTests")
104{
105
106TEST_CASE ("DepthToSpaceFp32Test_CpuRef_Test")
107{
108 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
109 DepthToSpaceFp32Test(backends, 2);
110}
111
112TEST_CASE ("DepthToSpaceUint8Test_CpuRef_Test")
113{
114 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
115 DepthToSpaceUint8Test(backends, 2);
116}
117
118} // TEST_SUITE("DepthToSpace_CpuRefTests")
119
120
121TEST_SUITE("DepthToSpace_CpuAccTests")
122{
123
124TEST_CASE ("DepthToSpaceFp32Test_CpuAcc_Test")
125{
126 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
127 DepthToSpaceFp32Test(backends, 2);
128}
129
130TEST_CASE ("DepthToSpaceUint8Test_CpuAcc_Test")
131{
132 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
133 DepthToSpaceUint8Test(backends, 2);
134}
135
136} // TEST_SUITE("DepthToSpace_CpuAccTests")
137
138TEST_SUITE("DepthToSpace_GpuAccTests")
139{
140
141TEST_CASE ("DepthToSpaceFp32Test_GpuAcc_Test")
142{
143 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
144 DepthToSpaceFp32Test(backends, 2);
145}
146
147TEST_CASE ("DepthToSpaceUint8Test_GpuAcc_Test")
148{
149 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
150 DepthToSpaceUint8Test(backends, 2);
151}
152
153} // TEST_SUITE("DepthToSpace_GpuAccTests")
154
155TEST_SUITE("SpaceToDepth_CpuRefTests")
156{
157
158TEST_CASE ("SpaceToDepthFp32Test_CpuRef_Test")
159{
160 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
161 SpaceToDepthFp32Test(backends, 2);
162}
163
164TEST_CASE ("SpaceToDepthUint8Test_CpuRef_Test")
165{
166 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
167 SpaceToDepthUint8Test(backends, 2);
168}
169
170} // TEST_SUITE("SpaceToDepth_CpuRefTests")
171
172TEST_SUITE("SpaceToDepth_CpuAccTests")
173{
174
175TEST_CASE ("SpaceToDepthFp32Test_CpuAcc_Test")
176{
177 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
178 SpaceToDepthFp32Test(backends, 2);
179}
180
181TEST_CASE ("SpaceToDepthUint8Test_CpuAcc_Test")
182{
183 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc };
184 SpaceToDepthUint8Test(backends, 2);
185}
186
187} // TEST_SUITE("SpaceToDepth_CpuAccTests")
188
189TEST_SUITE("SpaceToDepth_GpuAccTests")
190{
191
192TEST_CASE ("SpaceToDepthFp32Test_GpuAcc_Test")
193{
194 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
195 SpaceToDepthFp32Test(backends, 2);
196}
197
198TEST_CASE ("SpaceToDepthUint8Test_GpuAcc_Test")
199{
200 std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc };
201 SpaceToDepthUint8Test(backends, 2);
202}
203
204} // TEST_SUITE("SpaceToDepth_GpuAccTests")
205
206} // namespace armnnDelegate