ArmNN  NotReleased
UtilsTests.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <armnn/Utils.hpp>
#include <armnn/Types.hpp>
#include <armnn/TypesUtils.hpp>
#include <armnn/Descriptors.hpp>
#include <GraphTopologicalSort.hpp>
#include <Graph.hpp>
#include <ResolveType.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (DataTypeSize)
 
 BOOST_AUTO_TEST_CASE (PermuteDescriptorWithTooManyMappings)
 
 BOOST_AUTO_TEST_CASE (PermuteDescriptorWithInvalidMappings1d)
 
 BOOST_AUTO_TEST_CASE (PermuteDescriptorWithInvalidMappings2d)
 
 BOOST_AUTO_TEST_CASE (PermuteDescriptorWithInvalidMappings3d)
 
 BOOST_AUTO_TEST_CASE (PermuteDescriptorWithInvalidMappings4d)
 
 BOOST_AUTO_TEST_CASE (PermuteDescriptorWithInvalidMappings5d)
 
 BOOST_AUTO_TEST_CASE (PermuteDescriptorWithDuplicatedMappings)
 
 BOOST_AUTO_TEST_CASE (HalfType)
 
 BOOST_AUTO_TEST_CASE (GraphTopologicalSortSimpleTest)
 
 BOOST_AUTO_TEST_CASE (GraphTopologicalSortVariantTest)
 
 BOOST_AUTO_TEST_CASE (CyclicalGraphTopologicalSortTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/12]

BOOST_AUTO_TEST_CASE ( DataTypeSize  )

◆ BOOST_AUTO_TEST_CASE() [2/12]

BOOST_AUTO_TEST_CASE ( PermuteDescriptorWithTooManyMappings  )

Definition at line 26 of file UtilsTests.cpp.

27 {
28  BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 1u, 2u, 3u, 4u, 5u }), armnn::InvalidArgumentException);
29 }
A PermuteDescriptor for the PermuteLayer.

◆ BOOST_AUTO_TEST_CASE() [3/12]

BOOST_AUTO_TEST_CASE ( PermuteDescriptorWithInvalidMappings1d  )

Definition at line 31 of file UtilsTests.cpp.

32 {
34 }
A PermuteDescriptor for the PermuteLayer.

◆ BOOST_AUTO_TEST_CASE() [4/12]

BOOST_AUTO_TEST_CASE ( PermuteDescriptorWithInvalidMappings2d  )

Definition at line 36 of file UtilsTests.cpp.

37 {
38  BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 2u, 0u }), armnn::InvalidArgumentException);
39 }
A PermuteDescriptor for the PermuteLayer.

◆ BOOST_AUTO_TEST_CASE() [5/12]

BOOST_AUTO_TEST_CASE ( PermuteDescriptorWithInvalidMappings3d  )

Definition at line 41 of file UtilsTests.cpp.

42 {
43  BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 3u, 1u }), armnn::InvalidArgumentException);
44 }
A PermuteDescriptor for the PermuteLayer.

◆ BOOST_AUTO_TEST_CASE() [6/12]

BOOST_AUTO_TEST_CASE ( PermuteDescriptorWithInvalidMappings4d  )

Definition at line 46 of file UtilsTests.cpp.

47 {
48  BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 1u, 2u, 4u }), armnn::InvalidArgumentException);
49 }
A PermuteDescriptor for the PermuteLayer.

◆ BOOST_AUTO_TEST_CASE() [7/12]

BOOST_AUTO_TEST_CASE ( PermuteDescriptorWithInvalidMappings5d  )

Definition at line 51 of file UtilsTests.cpp.

52 {
53  BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 0u, 1u, 2u, 3u, 5u }), armnn::InvalidArgumentException);
54 }
A PermuteDescriptor for the PermuteLayer.

◆ BOOST_AUTO_TEST_CASE() [8/12]

BOOST_AUTO_TEST_CASE ( PermuteDescriptorWithDuplicatedMappings  )

Definition at line 56 of file UtilsTests.cpp.

57 {
58  BOOST_CHECK_THROW(armnn::PermuteDescriptor({ 1u, 1u, 0u }), armnn::InvalidArgumentException);
59 }
A PermuteDescriptor for the PermuteLayer.

◆ BOOST_AUTO_TEST_CASE() [9/12]

BOOST_AUTO_TEST_CASE ( HalfType  )

Definition at line 61 of file UtilsTests.cpp.

