arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 6 | #include <layers/ConvertFp16ToFp32Layer.hpp> |
| 7 | #include <layers/ConvertFp32ToFp16Layer.hpp> |
| 8 | #include <test/TensorHelpers.hpp> |
arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 9 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 11 | #include <reference/RefWorkloadFactory.hpp> |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 12 | #include <reference/RefLayerSupport.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 13 | #include <backendsCommon/test/LayerTests.hpp> |
| 14 | #include <backendsCommon/test/IsLayerSupportedTestImpl.hpp> |
arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 15 | |
| 16 | #include <boost/test/unit_test.hpp> |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 17 | #include <boost/algorithm/string/trim.hpp> |
arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | namespace |
| 22 | { |
| 23 | |
| 24 | bool LayerTypeMatchesTest() |
| 25 | { |
| 26 | return LayerTypeMatchesTestImpl<armnn::LayerType::FirstLayer>(Tag<armnn::LayerType::FirstLayer>()); |
| 27 | }; |
| 28 | |
| 29 | } // anonymous namespace |
| 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(RefLayerSupported) |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE(IsLayerSupportedLayerTypeMatches) |
| 34 | { |
| 35 | LayerTypeMatchesTest(); |
| 36 | } |
Derek Lamberti | 50db4e8 | 2019-03-13 14:16:15 +0000 | [diff] [blame] | 37 | BOOST_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 | |
arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 51 | BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat16Reference) |
| 52 | { |
| 53 | armnn::RefWorkloadFactory factory; |
| 54 | IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float16>(&factory); |
| 55 | } |
| 56 | |
| 57 | BOOST_AUTO_TEST_CASE(IsLayerSupportedFloat32Reference) |
| 58 | { |
| 59 | armnn::RefWorkloadFactory factory; |
| 60 | IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::Float32>(&factory); |
| 61 | } |
| 62 | |
| 63 | BOOST_AUTO_TEST_CASE(IsLayerSupportedUint8Reference) |
| 64 | { |
| 65 | armnn::RefWorkloadFactory factory; |
| 66 | IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QuantisedAsymm8>(&factory); |
| 67 | } |
| 68 | |
Narumol Prangnawarat | f9ac3fd | 2019-07-03 14:55:57 +0100 | [diff] [blame] | 69 | BOOST_AUTO_TEST_CASE(IsLayerSupportedInt16Reference) |
| 70 | { |
| 71 | armnn::RefWorkloadFactory factory; |
| 72 | IsLayerSupportedTests<armnn::RefWorkloadFactory, armnn::DataType::QuantisedSymm16>(&factory); |
| 73 | } |
| 74 | |
arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 75 | BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedReference) |
| 76 | { |
| 77 | std::string reasonIfUnsupported; |
| 78 | |
| 79 | bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer, |
| 80 | armnn::DataType::Float16, armnn::DataType::Float32>(reasonIfUnsupported); |
| 81 | |
| 82 | BOOST_CHECK(result); |
| 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp32InputReference) |
| 86 | { |
| 87 | std::string reasonIfUnsupported; |
| 88 | |
| 89 | bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer, |
| 90 | armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported); |
| 91 | |
| 92 | BOOST_CHECK(!result); |
| 93 | BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type input"); |
| 94 | } |
| 95 | |
| 96 | BOOST_AUTO_TEST_CASE(IsConvertFp16ToFp32SupportedFp16OutputReference) |
| 97 | { |
| 98 | std::string reasonIfUnsupported; |
| 99 | |
| 100 | bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp16ToFp32Layer, |
| 101 | armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported); |
| 102 | |
| 103 | BOOST_CHECK(!result); |
| 104 | BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float16 data type output"); |
| 105 | } |
| 106 | |
| 107 | BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedReference) |
| 108 | { |
| 109 | std::string reasonIfUnsupported; |
| 110 | |
| 111 | bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer, |
| 112 | armnn::DataType::Float32, armnn::DataType::Float16>(reasonIfUnsupported); |
| 113 | |
| 114 | BOOST_CHECK(result); |
| 115 | } |
| 116 | |
| 117 | BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp16InputReference) |
| 118 | { |
| 119 | std::string reasonIfUnsupported; |
| 120 | |
| 121 | bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer, |
| 122 | armnn::DataType::Float16, armnn::DataType::Float16>(reasonIfUnsupported); |
| 123 | |
| 124 | BOOST_CHECK(!result); |
| 125 | BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float16 data type input"); |
| 126 | } |
| 127 | |
| 128 | BOOST_AUTO_TEST_CASE(IsConvertFp32ToFp16SupportedFp32OutputReference) |
| 129 | { |
| 130 | std::string reasonIfUnsupported; |
| 131 | |
| 132 | bool result = IsConvertLayerSupportedTests<armnn::RefWorkloadFactory, armnn::ConvertFp32ToFp16Layer, |
| 133 | armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported); |
| 134 | |
| 135 | BOOST_CHECK(!result); |
| 136 | BOOST_CHECK_EQUAL(reasonIfUnsupported, "Layer is not supported with float32 data type output"); |
| 137 | } |
| 138 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 139 | BOOST_AUTO_TEST_CASE(IsLayerSupportedMeanDimensionsReference) |
| 140 | { |
| 141 | std::string reasonIfUnsupported; |
| 142 | |
| 143 | bool result = IsMeanLayerSupportedTests<armnn::RefWorkloadFactory, |
| 144 | armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported); |
| 145 | |
| 146 | BOOST_CHECK(result); |
| 147 | } |
| 148 | |
| 149 | BOOST_AUTO_TEST_CASE(IsLayerNotSupportedMeanDimensionsReference) |
| 150 | { |
| 151 | std::string reasonIfUnsupported; |
| 152 | |
| 153 | bool result = IsMeanLayerNotSupportedTests<armnn::RefWorkloadFactory, |
| 154 | armnn::DataType::Float32, armnn::DataType::Float32>(reasonIfUnsupported); |
| 155 | |
| 156 | BOOST_CHECK(!result); |
| 157 | |
| 158 | boost::algorithm::trim(reasonIfUnsupported); |
| 159 | BOOST_CHECK_EQUAL(reasonIfUnsupported, |
| 160 | "Reference Mean: Expected 4 dimensions but got 2 dimensions instead, for the 'output' tensor."); |
| 161 | } |
| 162 | |
arovir01 | 43095f3 | 2018-10-09 18:04:24 +0100 | [diff] [blame] | 163 | BOOST_AUTO_TEST_SUITE_END() |