Release 18.08
[platform/upstream/armnn.git] / src / armnn / backends / test / IsLayerSupportedTest.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
4 //
5 #include <boost/test/unit_test.hpp>
6
7 #include "test/TensorHelpers.hpp"
8 #include "LayerTests.hpp"
9
10 #include "backends/CpuTensorHandle.hpp"
11 #include "backends/RefWorkloadFactory.hpp"
12
13 #include <string>
14 #include <iostream>
15 #include <backends/ClWorkloadFactory.hpp>
16 #include <backends/NeonWorkloadFactory.hpp>
17
18 #include "IsLayerSupportedTestImpl.hpp"
19 #include "ClContextControlFixture.hpp"
20
21 #include "layers/ConvertFp16ToFp32Layer.hpp"
22 #include "layers/ConvertFp32ToFp16Layer.hpp"
23
24 BOOST_AUTO_TEST_SUITE(IsLayerSupported)
25
26 BOOST_AUTO_TEST_CASE(IsLayerSupportedLayerTypeMatches)
27 {
28     LayerTypeMatchesTest();
29 }
30
31 BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat16Reference)
32 {
33     armnn::RefWorkloadFactory factory;
34     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float16>(&factory);
35 }
36
37 BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat32Reference)
38 {
39     armnn::RefWorkloadFactory factory;
40     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float32>(&factory);
41 }
42
43 BOOST_AUTO_TEST_CASE(IsLayerSupportedUint8Reference)
44 {
45     armnn::RefWorkloadFactory factory;
46     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QuantisedAsymm8>(&factory);
47 }
48
49 BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedReference)
50 {
51     std::string reasonIfUnsupported;
52
53     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
54       armnn::DataType::Float16, armnn::DataType::Float32>(reasonIfUnsupported);
55
56     BOOST_CHECK(result);
57 }
58
59 BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp32InputReference)
60 {
61     std::string reasonIfUnsupported;
62
63     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
64       armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
65
66     BOOST_CHECK(!result);
67     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type input");
68 }
69
70 BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp16OutputReference)
71 {
72     std::string reasonIfUnsupported;
73
74     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
75       armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
76
77     BOOST_CHECK(!result);
78     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float16 data type output");
79 }
80
81 BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedReference)
82 {
83     std::string reasonIfUnsupported;
84
85     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
86       armnn::DataType::Float32, armnn::DataType::Float16>(reasonIfUnsupported);
87
88     BOOST_CHECK(result);
89 }
90
91 BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp16InputReference)
92 {
93     std::string reasonIfUnsupported;
94
95     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
96       armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
97
98     BOOST_CHECK(!result);
99     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float16 data type input");
100 }
101
102 BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp32OutputReference)
103 {
104     std::string reasonIfUnsupported;
105
106     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
107       armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
108
109     BOOST_CHECK(!result);
110     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type output");
111 }
112
113 #ifdef ARMCOMPUTENEON_ENABLED
114 BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat16Neon)
115 {
116     armnn::NeonWorkloadFactory factory;
117     IsLayerSupportedTests<armnn::NeonWorkloadFactory, armnn::DataType::Float16>(&factory);
118 }
119
120 BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat32Neon)
121 {
122     armnn::NeonWorkloadFactory factory;
123     IsLayerSupportedTests<armnn::NeonWorkloadFactory, armnn::DataType::Float32>(&factory);
124 }
125
126 BOOST_AUTO_TEST_CASE(IsLayerSupportedUint8Neon)
127 {
128     armnn::NeonWorkloadFactory factory;
129     IsLayerSupportedTests<armnn::NeonWorkloadFactory, armnn::DataType::QuantisedAsymm8>(&factory);
130 }
131
132 BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedNeon)
133 {
134     std::string reasonIfUnsupported;
135
136     bool result = IsConvertLayerSupportedTests<armnn::NeonWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
137       armnn::DataType::Float16, armnn::DataType::Float32>(reasonIfUnsupported);
138
139     BOOST_CHECK(result);
140 }
141
142 BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedNeon)
143 {
144     std::string reasonIfUnsupported;
145
146     bool result = IsConvertLayerSupportedTests<armnn::NeonWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
147       armnn::DataType::Float32, armnn::DataType::Float16>(reasonIfUnsupported);
148
149     BOOST_CHECK(result);
150 }
151 #endif //#ifdef ARMCOMPUTENEON_ENABLED.
152
153
154 #ifdef ARMCOMPUTECL_ENABLED
155
156 BOOST_FIXTURE_TEST_CASE(IsLayerSupportedFloat16Cl, ClContextControlFixture)
157 {
158     armnn::ClWorkloadFactory factory;
159     IsLayerSupportedTests<armnn::ClWorkloadFactory, armnn::DataType::Float16>(&factory);
160 }
161
162 BOOST_FIXTURE_TEST_CASE(IsLayerSupportedFloat32Cl, ClContextControlFixture)
163 {
164     armnn::ClWorkloadFactory factory;
165     IsLayerSupportedTests<armnn::ClWorkloadFactory, armnn::DataType::Float32>(&factory);
166 }
167
168 BOOST_FIXTURE_TEST_CASE(IsLayerSupportedUint8Cl, ClContextControlFixture)
169 {
170     armnn::ClWorkloadFactory factory;
171     IsLayerSupportedTests<armnn::ClWorkloadFactory, armnn::DataType::QuantisedAsymm8>(&factory);
172 }
173
174 BOOST_FIXTURE_TEST_CASE(IsConvertFp16ToFp32SupportedCl, ClContextControlFixture)
175 {
176     std::string reasonIfUnsupported;
177
178     bool result = IsConvertLayerSupportedTests<armnn::ClWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
179       armnn::DataType::Float16, armnn::DataType::Float32>(reasonIfUnsupported);
180
181     BOOST_CHECK(result);
182 }
183
184 BOOST_FIXTURE_TEST_CASE(IsConvertFp16ToFp32SupportedFp32InputCl, ClContextControlFixture)
185 {
186     std::string reasonIfUnsupported;
187
188     bool result = IsConvertLayerSupportedTests<armnn::ClWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
189       armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
190
191     BOOST_CHECK(!result);
192     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Input should be Float16");
193 }
194
195 BOOST_FIXTURE_TEST_CASE(IsConvertFp16ToFp32SupportedFp16OutputCl, ClContextControlFixture)
196 {
197     std::string reasonIfUnsupported;
198
199     bool result = IsConvertLayerSupportedTests<armnn::ClWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
200       armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
201
202     BOOST_CHECK(!result);
203     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Output should be Float32");
204 }
205
206 BOOST_FIXTURE_TEST_CASE(IsConvertFp32ToFp16SupportedCl, ClContextControlFixture)
207 {
208     std::string reasonIfUnsupported;
209
210     bool result = IsConvertLayerSupportedTests<armnn::ClWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
211       armnn::DataType::Float32, armnn::DataType::Float16>(reasonIfUnsupported);
212
213     BOOST_CHECK(result);
214 }
215
216 BOOST_FIXTURE_TEST_CASE(IsConvertFp32ToFp16SupportedFp16InputCl, ClContextControlFixture)
217 {
218     std::string reasonIfUnsupported;
219
220     bool result = IsConvertLayerSupportedTests<armnn::ClWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
221       armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
222
223     BOOST_CHECK(!result);
224     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Input should be Float32");
225 }
226
227 BOOST_FIXTURE_TEST_CASE(IsConvertFp32ToFp16SupportedFp32OutputCl, ClContextControlFixture)
228 {
229     std::string reasonIfUnsupported;
230
231     bool result = IsConvertLayerSupportedTests<armnn::ClWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
232       armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
233
234     BOOST_CHECK(!result);
235     BOOST_CHECK_EQUAL(reasonIfUnsupported, "Output should be Float16");
236 }
237 #endif //#ifdef ARMCOMPUTECL_ENABLED.
238
239 BOOST_AUTO_TEST_SUITE_END()