ArmNN
 20.02
WorkloadDataValidation.cpp File Reference

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (BatchNormalizationQueueDescriptor_Validate_DifferentQuantizationData)
 
 BOOST_AUTO_TEST_CASE (QueueDescriptor_Validate_WrongNumOfInputsOutputs)
 
 BOOST_AUTO_TEST_CASE (RefPooling2dFloat32Workload_Validate_WrongDimTensor)
 
 BOOST_AUTO_TEST_CASE (SoftmaxQueueDescriptor_Validate_WrongInputHeight)
 
 BOOST_AUTO_TEST_CASE (FullyConnectedQueueDescriptor_Validate_RequiredDataMissing)
 
 BOOST_AUTO_TEST_CASE (NormalizationQueueDescriptor_Validate_WrongInputHeight)
 
 BOOST_AUTO_TEST_CASE (SplitterQueueDescriptor_Validate_WrongWindow)
 
 BOOST_AUTO_TEST_CASE (ConcatQueueDescriptor_Validate_WrongWindow)
 
 BOOST_AUTO_TEST_CASE (AdditionQueueDescriptor_Validate_InputNumbers)
 
 BOOST_AUTO_TEST_CASE (AdditionQueueDescriptor_Validate_InputShapes)
 
 BOOST_AUTO_TEST_CASE (MultiplicationQueueDescriptor_Validate_InputTensorDimensionMismatch)
 
 BOOST_AUTO_TEST_CASE (ReshapeQueueDescriptor_Validate_MismatchingNumElements)
 
 BOOST_AUTO_TEST_CASE (LstmQueueDescriptor_Validate)
 
 BOOST_AUTO_TEST_CASE (BiasPerAxisQuantization_Validate)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/14]

BOOST_AUTO_TEST_CASE ( BatchNormalizationQueueDescriptor_Validate_DifferentQuantizationData  )

Definition at line 22 of file WorkloadDataValidation.cpp.

References BatchNormalizationQueueDescriptor::m_Beta, BatchNormalizationQueueDescriptor::m_Gamma, BatchNormalizationQueueDescriptor::m_Mean, BatchNormalizationQueueDescriptor::m_Variance, and armnn::QAsymmU8.

23 {
24  TensorShape inputShape { 1, 3, 2, 2 };
25  TensorShape outputShape { 1, 3, 2, 2 };
26 
27  TensorInfo inputTensorInfo(inputShape, armnn::DataType::QAsymmU8, .1f, 125);
28  TensorInfo outputTensorInfo(outputShape, armnn::DataType::QAsymmU8, .2f, 120);
29 
31  WorkloadInfo invalidInfo;
32 
33  unsigned int sameShape[] = { 10 };
34  TensorInfo sameInfo = armnn::TensorInfo(1, sameShape, armnn::DataType::QAsymmU8);
35  ScopedCpuTensorHandle sameTensor(sameInfo);
36 
37  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
38  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
39 
40  invalidData.m_Mean = &sameTensor;
41  invalidData.m_Variance = &sameTensor;
42  invalidData.m_Beta= &sameTensor;
43  invalidData.m_Gamma = &sameTensor;
44 
45  BOOST_CHECK_NO_THROW(RefBatchNormalizationWorkload(invalidData, invalidInfo));
46 }
const ConstCpuTensorHandle * m_Gamma
const ConstCpuTensorHandle * m_Beta
const ConstCpuTensorHandle * m_Mean
const ConstCpuTensorHandle * m_Variance
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [2/14]

BOOST_AUTO_TEST_CASE ( QueueDescriptor_Validate_WrongNumOfInputsOutputs  )

Definition at line 48 of file WorkloadDataValidation.cpp.

49 {
50  InputQueueDescriptor invalidData;
51  WorkloadInfo invalidInfo;
52  //Invalid argument exception is expected, because no inputs and no outputs were defined.
53  BOOST_CHECK_THROW(RefWorkloadFactory().CreateInput(invalidData, invalidInfo), armnn::InvalidArgumentException);
54 }
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [3/14]

BOOST_AUTO_TEST_CASE ( RefPooling2dFloat32Workload_Validate_WrongDimTensor  )

Definition at line 56 of file WorkloadDataValidation.cpp.

References armnn::Float32.

