blob: f0c69f92cc019733612ca717376924bef6fc4af2 [file] [log] [blame]
arovir0143095f32018-10-09 18:04:24 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00006#include <layers/ConvertFp16ToFp32Layer.hpp>
7#include <layers/ConvertFp32ToFp16Layer.hpp>
8#include <test/TensorHelpers.hpp>
arovir0143095f32018-10-09 18:04:24 +01009
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000010#include <backendsCommon/CpuTensorHandle.hpp>
11#include <reference/RefWorkloadFactory.hpp>
Derek Lamberti50db4e82019-03-13 14:16:15 +000012#include <reference/RefLayerSupport.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000013#include <backendsCommon/test/LayerTests.hpp>
14#include <backendsCommon/test/IsLayerSupportedTestImpl.hpp>
arovir0143095f32018-10-09 18:04:24 +010015
16#include <boost/test/unit_test.hpp>
James Conroy4d1ff582019-06-10 17:06:39 +010017#include <boost/algorithm/string/trim.hpp>
arovir0143095f32018-10-09 18:04:24 +010018
19#include <string>
20
21namespace
22{
23
24bool LayerTypeMatchesTest()
25{
26 return LayerTypeMatchesTestImpl<armnn::LayerType::FirstLayer>(Tag<armnn::LayerType::FirstLayer>());
27};
28
29} // anonymous namespace
30
31BOOST_AUTO_TEST_SUITE(RefLayerSupported)
32
33BOOST_AUTO_TEST_CASE(IsLayerSupportedLayerTypeMatches)
34{
35 LayerTypeMatchesTest();
36}
Derek Lamberti50db4e82019-03-13 14:16:15 +000037BOOST_AUTO_TEST_CASE(IsLayerSupportedReferenceAddition)
38{
39 armnn::TensorShape shape0 = {1,1,3,4};
40 armnn::TensorShape shape1 = {4};
41 armnn::TensorShape outShape = {1,1,3,4};
42 armnn::TensorInfo in0(shape0, armnn::DataType::Float32);
43 armnn::TensorInfo in1(shape1, armnn::DataType::Float32);
44 armnn::TensorInfo out(outShape, armnn::DataType::Float32);
45
46 armnn::RefLayerSupport supportChecker;
47 std::string reasonNotSupported;
48 BOOST_CHECK(supportChecker.IsAdditionSupported(in0, in1, out, reasonNotSupported));
49}
50
Narumol Prangnawarat44179c32020-03-11 14:51:27 +000051BOOST_AUTO_TEST_CASE(IsLayerSupportedBFloat16Reference)
52{
53 armnn::RefWorkloadFactory factory;
54 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::BFloat16>(&factory);
55}
56
arovir0143095f32018-10-09 18:04:24 +010057BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat16Reference)
58{
59 armnn::RefWorkloadFactory factory;
60 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float16>(&factory);
61}
62
63BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat32Reference)
64{
65 armnn::RefWorkloadFactory factory;
66 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float32>(&factory);
67}
68
69BOOST_AUTO_TEST_CASE(IsLayerSupportedUint8Reference)
70{
71 armnn::RefWorkloadFactory factory;
Derek Lambertif90c56d2020-01-10 17:14:08 +000072 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QAsymmU8>(&factory);
arovir0143095f32018-10-09 18:04:24 +010073}
74
Keith Davis9d0ff742020-02-03 14:47:54 +000075BOOST_AUTO_TEST_CASE(IsLayerSupportedInt8Reference)
76{
77 armnn::RefWorkloadFactory factory;
78 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QSymmS8>(&factory);
79}
80
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +010081BOOST_AUTO_TEST_CASE(IsLayerSupportedInt16Reference)
82{
83 armnn::RefWorkloadFactory factory;
Derek Lambertif90c56d2020-01-10 17:14:08 +000084 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QSymmS16>(&factory);
Narumol Prangnawaratf9ac3fd2019-07-03 14:55:57 +010085}
86
arovir0143095f32018-10-09 18:04:24 +010087BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedReference)
88{
89 std::string reasonIfUnsupported;
90
91 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
92 armnn::DataType::Float16, armnn::DataType::Float32>(reasonIfUnsupported);
93
94 BOOST_CHECK(result);
95}
96
97BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp32InputReference)
98{
99 std::string reasonIfUnsupported;
100
101 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
102 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
103
104 BOOST_CHECK(!result);
105 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type input");
106}
107
108BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp16OutputReference)
109{
110 std::string reasonIfUnsupported;
111
112 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
113 armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
114
115 BOOST_CHECK(!result);
116 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float16 data type output");
117}
118
Narumol Prangnawarat7ddbbae2020-03-13 10:26:05 +0000119BOOST_AUTO_TEST_CASE(IsConvertBf16ToFp32SupportedReference)
120{
121 std::string reasonIfUnsupported;
122
123 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertBf16ToFp32Layer,
124 armnn::DataType::BFloat16, armnn::DataType::Float32>(reasonIfUnsupported);
125
126 BOOST_CHECK(result);
127}
128
129BOOST_AUTO_TEST_CASE(IsConvertBf16ToFp32SupportedFp32InputReference)
130{
131 std::string reasonIfUnsupported;
132
133 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertBf16ToFp32Layer,
134 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
135
136 BOOST_CHECK(!result);
137 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Reference for ConvertBf16ToFp32 layer: input type not supported\n");
138}
139
140BOOST_AUTO_TEST_CASE(IsConvertBf16ToFp32SupportedBf16OutputReference)
141{
142 std::string reasonIfUnsupported;
143
144 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertBf16ToFp32Layer,
145 armnn::DataType::BFloat16, armnn::DataType::BFloat16>(reasonIfUnsupported);
146
147 BOOST_CHECK(!result);
148 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Reference for ConvertBf16ToFp32 layer: output type not supported\n");
149}
150
Narumol Prangnawaratea54a012020-03-16 16:36:10 +0000151BOOST_AUTO_TEST_CASE(IsConvertFp32ToBf16SupportedReference)
152{
153 std::string reasonIfUnsupported;
154
155 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToBf16Layer,
156 armnn::DataType::Float32, armnn::DataType::BFloat16>(reasonIfUnsupported);
157
158 BOOST_CHECK(result);
159}
160
161BOOST_AUTO_TEST_CASE(IsConvertFp32ToBf16SupportedBf16InputReference)
162{
163 std::string reasonIfUnsupported;
164
165 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToBf16Layer,
166 armnn::DataType::BFloat16, armnn::DataType::BFloat16>(reasonIfUnsupported);
167
168 BOOST_CHECK(!result);
169 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Reference for ConvertFp32ToBf16 layer: input type not supported\n");
170}
171
172BOOST_AUTO_TEST_CASE(IsConvertFp32ToBf16SupportedFp32OutputReference)
173{
174 std::string reasonIfUnsupported;
175
176 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToBf16Layer,
177 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
178
179 BOOST_CHECK(!result);
180 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Reference for ConvertFp32ToBf16 layer: output type not supported\n");
181}
182
arovir0143095f32018-10-09 18:04:24 +0100183BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedReference)
184{
185 std::string reasonIfUnsupported;
186
187 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
188 armnn::DataType::Float32, armnn::DataType::Float16>(reasonIfUnsupported);
189
190 BOOST_CHECK(result);
191}
192
193BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp16InputReference)
194{
195 std::string reasonIfUnsupported;
196
197 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
198 armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
199
200 BOOST_CHECK(!result);
201 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float16 data type input");
202}
203
204BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp32OutputReference)
205{
206 std::string reasonIfUnsupported;
207
208 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
209 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
210
211 BOOST_CHECK(!result);
212 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type output");
213}
214
James Conroy4d1ff582019-06-10 17:06:39 +0100215BOOST_AUTO_TEST_CASE(IsLayerSupportedMeanDimensionsReference)
216{
217 std::string reasonIfUnsupported;
218
219 bool result = IsMeanLayerSupportedTests<armnn::RefWorkloadFactory,
220 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
221
222 BOOST_CHECK(result);
223}
224
225BOOST_AUTO_TEST_CASE(IsLayerNotSupportedMeanDimensionsReference)
226{
227 std::string reasonIfUnsupported;
228
229 bool result = IsMeanLayerNotSupportedTests<armnn::RefWorkloadFactory,
230 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
231
232 BOOST_CHECK(!result);
233
234 boost::algorithm::trim(reasonIfUnsupported);
235 BOOST_CHECK_EQUAL(reasonIfUnsupported,
236 "Reference Mean: Expected 4 dimensions but got 2 dimensions instead, for the 'output' tensor.");
237}
238
arovir0143095f32018-10-09 18:04:24 +0100239BOOST_AUTO_TEST_SUITE_END()