blob: 0d99b3e66f1c7b13f03dccdd27beed7548b18276 [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
arovir0143095f32018-10-09 18:04:24 +010051
52BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat16Reference)
53{
54 armnn::RefWorkloadFactory factory;
55 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float16>(&factory);
56}
57
58BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat32Reference)
59{
60 armnn::RefWorkloadFactory factory;
61 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float32>(&factory);
62}
63
64BOOST_AUTO_TEST_CASE(IsLayerSupportedUint8Reference)
65{
66 armnn::RefWorkloadFactory factory;
67 IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QuantisedAsymm8>(&factory);
68}
69
70BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedReference)
71{
72 std::string reasonIfUnsupported;
73
74 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
75 armnn::DataType::Float16, armnn::DataType::Float32>(reasonIfUnsupported);
76
77 BOOST_CHECK(result);
78}
79
80BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp32InputReference)
81{
82 std::string reasonIfUnsupported;
83
84 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
85 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
86
87 BOOST_CHECK(!result);
88 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type input");
89}
90
91BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp16OutputReference)
92{
93 std::string reasonIfUnsupported;
94
95 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer,
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 output");
100}
101
102BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedReference)
103{
104 std::string reasonIfUnsupported;
105
106 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
107 armnn::DataType::Float32, armnn::DataType::Float16>(reasonIfUnsupported);
108
109 BOOST_CHECK(result);
110}
111
112BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp16InputReference)
113{
114 std::string reasonIfUnsupported;
115
116 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
117 armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported);
118
119 BOOST_CHECK(!result);
120 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float16 data type input");
121}
122
123BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp32OutputReference)
124{
125 std::string reasonIfUnsupported;
126
127 bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer,
128 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
129
130 BOOST_CHECK(!result);
131 BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type output");
132}
133
James Conroy4d1ff582019-06-10 17:06:39 +0100134BOOST_AUTO_TEST_CASE(IsLayerSupportedMeanDimensionsReference)
135{
136 std::string reasonIfUnsupported;
137
138 bool result = IsMeanLayerSupportedTests<armnn::RefWorkloadFactory,
139 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
140
141 BOOST_CHECK(result);
142}
143
144BOOST_AUTO_TEST_CASE(IsLayerNotSupportedMeanDimensionsReference)
145{
146 std::string reasonIfUnsupported;
147
148 bool result = IsMeanLayerNotSupportedTests<armnn::RefWorkloadFactory,
149 armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported);
150
151 BOOST_CHECK(!result);
152
153 boost::algorithm::trim(reasonIfUnsupported);
154 BOOST_CHECK_EQUAL(reasonIfUnsupported,
155 "Reference Mean: Expected 4 dimensions but got 2 dimensions instead, for the 'output' tensor.");
156}
157
arovir0143095f32018-10-09 18:04:24 +0100158BOOST_AUTO_TEST_SUITE_END()