57 {
58  armnn::TensorInfo inputTensorInfo;
59  armnn::TensorInfo outputTensorInfo;
60 
61  unsigned int inputShape[] = {2, 3, 4}; // <- Invalid - input tensor has to be 4D.
62  unsigned int outputShape[] = {2, 3, 4, 5};
63 
64  outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
65  inputTensorInfo = armnn::TensorInfo(3, inputShape, armnn::DataType::Float32);
66 
67  Pooling2dQueueDescriptor invalidData;
68  WorkloadInfo invalidInfo;
69 
70  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
71  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
72 
73  // Invalid argument exception is expected, input tensor has to be 4D.
74  BOOST_CHECK_THROW(RefPooling2dWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
75 }
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [4/14]

BOOST_AUTO_TEST_CASE ( SoftmaxQueueDescriptor_Validate_WrongInputHeight  )

Definition at line 77 of file WorkloadDataValidation.cpp.

References armnn::Float32.

78 {
79  unsigned int inputHeight = 1;
80  unsigned int inputWidth = 1;
81  unsigned int inputChannels = 4;
82  unsigned int inputNum = 2;
83 
84  unsigned int outputChannels = inputChannels;
85  unsigned int outputHeight = inputHeight + 1; //Makes data invalid - Softmax expects height and width to be 1.
86  unsigned int outputWidth = inputWidth;
87  unsigned int outputNum = inputNum;
88 
89  armnn::TensorInfo inputTensorInfo;
90  armnn::TensorInfo outputTensorInfo;
91 
92  unsigned int inputShape[] = { inputNum, inputChannels, inputHeight, inputWidth };
93  unsigned int outputShape[] = { outputNum, outputChannels, outputHeight, outputWidth };
94 
95  inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
96  outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
97 
98  SoftmaxQueueDescriptor invalidData;
99  WorkloadInfo invalidInfo;
100 
101  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
102  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
103 
104  //Invalid argument exception is expected, because height != 1.
105  BOOST_CHECK_THROW(RefSoftmaxWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
106 }
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [5/14]

BOOST_AUTO_TEST_CASE ( FullyConnectedQueueDescriptor_Validate_RequiredDataMissing  )

Definition at line 108 of file WorkloadDataValidation.cpp.

References armnn::Float32, FullyConnectedQueueDescriptor::m_Bias, FullyConnectedDescriptor::m_BiasEnabled, QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters, FullyConnectedDescriptor::m_TransposeWeightMatrix, and FullyConnectedQueueDescriptor::m_Weight.

109 {
110  unsigned int inputWidth = 1;
111  unsigned int inputHeight = 1;
112  unsigned int inputChannels = 5;
113  unsigned int inputNum = 2;
114 
115  unsigned int outputWidth = 1;
116  unsigned int outputHeight = 1;
117  unsigned int outputChannels = 3;
118  unsigned int outputNum = 2;
119 
120  // Define the tensor descriptors.
121  armnn::TensorInfo inputTensorInfo;
122  armnn::TensorInfo outputTensorInfo;
123  armnn::TensorInfo weightsDesc;
124  armnn::TensorInfo biasesDesc;
125 
126  unsigned int inputShape[] = { inputNum, inputChannels, inputHeight, inputWidth };
127  unsigned int outputShape[] = { outputNum, outputChannels, outputHeight, outputWidth };
128  unsigned int weightsShape[] = { 1, 1, inputChannels, outputChannels };
129  unsigned int biasShape[] = { 1, outputChannels, outputHeight, outputWidth };
130 
131  inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
132  outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
133  weightsDesc = armnn::TensorInfo(4, weightsShape, armnn::DataType::Float32);
134  biasesDesc = armnn::TensorInfo(4, biasShape, armnn::DataType::Float32);
135 
136  FullyConnectedQueueDescriptor invalidData;
137  WorkloadInfo invalidInfo;
138 
139  ScopedCpuTensorHandle weightTensor(weightsDesc);
140  ScopedCpuTensorHandle biasTensor(biasesDesc);
141 
142  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
143  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
144  invalidData.m_Weight = &weightTensor;
145  invalidData.m_Bias = &biasTensor;
146  invalidData.m_Parameters.m_BiasEnabled = true;
147  invalidData.m_Parameters.m_TransposeWeightMatrix = false;
148 
149 
150  //Invalid argument exception is expected, because not all required fields have been provided.
151  //In particular inputsData[0], outputsData[0] and weightsData can not be null.
152  BOOST_CHECK_THROW(RefFullyConnectedWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
153 }
const ConstCpuTensorHandle * m_Weight
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
bool m_BiasEnabled
Enable/disable bias.
Contains information about inputs and outputs to a layer.
const ConstCpuTensorHandle * m_Bias

◆ BOOST_AUTO_TEST_CASE() [6/14]

BOOST_AUTO_TEST_CASE ( NormalizationQueueDescriptor_Validate_WrongInputHeight  )

Definition at line 156 of file WorkloadDataValidation.cpp.

References armnn::Across, armnn::Float32, armnn::LocalBrightness, NormalizationDescriptor::m_Alpha, NormalizationDescriptor::m_Beta, NormalizationDescriptor::m_K, NormalizationDescriptor::m_NormChannelType, NormalizationDescriptor::m_NormMethodType, NormalizationDescriptor::m_NormSize, and QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters.

157 {
158  constexpr unsigned int inputNum = 5;
159  constexpr unsigned int inputHeight = 32;
160  constexpr unsigned int inputWidth = 24;
161  constexpr unsigned int inputChannels = 3;
162 
163  constexpr unsigned int outputNum = inputNum;
164  constexpr unsigned int outputChannels = inputChannels;
165  constexpr unsigned int outputHeight = inputHeight + 1; //Makes data invalid - normalization requires.
166  //Input and output to have the same dimensions.
167  constexpr unsigned int outputWidth = inputWidth;
168 
169 
170  armnn::TensorInfo inputTensorInfo;
171  armnn::TensorInfo outputTensorInfo;
172 
173  unsigned int inputShape[] = {inputNum, inputChannels, inputHeight, inputWidth};
174  unsigned int outputShape[] = {outputNum, outputChannels, outputHeight, outputWidth};
175 
176  inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
177  outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
178 
179 
182  float alpha = 1.f;
183  float beta = 1.f;
184  float kappa = 1.f;
185  uint32_t normSize = 5;
186 
187  NormalizationQueueDescriptor invalidData;
188  WorkloadInfo invalidInfo;
189 
190  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
191  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
192  invalidData.m_Parameters.m_NormChannelType = normChannel;
193  invalidData.m_Parameters.m_NormMethodType = normMethod;
194  invalidData.m_Parameters.m_NormSize = normSize;
195  invalidData.m_Parameters.m_Alpha = alpha;
196  invalidData.m_Parameters.m_Beta = beta;
197  invalidData.m_Parameters.m_K = kappa;
198 
199  //Invalid argument exception is expected, because input height != output height.
200  BOOST_CHECK_THROW(RefNormalizationWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
201 }
float m_K
Kappa value used for the across channel normalization equation.
float m_Alpha
Alpha value for the normalization equation.
NormalizationAlgorithmChannel
Definition: Types.hpp:126
NormalizationAlgorithmMethod m_NormMethodType
Normalization method algorithm to use (LocalBrightness, LocalContrast).
NormalizationAlgorithmChannel m_NormChannelType
Normalization channel algorithm to use (Across, Within).
Contains information about inputs and outputs to a layer.
Krichevsky 2012: Local Brightness Normalization.
NormalizationAlgorithmMethod
Definition: Types.hpp:132
float m_Beta
Beta value for the normalization equation.
uint32_t m_NormSize
Depth radius value.

◆ BOOST_AUTO_TEST_CASE() [7/14]

BOOST_AUTO_TEST_CASE ( SplitterQueueDescriptor_Validate_WrongWindow  )

Definition at line 203 of file WorkloadDataValidation.cpp.

References armnn::Float32, and SplitterQueueDescriptor::m_ViewOrigins.

204 {
205  constexpr unsigned int inputNum = 1;
206  constexpr unsigned int inputHeight = 32;
207  constexpr unsigned int inputWidth = 24;
208  constexpr unsigned int inputChannels = 3;
209 
210  constexpr unsigned int outputNum = inputNum;
211  constexpr unsigned int outputChannels = inputChannels;
212  constexpr unsigned int outputHeight = 18;
213  constexpr unsigned int outputWidth = inputWidth;
214 
215 
216  armnn::TensorInfo inputTensorInfo;
217  armnn::TensorInfo outputTensorInfo;
218 
219  unsigned int inputShape[] = {inputNum, inputChannels, inputHeight, inputWidth};
220  unsigned int outputShape[] = {outputNum, outputChannels, outputHeight, outputWidth};
221 
222  inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
223  outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
224 
225  SplitterQueueDescriptor invalidData;
226  WorkloadInfo invalidInfo;
227 
228  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
229  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
230 
231  // Invalid, since it has only 3 dimensions while the input tensor is 4d.
232  std::vector<unsigned int> wOrigin = {0, 0, 0};
234  invalidData.m_ViewOrigins.push_back(window);
235 
236  BOOST_TEST_INFO("Invalid argument exception is expected, because split window dimensionality does not "
237  "match input.");
238  BOOST_CHECK_THROW(RefSplitterWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
239 
240  // Invalid, since window extends past the boundary of input tensor.
241  std::vector<unsigned int> wOrigin3 = {0, 0, 15, 0};
243  invalidData.m_ViewOrigins[0] = window3;
244  BOOST_TEST_INFO("Invalid argument exception is expected (wOrigin3[2]+ outputHeight > inputHeight");
245  BOOST_CHECK_THROW(RefSplitterWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
246 
247 
248  std::vector<unsigned int> wOrigin4 = {0, 0, 0, 0};
250  invalidData.m_ViewOrigins[0] = window4;
251 
252  std::vector<unsigned int> wOrigin5 = {1, 16, 20, 2};
254  invalidData.m_ViewOrigins.push_back(window5);
255 
256  BOOST_TEST_INFO("Invalid exception due to number of split windows not matching number of outputs.");
257  BOOST_CHECK_THROW(RefSplitterWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
258 }
std::vector< ViewOrigin > m_ViewOrigins
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [8/14]

BOOST_AUTO_TEST_CASE ( ConcatQueueDescriptor_Validate_WrongWindow  )

Definition at line 261 of file WorkloadDataValidation.cpp.

References armnn::Float32, and ConcatQueueDescriptor::m_ViewOrigins.

262 {
263  constexpr unsigned int inputNum = 1;
264  constexpr unsigned int inputChannels = 3;
265  constexpr unsigned int inputHeight = 32;
266  constexpr unsigned int inputWidth = 24;
267 
268  constexpr unsigned int outputNum = 1;
269  constexpr unsigned int outputChannels = 3;
270  constexpr unsigned int outputHeight = 32;
271  constexpr unsigned int outputWidth = 24;
272 
273 
274  armnn::TensorInfo inputTensorInfo;
275  armnn::TensorInfo outputTensorInfo;
276 
277  unsigned int inputShape[] = {inputNum, inputChannels, inputHeight, inputWidth};
278  unsigned int outputShape[] = {outputNum, outputChannels, outputHeight, outputWidth};
279 
280  inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
281  outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
282 
283  ConcatQueueDescriptor invalidData;
284  WorkloadInfo invalidInfo;
285 
286  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
287  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
288 
289  // Invalid, since it has only 3 dimensions while the input tensor is 4d.
290  std::vector<unsigned int> wOrigin = {0, 0, 0};
292  invalidData.m_ViewOrigins.push_back(window);
293 
294  BOOST_TEST_INFO("Invalid argument exception is expected, because merge window dimensionality does not "
295  "match input.");
296  BOOST_CHECK_THROW(RefConcatWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
297 
298  // Invalid, since window extends past the boundary of output tensor.
299  std::vector<unsigned int> wOrigin3 = {0, 0, 15, 0};
301  invalidData.m_ViewOrigins[0] = window3;
302  BOOST_TEST_INFO("Invalid argument exception is expected (wOrigin3[2]+ inputHeight > outputHeight");
303  BOOST_CHECK_THROW(RefConcatWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
304 
305 
306  std::vector<unsigned int> wOrigin4 = {0, 0, 0, 0};
308  invalidData.m_ViewOrigins[0] = window4;
309 
310  std::vector<unsigned int> wOrigin5 = {1, 16, 20, 2};
312  invalidData.m_ViewOrigins.push_back(window5);
313 
314  BOOST_TEST_INFO("Invalid exception due to number of merge windows not matching number of inputs.");
315  BOOST_CHECK_THROW(RefConcatWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
316 }
std::vector< ViewOrigin > m_ViewOrigins
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [9/14]

BOOST_AUTO_TEST_CASE ( AdditionQueueDescriptor_Validate_InputNumbers  )

Definition at line 318 of file WorkloadDataValidation.cpp.

References armnn::Float32.

319 {
320  armnn::TensorInfo input1TensorInfo;
321  armnn::TensorInfo input2TensorInfo;
322  armnn::TensorInfo input3TensorInfo;
323  armnn::TensorInfo outputTensorInfo;
324 
325  unsigned int shape[] = {1, 1, 1, 1};
326 
327  input1TensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
328  input2TensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
329  input3TensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
330  outputTensorInfo = armnn::TensorInfo(4, shape, armnn::DataType::Float32);
331 
332  AdditionQueueDescriptor invalidData;
333  WorkloadInfo invalidInfo;
334 
335  AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr);
336  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
337 
338  // Too few inputs.
339  BOOST_CHECK_THROW(RefAdditionWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
340 
341  AddInputToWorkload(invalidData, invalidInfo, input2TensorInfo, nullptr);
342 
343  // Correct.
344  BOOST_CHECK_NO_THROW(RefAdditionWorkload(invalidData, invalidInfo));
345 
346  AddInputToWorkload(invalidData, invalidInfo, input3TensorInfo, nullptr);
347 
348  // Too many inputs.
349  BOOST_CHECK_THROW(RefAdditionWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
350 }
RefElementwiseWorkload< std::plus< float >, AdditionQueueDescriptor, StringMapping::RefAdditionWorkload_Execute > RefAdditionWorkload
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [10/14]

BOOST_AUTO_TEST_CASE ( AdditionQueueDescriptor_Validate_InputShapes  )

Definition at line 352 of file WorkloadDataValidation.cpp.

References armnn::Float32.

353 {
354  armnn::TensorInfo input1TensorInfo;
355  armnn::TensorInfo input2TensorInfo;
356  armnn::TensorInfo outputTensorInfo;
357 
358  unsigned int shape1[] = {1, 1, 2, 1};
359  unsigned int shape2[] = {1, 1, 3, 2};
360 
361  // Incompatible shapes even with broadcasting.
362  {
363  input1TensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32);
364  input2TensorInfo = armnn::TensorInfo(4, shape2, armnn::DataType::Float32);
365  outputTensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32);
366 
367  AdditionQueueDescriptor invalidData;
368  WorkloadInfo invalidInfo;
369 
370  AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr);
371  AddInputToWorkload(invalidData, invalidInfo, input2TensorInfo, nullptr);
372  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
373 
374  BOOST_CHECK_THROW(RefAdditionWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
375  }
376 
377  // Output size not compatible with input sizes.
378  {
379  input1TensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32);
380  input2TensorInfo = armnn::TensorInfo(4, shape1, armnn::DataType::Float32);
381  outputTensorInfo = armnn::TensorInfo(4, shape2, armnn::DataType::Float32);
382 
383  AdditionQueueDescriptor invalidData;
384  WorkloadInfo invalidInfo;
385 
386  AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr);
387  AddInputToWorkload(invalidData, invalidInfo, input2TensorInfo, nullptr);
388  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
389 
390  // Output differs.
391  BOOST_CHECK_THROW(RefAdditionWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
392  }
393 }
RefElementwiseWorkload< std::plus< float >, AdditionQueueDescriptor, StringMapping::RefAdditionWorkload_Execute > RefAdditionWorkload
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [11/14]

BOOST_AUTO_TEST_CASE ( MultiplicationQueueDescriptor_Validate_InputTensorDimensionMismatch  )

Definition at line 395 of file WorkloadDataValidation.cpp.

References armnn::Float32.

396 {
397  armnn::TensorInfo input0TensorInfo;
398  armnn::TensorInfo input1TensorInfo;
399  armnn::TensorInfo outputTensorInfo;
400 
401  constexpr unsigned int input0Shape[] = { 2, 2, 4, 4 };
402  constexpr std::size_t dimensionCount = std::extent<decltype(input0Shape)>::value;
403 
404  // Checks dimension consistency for input tensors.
405  for (unsigned int dimIndex = 0; dimIndex < dimensionCount; ++dimIndex)
406  {
407  unsigned int input1Shape[dimensionCount];
408  for (unsigned int i = 0; i < dimensionCount; ++i)
409  {
410  input1Shape[i] = input0Shape[i];
411  }
412 
413  ++input1Shape[dimIndex];
414 
415  input0TensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32);
416  input1TensorInfo = armnn::TensorInfo(dimensionCount, input1Shape, armnn::DataType::Float32);
417  outputTensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32);
418 
419  MultiplicationQueueDescriptor invalidData;
420  WorkloadInfo invalidInfo;
421 
422  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
423  AddInputToWorkload(invalidData, invalidInfo, input0TensorInfo, nullptr);
424  AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr);
425 
426  BOOST_CHECK_THROW(RefMultiplicationWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
427  }
428 
429  // Checks dimension consistency for input and output tensors.
430  for (unsigned int dimIndex = 0; dimIndex < dimensionCount; ++dimIndex)
431  {
432  unsigned int outputShape[dimensionCount];
433  for (unsigned int i = 0; i < dimensionCount; ++i)
434  {
435  outputShape[i] = input0Shape[i];
436  }
437 
438  ++outputShape[dimIndex];
439 
440  input0TensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32);
441  input1TensorInfo = armnn::TensorInfo(dimensionCount, input0Shape, armnn::DataType::Float32);
442  outputTensorInfo = armnn::TensorInfo(dimensionCount, outputShape, armnn::DataType::Float32);
443 
444  MultiplicationQueueDescriptor invalidData;
445  WorkloadInfo invalidInfo;
446 
447  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
448  AddInputToWorkload(invalidData, invalidInfo, input0TensorInfo, nullptr);
449  AddInputToWorkload(invalidData, invalidInfo, input1TensorInfo, nullptr);
450 
451  BOOST_CHECK_THROW(RefMultiplicationWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
452  }
453 }
RefElementwiseWorkload< std::multiplies< float >, MultiplicationQueueDescriptor, StringMapping::RefMultiplicationWorkload_Execute > RefMultiplicationWorkload
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [12/14]

BOOST_AUTO_TEST_CASE ( ReshapeQueueDescriptor_Validate_MismatchingNumElements  )

Definition at line 455 of file WorkloadDataValidation.cpp.

References armnn::Float32.

456 {
457  armnn::TensorInfo inputTensorInfo;
458  armnn::TensorInfo outputTensorInfo;
459 
460  // The input and output shapes should have the same number of elements, but these don't.
461  unsigned int inputShape[] = { 1, 1, 2, 3 };
462  unsigned int outputShape[] = { 1, 1, 1, 2 };
463 
464  inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
465  outputTensorInfo = armnn::TensorInfo(4, outputShape, armnn::DataType::Float32);
466 
467  ReshapeQueueDescriptor invalidData;
468  WorkloadInfo invalidInfo;
469 
470  AddInputToWorkload(invalidData, invalidInfo, inputTensorInfo, nullptr);
471  AddOutputToWorkload(invalidData, invalidInfo, outputTensorInfo, nullptr);
472 
473  // InvalidArgumentException is expected, because the number of elements don't match.
474  BOOST_CHECK_THROW(RefReshapeWorkload(invalidData, invalidInfo), armnn::InvalidArgumentException);
475 }
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [13/14]

BOOST_AUTO_TEST_CASE ( LstmQueueDescriptor_Validate  )

Definition at line 478 of file WorkloadDataValidation.cpp.

References armnn::Float32, and armnn::info.

479 {
481 
482  float qScale = 0.0f;
483  int32_t qOffset = 0;
484 
485  unsigned int batchSize = 2;
486  unsigned int outputSize = 3;
487  unsigned int inputSize = 5;
488  unsigned numUnits = 4;
489 
490  armnn::TensorInfo inputTensorInfo({batchSize , inputSize}, dataType, qScale, qOffset );
491  armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, dataType, qScale, qOffset);
492  armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, dataType, qScale, qOffset);
493 
494  // Scratch buffer size with CIFG [batchSize, numUnits * 4]
495  armnn::TensorInfo scratchBufferTensorInfo({batchSize, numUnits * 4}, dataType, qScale, qOffset);
496  armnn::TensorInfo cellStateOutTensorInfo({batchSize, numUnits}, dataType, qScale, qOffset);
497  armnn::TensorInfo outputStateOutTensorInfo({batchSize, outputSize}, dataType, qScale, qOffset);
498  armnn::TensorInfo outputTensorInfo({batchSize, outputSize}, dataType, qScale, qOffset);
499 
500  armnn::TensorInfo tensorInfo3({outputSize}, dataType, qScale, qOffset);
501  armnn::TensorInfo tensorInfo4({numUnits}, dataType, qScale, qOffset);
502  armnn::TensorInfo tensorInfo4x5({numUnits, inputSize}, dataType, qScale, qOffset);
503  armnn::TensorInfo tensorInfo4x3({numUnits, outputSize}, dataType, qScale, qOffset);
504  armnn::TensorInfo tensorInfo3x4({outputSize, numUnits}, dataType, qScale, qOffset);
505 
506  LstmQueueDescriptor data;
508 
509  AddInputToWorkload(data, info, inputTensorInfo, nullptr);
510  AddInputToWorkload(data, info, outputStateInTensorInfo, nullptr);
511  AddInputToWorkload(data, info, cellStateInTensorInfo, nullptr);
512 
513  AddOutputToWorkload(data, info, scratchBufferTensorInfo, nullptr);
514  AddOutputToWorkload(data, info, outputStateOutTensorInfo, nullptr);
515  AddOutputToWorkload(data, info, cellStateOutTensorInfo, nullptr);
516  // AddOutputToWorkload(data, info, outputTensorInfo, nullptr); is left out
517 
518  armnn::ScopedCpuTensorHandle inputToInputWeightsTensor(tensorInfo4x5);
519  armnn::ScopedCpuTensorHandle inputToForgetWeightsTensor(tensorInfo4x5);
520  armnn::ScopedCpuTensorHandle inputToCellWeightsTensor(tensorInfo4x5);
521  armnn::ScopedCpuTensorHandle inputToOutputWeightsTensor(tensorInfo4x5);
522  armnn::ScopedCpuTensorHandle recurrentToForgetWeightsTensor(tensorInfo4x3);
523  armnn::ScopedCpuTensorHandle recurrentToInputWeightsTensor(tensorInfo4x3);
524  armnn::ScopedCpuTensorHandle recurrentToCellWeightsTensor(tensorInfo4x3);
525  armnn::ScopedCpuTensorHandle recurrentToOutputWeightsTensor(tensorInfo4x3);
526  armnn::ScopedCpuTensorHandle cellToInputWeightsTensor(tensorInfo4);
527  armnn::ScopedCpuTensorHandle inputGateBiasTensor(tensorInfo4);
528  armnn::ScopedCpuTensorHandle forgetGateBiasTensor(tensorInfo4);
529  armnn::ScopedCpuTensorHandle cellBiasTensor(tensorInfo4);
530  armnn::ScopedCpuTensorHandle outputGateBiasTensor(tensorInfo4);
531  armnn::ScopedCpuTensorHandle cellToForgetWeightsTensor(tensorInfo4);
532  armnn::ScopedCpuTensorHandle cellToOutputWeightsTensor(tensorInfo4);
533  armnn::ScopedCpuTensorHandle projectionWeightsTensor(tensorInfo3x4);
534  armnn::ScopedCpuTensorHandle projectionBiasTensor(tensorInfo3);
535  armnn::ScopedCpuTensorHandle inputLayerNormWeightsTensor(tensorInfo4);
536  armnn::ScopedCpuTensorHandle forgetLayerNormWeightsTensor(tensorInfo4);
537  armnn::ScopedCpuTensorHandle cellLayerNormWeightsTensor(tensorInfo4);
538  armnn::ScopedCpuTensorHandle outputLayerNormWeightsTensor(tensorInfo4);
539 
540  data.m_InputToInputWeights = &inputToInputWeightsTensor;
541  data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
542  data.m_InputToCellWeights = &inputToCellWeightsTensor;
543  data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
544  data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
545  data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
546  data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
547  data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
548  data.m_CellToInputWeights = &cellToInputWeightsTensor;
549  data.m_InputGateBias = &inputGateBiasTensor;
550  data.m_ForgetGateBias = &forgetGateBiasTensor;
551  data.m_CellBias = &cellBiasTensor;
552  data.m_OutputGateBias = &outputGateBiasTensor;
553  data.m_CellToForgetWeights = &cellToForgetWeightsTensor;
554  data.m_CellToOutputWeights = &cellToOutputWeightsTensor;
555  data.m_ProjectionWeights = &projectionWeightsTensor;
556  data.m_ProjectionBias = &projectionBiasTensor;
557 
558  data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor;
559  data.m_ForgetLayerNormWeights = &forgetLayerNormWeightsTensor;
560  data.m_CellLayerNormWeights = &cellLayerNormWeightsTensor;
561  data.m_OutputLayerNormWeights = &outputLayerNormWeightsTensor;
562 
563  // Flags to set test configuration
564  data.m_Parameters.m_ActivationFunc = 4;
565  data.m_Parameters.m_CifgEnabled = false;
566  data.m_Parameters.m_PeepholeEnabled = true;
567  data.m_Parameters.m_ProjectionEnabled = true;
568  data.m_Parameters.m_LayerNormEnabled = true;
569 
570  // check wrong number of outputs
571  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
572  AddOutputToWorkload(data, info, outputTensorInfo, nullptr);
573 
574  // check wrong cifg parameter configuration
575  data.m_Parameters.m_CifgEnabled = true;
576  armnn::TensorInfo scratchBufferTensorInfo2({batchSize, numUnits * 3}, dataType, qScale, qOffset);
577  SetWorkloadOutput(data, info, 0, scratchBufferTensorInfo2, nullptr);
578  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
579  data.m_Parameters.m_CifgEnabled = false;
580  SetWorkloadOutput(data, info, 0, scratchBufferTensorInfo, nullptr);
581 
582  // check wrong inputGateBias configuration
583  data.m_InputGateBias = nullptr;
584  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
585  data.m_InputGateBias = &inputGateBiasTensor;
586 
587  // check inconsistant projection parameters
588  data.m_Parameters.m_ProjectionEnabled = false;
589  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
590  data.m_Parameters.m_ProjectionEnabled = true;
591  data.m_ProjectionWeights = nullptr;
592  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
593  data.m_ProjectionWeights = &projectionWeightsTensor;
594 
595  // check missing input layer normalisation weights
596  data.m_InputLayerNormWeights = nullptr;
597  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
598  data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor;
599 
600  // layer norm disabled but normalisation weights are present
601  data.m_Parameters.m_LayerNormEnabled = false;
602  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
603  data.m_Parameters.m_LayerNormEnabled = true;
604 
605  // check invalid outputTensor shape
606  armnn::TensorInfo incorrectOutputTensorInfo({batchSize, outputSize + 1}, dataType, qScale, qOffset);
607  SetWorkloadOutput(data, info, 3, incorrectOutputTensorInfo, nullptr);
608  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
609  SetWorkloadOutput(data, info, 3, outputTensorInfo, nullptr);
610 
611  // check invalid cell clipping parameters
612  data.m_Parameters.m_ClippingThresCell = -1.0f;
613  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
614  data.m_Parameters.m_ClippingThresCell = 0.0f;
615 
616  // check invalid projection clipping parameters
617  data.m_Parameters.m_ClippingThresProj = -1.0f;
618  BOOST_CHECK_THROW(data.Validate(info), armnn::InvalidArgumentException);
619  data.m_Parameters.m_ClippingThresProj = 0.0f;
620 
621  // check correct configuration
622  BOOST_CHECK_NO_THROW(data.Validate(info));
623 }
DataType
Definition: Types.hpp:32
Contains information about inputs and outputs to a layer.

◆ BOOST_AUTO_TEST_CASE() [14/14]

BOOST_AUTO_TEST_CASE ( BiasPerAxisQuantization_Validate  )

Definition at line 625 of file WorkloadDataValidation.cpp.

References BOOST_AUTO_TEST_SUITE_END(), Convolution2dQueueDescriptor::m_Bias, Convolution2dDescriptor::m_BiasEnabled, QueueDescriptorWithParameters< LayerDescriptor >::m_Parameters, Convolution2dQueueDescriptor::m_Weight, armnn::QAsymmU8, armnn::QSymmS8, armnn::Signed32, and Convolution2dQueueDescriptor::Validate().

626 {
627  constexpr unsigned int nInput = 1u;
628  constexpr unsigned int cInput = 3u;
629  constexpr unsigned int hInput = 3u;
630  constexpr unsigned int wInput = 3u;
631 
632  constexpr unsigned int nOutput = nInput;
633  constexpr unsigned int cOutput = cInput;
634  constexpr unsigned int hOutput = 1u;
635  constexpr unsigned int wOutput = 1u;
636 
637  const TensorShape inputShape { nInput, cInput, hInput, wInput };
638  const TensorShape outputShape{ nOutput, cOutput, hOutput, wOutput };
639  const TensorShape weightShape{ cOutput, cInput, hInput, wInput };
640  const TensorShape biasShape { cOutput };
641 
642  constexpr DataType inputType = DataType::QAsymmU8;
643  constexpr DataType weightType = DataType::QSymmS8;
644  constexpr DataType biasType = DataType::Signed32;
645 
646  constexpr float perTensorScale = 1.5f;
647  const TensorInfo inputInfo (inputShape, inputType, perTensorScale);
648  const TensorInfo outputInfo(outputShape, inputType, perTensorScale);
649 
650  const std::vector<float> weightPerAxisScales = { 2.50f, 3.50f };
651  const TensorInfo weightInfo(weightShape, weightType, weightPerAxisScales, 0);
652 
653  Convolution2dQueueDescriptor queueDescriptor;
654  queueDescriptor.m_Parameters.m_BiasEnabled = true;
655 
656  WorkloadInfo workloadInfo;
657  AddInputToWorkload(queueDescriptor, workloadInfo, inputInfo, nullptr);
658  AddOutputToWorkload(queueDescriptor, workloadInfo, outputInfo, nullptr);
659 
660  ScopedCpuTensorHandle weightTensor(weightInfo);
661  queueDescriptor.m_Weight = &weightTensor;
662 
663  // Test 1: correct per-axis quantization values
664  const std::vector<float> biasPerAxisScales1 = { 3.75f, 5.25f };
665  const TensorInfo biasInfo1(biasShape, biasType, biasPerAxisScales1, 0);
666 
667  ScopedCpuTensorHandle biasHandle1(biasInfo1);
668  queueDescriptor.m_Bias = &biasHandle1;
669 
670  BOOST_CHECK_NO_THROW(queueDescriptor.Validate(workloadInfo));
671 
672  // Test 2: wrong per-axis quantization values
673  const std::vector<float> biasPerAxisScales2 = { 4.00f, 5.00f };
674  const TensorInfo biasInfo2(biasShape, biasType, biasPerAxisScales2, 0);
675 
676  ScopedCpuTensorHandle biasHandle2(biasInfo2);
677  queueDescriptor.m_Bias = &biasHandle2;
678 
679  BOOST_CHECK_THROW(queueDescriptor.Validate(workloadInfo), InvalidArgumentException);
680 
681  // Test 3: mismatched number of quantization scales
682  const std::vector<float> biasPerAxisScales3 = { 3.75f, 5.25f, 5.25f };
683  const TensorInfo biasInfo3(biasShape, biasType, biasPerAxisScales3, 0);
684 
685  ScopedCpuTensorHandle biasHandle3(biasInfo3);
686  queueDescriptor.m_Bias = &biasHandle3;
687 
688  BOOST_CHECK_THROW(queueDescriptor.Validate(workloadInfo), InvalidArgumentException);
689 }
bool m_BiasEnabled
Enable/disable bias.
const ConstCpuTensorHandle * m_Bias
DataType
Definition: Types.hpp:32
const ConstCpuTensorHandle * m_Weight
void Validate(const WorkloadInfo &workloadInfo) const
Contains information about inputs and outputs to a layer.