xref: /aosp_15_r20/external/armnn/src/backends/reference/test/RefLayerSupportTests.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <layers/ConvertFp16ToFp32Layer.hpp>
7 #include <layers/ConvertFp32ToFp16Layer.hpp>
8 
9 #include <armnnTestUtils/TensorHelpers.hpp>
10 
11 #include <armnn/backends/TensorHandle.hpp>
12 #include <reference/RefWorkloadFactory.hpp>
13 #include <reference/RefLayerSupport.hpp>
14 #include <backendsCommon/test/LayerTests.hpp>
15 #include <backendsCommon/test/IsLayerSupportedTestImpl.hpp>
16 
17 #include <doctest/doctest.h>
18 
19 #include <string>
20 
21 namespace
22 {
23 
LayerTypeMatchesTest()24 bool LayerTypeMatchesTest()
25 {
26     return LayerTypeMatchesTestImpl<armnn::LayerType::FirstLayer>(Tag<armnn::LayerType::FirstLayer>());
27 };
28 
29 } // anonymous namespace
30 
31 TEST_SUITE("RefLayerSupported")
32 {
33 TEST_CASE("IsLayerSupportedLayerTypeMatches")
34 {
35     LayerTypeMatchesTest();
36 }
37 
38 TEST_CASE("IsLayerSupportedReferenceAddition")
39 {
40     armnn::TensorShape shape0 = {1,1,3,4};
41     armnn::TensorShape shape1 = {4};
42     armnn::TensorShape outShape = {1,1,3,4};
43     armnn::TensorInfo in0(shape0, armnn::DataType::Float32);
44     armnn::TensorInfo in1(shape1, armnn::DataType::Float32);
45     armnn::TensorInfo out(outShape, armnn::DataType::Float32);
46 
47     armnn::RefLayerSupport supportChecker;
48     std::string reasonNotSupported;
49     CHECK(supportChecker.IsAdditionSupported(in0, in1, out, reasonNotSupported));
50 }
51 
52 TEST_CASE("IsLayerSupportedFloat16Reference")
53 {
54     armnn::RefWorkloadFactory factory;
55     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float16>(&factory);
56 }
57 
58 TEST_CASE("IsLayerSupportedFloat32Reference")
59 {
60     armnn::RefWorkloadFactory factory;
61     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float32>(&factory);
62 }
63 
64 TEST_CASE("IsLayerSupportedUint8Reference")
65 {
66     armnn::RefWorkloadFactory factory;
67     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QAsymmU8>(&factory);
68 }
69 
70 TEST_CASE("IsLayerSupportedInt8Reference")
71 {
72     armnn::RefWorkloadFactory factory;
73     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QSymmS8>(&factory);
74 }
75 
76 TEST_CASE("IsLayerSupportedInt16Reference")
77 {
78     armnn::RefWorkloadFactory factory;
79     IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QSymmS16>(&factory);
80 }
81 
82 TEST_CASE("IsConvertFp16ToFp32SupportedReference")
83 {
84     std::string reasonIfUnsupported;
85 
86     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
87       armnn::DataType::Float16, armnn::DataType::Float32>(reasonIfUnsupported);
88 
89     CHECK(result);
90 }
91 
92 TEST_CASE("IsConvertFp16ToFp32SupportedFp32InputReference")
93 {
94     std::string reasonIfUnsupported;
95 
96     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
97       armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
98 
99     CHECK(!result);
100     CHECK_EQ(reasonIfUnsupported, "Layer is not supported with float32 data type input");
101 }
102 
103 TEST_CASE("IsConvertFp16ToFp32SupportedFp16OutputReference")
104 {
105     std::string reasonIfUnsupported;
106 
107     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
108       armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
109 
110     CHECK(!result);
111     CHECK_EQ(reasonIfUnsupported, "Layer is not supported with float16 data type output");
112 }
113 
114 TEST_CASE("IsConvertFp32ToFp16SupportedReference")
115 {
116     std::string reasonIfUnsupported;
117 
118     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
119       armnn::DataType::Float32, armnn::DataType::Float16>(reasonIfUnsupported);
120 
121     CHECK(result);
122 }
123 
124 TEST_CASE("IsConvertFp32ToFp16SupportedFp16InputReference")
125 {
126     std::string reasonIfUnsupported;
127 
128     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
129       armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
130 
131     CHECK(!result);
132     CHECK_EQ(reasonIfUnsupported, "Layer is not supported with float16 data type input");
133 }
134 
135 TEST_CASE("IsConvertFp32ToFp16SupportedFp32OutputReference")
136 {
137     std::string reasonIfUnsupported;
138 
139     bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
140       armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
141 
142     CHECK(!result);
143     CHECK_EQ(reasonIfUnsupported, "Layer is not supported with float32 data type output");
144 }
145 
146 TEST_CASE("IsLayerSupportedMeanDimensionsReference")
147 {
148     std::string reasonIfUnsupported;
149 
150     bool result = IsMeanLayerSupportedTests<armnn::RefWorkloadFactory,
151             armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
152 
153     CHECK(result);
154 }
155 
156 TEST_CASE("IsLayerNotSupportedMeanDimensionsReference")
157 {
158     std::string reasonIfUnsupported;
159 
160     bool result = IsMeanLayerNotSupportedTests<armnn::RefWorkloadFactory,
161             armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
162 
163     CHECK(!result);
164 
165     CHECK(reasonIfUnsupported.find(
166         "Reference Mean: Expected 4 dimensions but got 2 dimensions instead, for the 'output' tensor.")
167         != std::string::npos);
168 }
169 
170 TEST_CASE("IsConstantSupportedRef")
171 {
172     std::string reasonIfUnsupported;
173 
174     bool result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
175             armnn::DataType::Float16>(reasonIfUnsupported);
176     CHECK(result);
177 
178     result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
179             armnn::DataType::Float32>(reasonIfUnsupported);
180     CHECK(result);
181 
182     result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
183             armnn::DataType::QAsymmU8>(reasonIfUnsupported);
184     CHECK(result);
185 
186     result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
187             armnn::DataType::Boolean>(reasonIfUnsupported);
188     CHECK(!result);
189 
190     result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
191             armnn::DataType::QSymmS16>(reasonIfUnsupported);
192     CHECK(result);
193 
194     result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
195             armnn::DataType::QSymmS8>(reasonIfUnsupported);
196     CHECK(result);
197 
198     result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
199             armnn::DataType::QAsymmS8>(reasonIfUnsupported);
200     CHECK(result);
201 
202     result = IsConstantLayerSupportedTests<armnn::RefWorkloadFactory,
203             armnn::DataType::BFloat16>(reasonIfUnsupported);
204     CHECK(!result);
205     CHECK(reasonIfUnsupported.find("Reference constant: output is not a supported type.") != std::string::npos);
206 
207 }
208 
209 }
210