References BOOST_CHECK(), armnn::Float16, armnn::GetDataTypeName(), and armnn::GetDataTypeSize().

62 {
63  using namespace half_float::literal;
64  armnn::Half a = 1.0_h;
65 
66  float b = 1.0f;
67  armnn::Half c(b);
68 
69  // Test half type
70  BOOST_CHECK_EQUAL(a, b);
71  BOOST_CHECK_EQUAL(sizeof(c), 2);
72 
73  // Test half type is floating point type
74  BOOST_CHECK(std::is_floating_point<armnn::Half>::value);
75 
76  // Test utility function returns correct type.
78  constexpr bool isHalfType = std::is_same<armnn::Half, ResolvedType>::value;
79  BOOST_CHECK(isHalfType);
80 
81  //Test utility functions return correct size
83 
84  //Test utility functions return correct name
85  BOOST_CHECK((GetDataTypeName(armnn::DataType::Float16) == std::string("Float16")));
86 }
half_float::half Half
Definition: Half.hpp:16
typename ResolveTypeImpl< DT >::Type ResolveType
Definition: ResolveType.hpp:66
constexpr unsigned int GetDataTypeSize(DataType dataType)
Definition: TypesUtils.hpp:113
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:165

◆ BOOST_AUTO_TEST_CASE() [10/12]

BOOST_AUTO_TEST_CASE ( GraphTopologicalSortSimpleTest  )

Definition at line 88 of file UtilsTests.cpp.

89 {
90  std::map<int, std::vector<int>> graph;
91 
92  graph[0] = {2};
93  graph[1] = {3};
94  graph[2] = {4};
95  graph[3] = {4};
96  graph[4] = {5};
97  graph[5] = {};
98 
99  auto getNodeInputs = [graph](int node) -> std::vector<int>
100  {
101  return graph.find(node)->second;
102  };
103 
104  std::vector<int> targetNodes = {0, 1};
105 
106  std::vector<int> output;
107  bool sortCompleted = armnnUtils::GraphTopologicalSort<int>(targetNodes, getNodeInputs, output);
108 
109  BOOST_TEST(sortCompleted);
110 
111  std::vector<int> correctResult = {5, 4, 2, 0, 3, 1};
112  BOOST_CHECK_EQUAL_COLLECTIONS(output.begin(), output.end(), correctResult.begin(), correctResult.end());
113 }

◆ BOOST_AUTO_TEST_CASE() [11/12]

BOOST_AUTO_TEST_CASE ( GraphTopologicalSortVariantTest  )

Definition at line 115 of file UtilsTests.cpp.

116 {
117  std::map<int, std::vector<int>> graph;
118 
119  graph[0] = {2};
120  graph[1] = {2};
121  graph[2] = {3, 4};
122  graph[3] = {5};
123  graph[4] = {5};
124  graph[5] = {6};
125  graph[6] = {};
126 
127  auto getNodeInputs = [graph](int node) -> std::vector<int>
128  {
129  return graph.find(node)->second;
130  };
131 
132  std::vector<int> targetNodes = {0, 1};
133 
134  std::vector<int> output;
135  bool sortCompleted = armnnUtils::GraphTopologicalSort<int>(targetNodes, getNodeInputs, output);
136 
137  BOOST_TEST(sortCompleted);
138 
139  std::vector<int> correctResult = {6, 5, 3, 4, 2, 0, 1};
140  BOOST_CHECK_EQUAL_COLLECTIONS(output.begin(), output.end(), correctResult.begin(), correctResult.end());
141 }

◆ BOOST_AUTO_TEST_CASE() [12/12]

BOOST_AUTO_TEST_CASE ( CyclicalGraphTopologicalSortTest  )

Definition at line 143 of file UtilsTests.cpp.

References BOOST_AUTO_TEST_SUITE_END().

144 {
145  std::map<int, std::vector<int>> graph;
146 
147  graph[0] = {1};
148  graph[1] = {2};
149  graph[2] = {0};
150 
151  auto getNodeInputs = [graph](int node) -> std::vector<int>
152  {
153  return graph.find(node)->second;
154  };
155 
156  std::vector<int> targetNodes = {0};
157 
158  std::vector<int> output;
159  bool sortCompleted = armnnUtils::GraphTopologicalSort<int>(targetNodes, getNodeInputs, output);
160 
161  BOOST_TEST(!sortCompleted);
162 }