diff options
Diffstat (limited to 'src/armnn/test/UtilsTests.cpp')
-rw-r--r-- | src/armnn/test/UtilsTests.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/src/armnn/test/UtilsTests.cpp b/src/armnn/test/UtilsTests.cpp index f2ca95d7bd..1599d0cd35 100644 --- a/src/armnn/test/UtilsTests.cpp +++ b/src/armnn/test/UtilsTests.cpp @@ -2,7 +2,7 @@ // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // -#include <boost/test/unit_test.hpp> +#include <doctest/doctest.h> #include <armnn/BackendHelper.hpp> @@ -15,52 +15,52 @@ #include <Graph.hpp> #include <ResolveType.hpp> -BOOST_AUTO_TEST_SUITE(Utils) - -BOOST_AUTO_TEST_CASE(DataTypeSize) +TEST_SUITE("Utils") +{ +TEST_CASE("DataTypeSize") { - BOOST_TEST(armnn::GetDataTypeSize(armnn::DataType::Float32) == 4); - BOOST_TEST(armnn::GetDataTypeSize(armnn::DataType::QAsymmU8) == 1); - BOOST_TEST(armnn::GetDataTypeSize(armnn::DataType::Signed32) == 4); - BOOST_TEST(armnn::GetDataTypeSize(armnn::DataType::Boolean) == 1); + CHECK(armnn::GetDataTypeSize(armnn::DataType::Float32) == 4); + CHECK(armnn::GetDataTypeSize(armnn::DataType::QAsymmU8) == 1); + CHECK(armnn::GetDataTypeSize(armnn::DataType::Signed32) == 4); + CHECK(armnn::GetDataTypeSize(armnn::DataType::Boolean) == 1); } -BOOST_AUTO_TEST_CASE(PermuteDescriptorWithTooManyMappings) +TEST_CASE("PermuteDescriptorWithTooManyMappings") { - BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 1u, 2u, 3u, 4u, 5u }), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::PermuteDescriptor({ 0u, 1u, 2u, 3u, 4u, 5u }), armnn::InvalidArgumentException); } -BOOST_AUTO_TEST_CASE(PermuteDescriptorWithInvalidMappings1d) +TEST_CASE("PermuteDescriptorWithInvalidMappings1d") { - BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 1u }), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::PermuteDescriptor({ 1u }), armnn::InvalidArgumentException); } -BOOST_AUTO_TEST_CASE(PermuteDescriptorWithInvalidMappings2d) +TEST_CASE("PermuteDescriptorWithInvalidMappings2d") { - BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 2u, 0u }), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::PermuteDescriptor({ 2u, 0u }), armnn::InvalidArgumentException); } -BOOST_AUTO_TEST_CASE(PermuteDescriptorWithInvalidMappings3d) +TEST_CASE("PermuteDescriptorWithInvalidMappings3d") { - BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 3u, 1u }), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::PermuteDescriptor({ 0u, 3u, 1u }), armnn::InvalidArgumentException); } -BOOST_AUTO_TEST_CASE(PermuteDescriptorWithInvalidMappings4d) +TEST_CASE("PermuteDescriptorWithInvalidMappings4d") { - BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 1u, 2u, 4u }), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::PermuteDescriptor({ 0u, 1u, 2u, 4u }), armnn::InvalidArgumentException); } -BOOST_AUTO_TEST_CASE(PermuteDescriptorWithInvalidMappings5d) +TEST_CASE("PermuteDescriptorWithInvalidMappings5d") { - BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 1u, 2u, 3u, 5u }), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::PermuteDescriptor({ 0u, 1u, 2u, 3u, 5u }), armnn::InvalidArgumentException); } -BOOST_AUTO_TEST_CASE(PermuteDescriptorWithDuplicatedMappings) +TEST_CASE("PermuteDescriptorWithDuplicatedMappings") { - BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 1u, 1u, 0u }), armnn::InvalidArgumentException); + CHECK_THROWS_AS(armnn::PermuteDescriptor({ 1u, 1u, 0u }), armnn::InvalidArgumentException); } -BOOST_AUTO_TEST_CASE(HalfType) +TEST_CASE("HalfType") { using namespace half_float::literal; armnn::Half a = 1.0_h; @@ -69,25 +69,25 @@ BOOST_AUTO_TEST_CASE(HalfType) armnn::Half c(b); // Test half type - BOOST_CHECK_EQUAL(a, b); - BOOST_CHECK_EQUAL(sizeof(c), 2); + CHECK_EQ(a, b); + CHECK_EQ(sizeof(c), 2); // Test half type is floating point type - BOOST_CHECK(std::is_floating_point<armnn::Half>::value); + CHECK(std::is_floating_point<armnn::Half>::value); // Test utility function returns correct type. using ResolvedType = armnn::ResolveType<armnn::DataType::Float16>; constexpr bool isHalfType = std::is_same<armnn::Half, ResolvedType>::value; - BOOST_CHECK(isHalfType); + CHECK(isHalfType); //Test utility functions return correct size - BOOST_CHECK(GetDataTypeSize(armnn::DataType::Float16) == 2); + CHECK(GetDataTypeSize(armnn::DataType::Float16) == 2); //Test utility functions return correct name - BOOST_CHECK((GetDataTypeName(armnn::DataType::Float16) == std::string("Float16"))); + CHECK((GetDataTypeName(armnn::DataType::Float16) == std::string("Float16"))); } -BOOST_AUTO_TEST_CASE(BFloatType) +TEST_CASE("BFloatType") { uint16_t v = 16256; armnn::BFloat16 a(v); @@ -95,83 +95,83 @@ BOOST_AUTO_TEST_CASE(BFloatType) armnn::BFloat16 zero; // Test BFloat16 type - BOOST_CHECK_EQUAL(sizeof(a), 2); - BOOST_CHECK_EQUAL(a, b); - BOOST_CHECK_EQUAL(a.Val(), v); - BOOST_CHECK_EQUAL(a, 1.0f); - BOOST_CHECK_EQUAL(zero, 0.0f); + CHECK_EQ(sizeof(a), 2); + CHECK_EQ(a, b); + CHECK_EQ(a.Val(), v); + CHECK_EQ(a, 1.0f); + CHECK_EQ(zero, 0.0f); // Infinity float infFloat = std::numeric_limits<float>::infinity(); armnn::BFloat16 infBF(infFloat); - BOOST_CHECK_EQUAL(infBF, armnn::BFloat16::Inf()); + CHECK_EQ(infBF, armnn::BFloat16::Inf()); // NaN float nan = std::numeric_limits<float>::quiet_NaN(); armnn::BFloat16 nanBF(nan); - BOOST_CHECK_EQUAL(nanBF, armnn::BFloat16::Nan()); + CHECK_EQ(nanBF, armnn::BFloat16::Nan()); // Test utility function returns correct type. using ResolvedType = armnn::ResolveType<armnn::DataType::BFloat16>; constexpr bool isBFloat16Type = std::is_same<armnn::BFloat16, ResolvedType>::value; - BOOST_CHECK(isBFloat16Type); + CHECK(isBFloat16Type); //Test utility functions return correct size - BOOST_CHECK(GetDataTypeSize(armnn::DataType::BFloat16) == 2); + CHECK(GetDataTypeSize(armnn::DataType::BFloat16) == 2); //Test utility functions return correct name - BOOST_CHECK((GetDataTypeName(armnn::DataType::BFloat16) == std::string("BFloat16"))); + CHECK((GetDataTypeName(armnn::DataType::BFloat16) == std::string("BFloat16"))); } -BOOST_AUTO_TEST_CASE(Float32ToBFloat16Test) +TEST_CASE("Float32ToBFloat16Test") { // LSB = 0, R = 0 -> round down armnn::BFloat16 roundDown0 = armnn::BFloat16::Float32ToBFloat16(1.704735E38f); // 0x7F004000 - BOOST_CHECK_EQUAL(roundDown0.Val(), 0x7F00); + CHECK_EQ(roundDown0.Val(), 0x7F00); // LSB = 1, R = 0 -> round down armnn::BFloat16 roundDown1 = armnn::BFloat16::Float32ToBFloat16(9.18355E-41f); // 0x00010000 - BOOST_CHECK_EQUAL(roundDown1.Val(), 0x0001); + CHECK_EQ(roundDown1.Val(), 0x0001); // LSB = 0, R = 1 all 0 -> round down armnn::BFloat16 roundDown2 = armnn::BFloat16::Float32ToBFloat16(1.14794E-40f); // 0x00014000 - BOOST_CHECK_EQUAL(roundDown2.Val(), 0x0001); + CHECK_EQ(roundDown2.Val(), 0x0001); // LSB = 1, R = 1 -> round up armnn::BFloat16 roundUp = armnn::BFloat16::Float32ToBFloat16(-2.0234377f); // 0xC0018001 - BOOST_CHECK_EQUAL(roundUp.Val(), 0xC002); + CHECK_EQ(roundUp.Val(), 0xC002); // LSB = 0, R = 1 -> round up armnn::BFloat16 roundUp1 = armnn::BFloat16::Float32ToBFloat16(4.843037E-35f); // 0x0680C000 - BOOST_CHECK_EQUAL(roundUp1.Val(), 0x0681); + CHECK_EQ(roundUp1.Val(), 0x0681); // Max positive value -> infinity armnn::BFloat16 maxPositive = armnn::BFloat16::Float32ToBFloat16(std::numeric_limits<float>::max()); // 0x7F7FFFFF - BOOST_CHECK_EQUAL(maxPositive, armnn::BFloat16::Inf()); + CHECK_EQ(maxPositive, armnn::BFloat16::Inf()); // Max negative value -> -infinity armnn::BFloat16 maxNeg = armnn::BFloat16::Float32ToBFloat16(std::numeric_limits<float>::lowest()); // 0xFF7FFFFF - BOOST_CHECK_EQUAL(maxNeg.Val(), 0xFF80); + CHECK_EQ(maxNeg.Val(), 0xFF80); // Min positive value armnn::BFloat16 minPositive = armnn::BFloat16::Float32ToBFloat16(1.1754942E-38f); // 0x007FFFFF - BOOST_CHECK_EQUAL(minPositive.Val(), 0x0080); + CHECK_EQ(minPositive.Val(), 0x0080); // Min negative value armnn::BFloat16 minNeg = armnn::BFloat16::Float32ToBFloat16(-1.1754942E-38f); // 0x807FFFFF - BOOST_CHECK_EQUAL(minNeg.Val(), 0x8080); + CHECK_EQ(minNeg.Val(), 0x8080); } -BOOST_AUTO_TEST_CASE(BFloat16ToFloat32Test) +TEST_CASE("BFloat16ToFloat32Test") { armnn::BFloat16 bf0(1.5f); - BOOST_CHECK_EQUAL(bf0.ToFloat32(), 1.5f); + CHECK_EQ(bf0.ToFloat32(), 1.5f); armnn::BFloat16 bf1(-5.525308E-25f); - BOOST_CHECK_EQUAL(bf1.ToFloat32(), -5.525308E-25f); + CHECK_EQ(bf1.ToFloat32(), -5.525308E-25f); armnn::BFloat16 bf2(-2.0625f); - BOOST_CHECK_EQUAL(bf2.ToFloat32(), -2.0625f); + CHECK_EQ(bf2.ToFloat32(), -2.0625f); uint16_t v = 32639; armnn::BFloat16 bf3(v); - BOOST_CHECK_EQUAL(bf3.ToFloat32(), 3.3895314E38f); + CHECK_EQ(bf3.ToFloat32(), 3.3895314E38f); // Infinity - BOOST_CHECK_EQUAL(armnn::BFloat16::Inf().ToFloat32(), std::numeric_limits<float>::infinity()); + CHECK_EQ(armnn::BFloat16::Inf().ToFloat32(), std::numeric_limits<float>::infinity()); // NaN - BOOST_CHECK(std::isnan(armnn::BFloat16::Nan().ToFloat32())); + CHECK(std::isnan(armnn::BFloat16::Nan().ToFloat32())); } -BOOST_AUTO_TEST_CASE(GraphTopologicalSortSimpleTest) +TEST_CASE("GraphTopologicalSortSimpleTest") { std::map<int, std::vector<int>> graph; @@ -192,13 +192,13 @@ BOOST_AUTO_TEST_CASE(GraphTopologicalSortSimpleTest) std::vector<int> output; bool sortCompleted = armnnUtils::GraphTopologicalSort<int>(targetNodes, getNodeInputs, output); - BOOST_TEST(sortCompleted); + CHECK(sortCompleted); std::vector<int> correctResult = {5, 4, 2, 0, 3, 1}; - BOOST_CHECK_EQUAL_COLLECTIONS(output.begin(), output.end(), correctResult.begin(), correctResult.end()); + CHECK(std::equal(output.begin(), output.end(), correctResult.begin(), correctResult.end())); } -BOOST_AUTO_TEST_CASE(GraphTopologicalSortVariantTest) +TEST_CASE("GraphTopologicalSortVariantTest") { std::map<int, std::vector<int>> graph; @@ -220,13 +220,13 @@ BOOST_AUTO_TEST_CASE(GraphTopologicalSortVariantTest) std::vector<int> output; bool sortCompleted = armnnUtils::GraphTopologicalSort<int>(targetNodes, getNodeInputs, output); - BOOST_TEST(sortCompleted); + CHECK(sortCompleted); std::vector<int> correctResult = {6, 5, 3, 4, 2, 0, 1}; - BOOST_CHECK_EQUAL_COLLECTIONS(output.begin(), output.end(), correctResult.begin(), correctResult.end()); + CHECK(std::equal(output.begin(), output.end(), correctResult.begin(), correctResult.end())); } -BOOST_AUTO_TEST_CASE(CyclicalGraphTopologicalSortTest) +TEST_CASE("CyclicalGraphTopologicalSortTest") { std::map<int, std::vector<int>> graph; @@ -244,32 +244,32 @@ BOOST_AUTO_TEST_CASE(CyclicalGraphTopologicalSortTest) std::vector<int> output; bool sortCompleted = armnnUtils::GraphTopologicalSort<int>(targetNodes, getNodeInputs, output); - BOOST_TEST(!sortCompleted); + CHECK(!sortCompleted); } -BOOST_AUTO_TEST_CASE(PermuteQuantizationDim) +TEST_CASE("PermuteQuantizationDim") { std::vector<float> scales {1.0f, 1.0f}; // Set QuantizationDim to be index 1 const armnn::TensorInfo perChannelInfo({ 1, 2, 3, 4 }, armnn::DataType::Float32, scales, 1U); - BOOST_CHECK(perChannelInfo.GetQuantizationDim().value() == 1U); + CHECK(perChannelInfo.GetQuantizationDim().value() == 1U); // Permute so that index 1 moves to final index i.e. index 3 armnn::PermutationVector mappings({ 0, 3, 2, 1 }); auto permutedPerChannel = armnnUtils::Permuted(perChannelInfo, mappings); // Check that QuantizationDim is in index 3 - BOOST_CHECK(permutedPerChannel.GetQuantizationDim().value() == 3U); + CHECK(permutedPerChannel.GetQuantizationDim().value() == 3U); // Even if there is only a single scale the quantization dim still exists and needs to be permuted std::vector<float> scale {1.0f}; const armnn::TensorInfo perChannelInfo1({ 1, 2, 3, 4 }, armnn::DataType::Float32, scale, 1U); auto permuted = armnnUtils::Permuted(perChannelInfo1, mappings); - BOOST_CHECK(permuted.GetQuantizationDim().value() == 3U); + CHECK(permuted.GetQuantizationDim().value() == 3U); } -BOOST_AUTO_TEST_CASE(PermuteVectorIterator) +TEST_CASE("PermuteVectorIterator") { // We're slightly breaking the spirit of std::array.end() because we're using it as a // variable length rather than fixed length. This test is to use a couple of iterators and @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(PermuteVectorIterator) // Create zero length. armnn::PermutationVector zeroPVector({}); // Begin should be equal to end. - BOOST_CHECK(zeroPVector.begin() == zeroPVector.end()); + CHECK(zeroPVector.begin() == zeroPVector.end()); // Create length 4. Summing the 4 values should be 6. armnn::PermutationVector fourPVector({ 0, 3, 2, 1 }); @@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(PermuteVectorIterator) { sum += it; } - BOOST_CHECK(sum == 6); + CHECK(sum == 6); // Directly use begin and end, make sure there are 4 iterations. unsigned int iterations = 0; auto itr = fourPVector.begin(); @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(PermuteVectorIterator) ++iterations; itr++; } - BOOST_CHECK(iterations == 4); + CHECK(iterations == 4); // Do the same with 2 elements. armnn::PermutationVector twoPVector({ 0, 1 }); @@ -307,20 +307,20 @@ BOOST_AUTO_TEST_CASE(PermuteVectorIterator) ++iterations; itr++; } - BOOST_CHECK(iterations == 2); + CHECK(iterations == 2); } #if defined(ARMNNREF_ENABLED) -BOOST_AUTO_TEST_CASE(LayerSupportHandle) +TEST_CASE("LayerSupportHandle") { auto layerSupportObject = armnn::GetILayerSupportByBackendId("CpuRef"); armnn::TensorInfo input; std::string reasonIfUnsupported; // InputLayer always supported for CpuRef - BOOST_CHECK_EQUAL(layerSupportObject.IsInputSupported(input, reasonIfUnsupported), true); + CHECK_EQ(layerSupportObject.IsInputSupported(input, reasonIfUnsupported), true); - BOOST_CHECK(layerSupportObject.IsBackendRegistered()); + CHECK(layerSupportObject.IsBackendRegistered()); } #endif -BOOST_AUTO_TEST_SUITE_END() +} |