ArmNN
 21.11
SoftmaxTestImpl.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "SoftmaxTestImpl.hpp"
7 
8 #include <QuantizeHelper.hpp>
9 #include <ResolveType.hpp>
10 
11 
13 
16 
17 #include <test/TensorHelpers.hpp>
18 
19 #include <algorithm>
20 
21 namespace
22 {
23 
24 struct Simple3dSoftmaxOutputData
25 {
26  const std::vector<float> outputData =
27  {
28  0.0964599f, 0.26220518f, 0.0964599f, 0.0964599f,
29  0.15903549f, 0.0964599f, 0.0964599f, 0.0964599f
30  };
31 
32  const armnn::TensorShape inputShape{ 1, 8, 1 };
33 
34  const std::vector<float> inputData =
35  {
36  0.0f, 1.0f, 0.0f, 0.0f,
37  0.5f, 0.0f, 0.0f, 0.0f,
38  };
39 };
40 
41 struct Simple4dSoftmaxData
42 {
43  const armnn::TensorShape inputShape{ 1, 8, 1, 1 };
44 
45  const std::vector<float> outputData =
46  {
47  0.0964599f, 0.26220518f, 0.0964599f, 0.0964599f,
48  0.15903549f, 0.0964599f, 0.0964599f, 0.0964599f
49  };
50 
51  const std::vector<float> inputData =
52  {
53  0.0f, 1.0f, 0.0f, 0.0f,
54  0.5f, 0.0f, 0.0f, 0.0f
55  };
56 };
57 
58 template<armnn::DataType ArmnnType, std::size_t n, typename T = armnn::ResolveType<ArmnnType>>
59 LayerTestResult<T, n> SimpleSoftmaxBaseTestImpl(
60  armnn::IWorkloadFactory& workloadFactory,
62  const armnn::ITensorHandleFactory& tensorHandleFactory,
63  float beta,
64  const armnn::TensorShape& inputShape,
65  const std::vector<float>& outputData,
66  const std::vector<float>& inputData,
67  int axis = -1)
68 {
69  using std::exp;
70 
71  const float qScale = 1.f / 256.f;
72  const int qOffset = 0;
73 
74  armnn::TensorInfo inputTensorInfo;
75  armnn::TensorInfo outputTensorInfo;
76 
77  inputTensorInfo = armnn::TensorInfo(inputShape, ArmnnType);
78  inputTensorInfo.SetQuantizationScale(qScale);
79  inputTensorInfo.SetQuantizationOffset(qOffset);
80 
81  outputTensorInfo = armnn::TensorInfo(inputShape, ArmnnType);
82  outputTensorInfo.SetQuantizationScale(qScale);
83  outputTensorInfo.SetQuantizationOffset(qOffset);
84 
85  // Each row is independently softmax'd.
86  std::vector<T> input = armnnUtils::QuantizedVector<T>(inputData, qScale, qOffset);
87  std::vector<T> expectedOutput = armnnUtils::QuantizedVector<T>(outputData, qScale, qOffset);
88  std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
89 
90  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
91  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
92 
94  data.m_Parameters.m_Beta = beta;
95  data.m_Parameters.m_Axis = axis;
96 
98  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
99  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
100 
101  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSoftmax(data, info);
102 
103  inputHandle->Allocate();
104  outputHandle->Allocate();
105  CopyDataToITensorHandle(inputHandle.get(), input.data());
106 
107  ARMNN_ASSERT(workload);
108 
109  ExecuteWorkload(*workload, memoryManager);
110 
111  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
112 
113  return LayerTestResult<T, n>(actualOutput,
114  expectedOutput,
115  outputHandle->GetShape(),
116  outputTensorInfo.GetShape());
117 }
118 
119 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
120 LayerTestResult<T, 2> SimpleSoftmaxTestImpl(
121  armnn::IWorkloadFactory& workloadFactory,
123  const armnn::ITensorHandleFactory& tensorHandleFactory,
124  float beta)
125 {
126  using std::exp;
127  const armnn::TensorShape inputShape{ 2, 4 };
128 
129  float x0[4] = { exp((0.f - 1.0f) * beta), exp((1.0f - 1.0f) * beta),
130  exp((0.0f - 1.0f) * beta), exp((0.0f - 1.0f) * beta) };
131  float sum0 = x0[0] + x0[1] + x0[2] + x0[3];
132  float x1[4] = { exp((0.5f - 0.5f) * beta), exp((0.0f - 0.5f) * beta),
133  exp((0.0f - 0.5f) * beta), exp((0.0f - 0.5f) * beta) };
134  float sum1 = x1[0] + x1[1] + x1[2] + x1[3];
135 
136  const std::vector<float> outputData = { x0[0] / sum0, x0[1] / sum0, x0[2] / sum0, x0[3] / sum0,
137  x1[0] / sum1, x1[1] / sum1, x1[2] / sum1, x1[3] / sum1 };
138 
139  const std::vector<float> inputData =
140  {
141  0.f, 1.f, 0.f, 0.f,
142  .5f, 0.f, 0.f, 0.f,
143  };
144 
145  return SimpleSoftmaxBaseTestImpl<ArmnnType, 2>(workloadFactory, memoryManager, tensorHandleFactory, beta,
146  inputShape, outputData, inputData);
147 }
148 
149 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
150 LayerTestResult<T, 2> SimpleSoftmaxTestImpl(
151  armnn::IWorkloadFactory& workloadFactory,
153  const armnn::ITensorHandleFactory& tensorHandleFactory,
154  float beta,
155  int axis)
156 {
157  armnn::TensorShape inputShape;
158  std::vector<float> inputData;
159  std::vector<float> outputData;
160  switch (axis)
161  {
162  case -2:
163  case 0:
164  {
165  inputShape = {5, 2};
166 
167  inputData =
168  {
169  17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f
170  };
171 
172  outputData =
173  {
174  0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f,
175  0.087144312427294f,
176  0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f,
177  7.246299848982885e-08f
178  };
179  break;
180  }
181  case -1:
182  case 1:
183  {
184  inputShape = {2, 5};
185 
186  inputData =
187  {
188  17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f
189  };
190 
191  outputData =
192  {
193  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
194  7.246299848982885e-08f,
195  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
196  7.246299848982885e-08f
197  };
198  break;
199  }
200  }
201  return SimpleSoftmaxBaseTestImpl<ArmnnType, 2>(workloadFactory, memoryManager, tensorHandleFactory, beta,
202  inputShape, outputData, inputData, axis);
203 }
204 
205 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
206 LayerTestResult<T, 3> Simple3dSoftmaxTestImpl(
207  armnn::IWorkloadFactory& workloadFactory,
209  const armnn::ITensorHandleFactory& tensorHandleFactory,
210  float beta,
211  const armnn::TensorShape& inputShape,
212  const std::vector<float>& outputData,
213  const std::vector<float>& inputData,
214  int axis = 1)
215 {
216  return SimpleSoftmaxBaseTestImpl<ArmnnType, 3>(workloadFactory, memoryManager, tensorHandleFactory, beta,
217  inputShape, outputData, inputData, axis);
218 }
219 
220 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
221 LayerTestResult<T, 4> Simple4dSoftmaxTestImpl(
222  armnn::IWorkloadFactory& workloadFactory,
224  const armnn::ITensorHandleFactory& tensorHandleFactory,
225  float beta,
226  const armnn::TensorShape& inputShape,
227  const std::vector<float>& outputData,
228  const std::vector<float>& inputData,
229  int axis = 1)
230 {
231 
232  return SimpleSoftmaxBaseTestImpl<ArmnnType, 4>(workloadFactory, memoryManager, tensorHandleFactory, beta,
233  inputShape, outputData, inputData, axis);
234 }
235 
236 template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
237 LayerTestResult<T, 2> CompareSoftmaxTestImpl(
238  armnn::IWorkloadFactory& workloadFactory,
240  armnn::IWorkloadFactory& refWorkloadFactory,
241  const armnn::ITensorHandleFactory& tensorHandleFactory,
242  const armnn::ITensorHandleFactory& refTensorHandleFactory,
243  float beta)
244 {
245  const int batchSize = 20;
246  const int channels = 30;
247 
248  armnn::TensorInfo inputTensorInfo;
249  armnn::TensorInfo outputTensorInfo;
250 
251  unsigned int inputShape[] = { batchSize, channels };
252 
253  inputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType);
254  outputTensorInfo = armnn::TensorInfo(2, inputShape, ArmnnType);
255  float qScale = 1.f / 256.f;
256  int qOffset = 0;
257  inputTensorInfo.SetQuantizationScale(qScale);
258  inputTensorInfo.SetQuantizationOffset(qOffset);
259  outputTensorInfo.SetQuantizationScale(qScale);
260  outputTensorInfo.SetQuantizationOffset(qOffset);
261 
262  auto input = MakeRandomTensor<T>(inputTensorInfo, 0xF00D, 0.0f, 1.0f);
263  std::vector<T> actualOutput(outputTensorInfo.GetNumElements());
264  std::vector<T> expectedOutput(outputTensorInfo.GetNumElements());
265 
266  std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo);
267  std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo);
268 
270  data.m_Parameters.m_Beta = beta;
271 
272  armnn::WorkloadInfo info;
273  AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get());
274  AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get());
275 
276  std::unique_ptr<armnn::ITensorHandle> outputHandleRef =
277  refTensorHandleFactory.CreateTensorHandle(outputTensorInfo);
278  std::unique_ptr<armnn::ITensorHandle> inputHandleRef =
279  refTensorHandleFactory.CreateTensorHandle(inputTensorInfo);
280 
281  armnn::SoftmaxQueueDescriptor refData = data;
282  armnn::WorkloadInfo refInfo = info;
283  SetWorkloadInput(refData, refInfo, 0, inputTensorInfo, inputHandleRef.get());
284  SetWorkloadOutput(refData, refInfo, 0, outputTensorInfo, outputHandleRef.get());
285 
286  std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateSoftmax(data, info);
287  std::unique_ptr<armnn::IWorkload> workloadRef = refWorkloadFactory.CreateSoftmax(refData, refInfo);
288 
289  outputHandleRef->Allocate();
290  inputHandleRef->Allocate();
291 
292  inputHandle->Allocate();
293  outputHandle->Allocate();
294 
295  CopyDataToITensorHandle(inputHandle.get(), input.data());
296  CopyDataToITensorHandle(inputHandleRef.get(), input.data());
297 
298  ExecuteWorkload(*workload, memoryManager);
299 
300  workloadRef->Execute();
301 
302  CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get());
303  CopyDataFromITensorHandle(expectedOutput.data(), outputHandleRef.get());
304 
305  return LayerTestResult<T, 2>(actualOutput,
306  expectedOutput,
307  outputHandle->GetShape(),
308  outputTensorInfo.GetShape());
309 }
310 
311 } // anonymous namespace
312 
314  armnn::IWorkloadFactory& workloadFactory,
316  const armnn::ITensorHandleFactory& tensorHandleFactory,
317  float beta)
318 {
319  return SimpleSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, beta);
320 }
321 
323  armnn::IWorkloadFactory& workloadFactory,
325  const armnn::ITensorHandleFactory& tensorHandleFactory,
326  float beta,
327  int axis)
328 {
329  return SimpleSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager,
330  tensorHandleFactory, beta, axis);
331 }
332 
334  armnn::IWorkloadFactory& workloadFactory,
336  const armnn::ITensorHandleFactory& tensorHandleFactory,
337  float beta)
338 {
339  Simple3dSoftmaxOutputData data;
340  return Simple3dSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, beta,
341  data.inputShape, data.outputData, data.inputData);
342 }
343 
345  armnn::IWorkloadFactory& workloadFactory,
347  const armnn::ITensorHandleFactory& tensorHandleFactory,
348  float beta,
349  int axis)
350 {
351  armnn::TensorShape inputShape;
352  std::vector<float> inputData;
353  std::vector<float> outputData;
354  switch (axis)
355  {
356  case -3:
357  case 0:
358  {
359  inputShape = {5, 2, 2};
360 
361  inputData =
362  {
363  17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f,
364 
365  15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f
366  };
367 
368  outputData =
369  {
370  0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f,
371  0.236882800924671f,
372  0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.087144312427294f,
373  0.087144312427294f,
374 
375  0.087144312427294f, 0.087144312427294f, 0.032058600957022f, 0.032058600957022f,
376  0.032058600957022f,
377  0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f,
378  7.246299848982885e-08f
379  };
380  break;
381  }
382  case -2:
383  case 1:
384  {
385  inputShape = {2, 5, 2};
386 
387  inputData =
388  {
389  17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f,
390 
391  17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f
392  };
393 
394  outputData =
395  {
396  0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f,
397  0.087144312427294f,
398  0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f,
399  7.246299848982885e-08f,
400 
401  0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f,
402  0.087144312427294f,
403  0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f,
404  7.246299848982885e-08f
405  };
406  break;
407  }
408  case -1:
409  case 2:
410  {
411  inputShape = {2, 2, 5};
412 
413  inputData =
414  {
415  17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f,
416  17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f
417  };
418 
419  outputData =
420  {
421  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
422  7.246299848982885e-08f,
423  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
424  7.246299848982885e-08f,
425 
426  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
427  7.246299848982885e-08f,
428  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
429  7.246299848982885e-08f
430  };
431  break;
432  }
433  }
434 
435  return Simple3dSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory, beta,
436  inputShape, outputData, inputData, axis);
437 }
438 
440  armnn::IWorkloadFactory& workloadFactory,
442  const armnn::ITensorHandleFactory& tensorHandleFactory,
443  float beta)
444 {
445  Simple4dSoftmaxData data;
446  return Simple4dSoftmaxTestImpl<armnn::DataType::Float32>(workloadFactory, memoryManager, tensorHandleFactory,
447  beta, data.inputShape, data.outputData, data.inputData);
448 }
449 
451  armnn::IWorkloadFactory& workloadFactory,
453  const armnn::ITensorHandleFactory& tensorHandleFactory,
454  float beta,
455  int axis)
456 {
457  armnn::TensorShape inputShape;
458  std::vector<float> inputData;
459  std::vector<float> outputData;
460  switch (axis)
461  {
462  case -4:
463  case 0:
464  {
465  inputShape = {5, 2, 2, 2};
466 
467  inputData =
468  {
469  17.0f, -1.0f, 17.0f, -1.0f, 17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f,
470  16.0f, -2.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f, 15.0f, -3.0f,
471  15.0f, -3.0f, 15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 14.0f, -4.0f,
472  14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f, 1.0f, -17.0f, 1.0f, -17.0f
473  };
474 
475  outputData =
476  {
477  0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f,
478  0.643914213228014f,
479  0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.236882800924671f,
480  0.236882800924671f,
481  0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.236882800924671f,
482  0.236882800924671f,
483  0.236882800924671f, 0.087144312427294f, 0.087144312427294f, 0.087144312427294f,
484  0.087144312427294f,
485 
486  0.087144312427294f, 0.087144312427294f, 0.087144312427294f, 0.087144312427294f,
487  0.032058600957022f,
488  0.032058600957022f, 0.032058600957022f, 0.032058600957022f, 0.032058600957022f,
489  0.032058600957022f,
490  0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f,
491  7.246299848982885e-08f,
492  7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f,
493  7.246299848982885e-08f, 7.246299848982885e-08f
494  };
495  break;
496  }
497  case -3:
498  case 1:
499  {
500  inputShape = {2, 5, 2, 2};
501 
502  inputData =
503  {
504  17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f,
505  15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f,
506  17.0f, -1.0f, 17.0f, -1.0f, 16.0f, -2.0f, 16.0f, -2.0f, 15.0f, -3.0f,
507  15.0f, -3.0f, 14.0f, -4.0f, 14.0f, -4.0f, 1.0f, -17.0f, 1.0f, -17.0f
508  };
509 
510  outputData =
511  {
512  0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f,
513  0.236882800924671f,
514  0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.087144312427294f,
515  0.087144312427294f,
516  0.087144312427294f, 0.087144312427294f, 0.032058600957022f, 0.032058600957022f,
517  0.032058600957022f,
518  0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f,
519  7.246299848982885e-08f,
520 
521 
522  0.643914213228014f, 0.643914213228014f, 0.643914213228014f, 0.643914213228014f,
523  0.236882800924671f,
524  0.236882800924671f, 0.236882800924671f, 0.236882800924671f, 0.087144312427294f,
525  0.087144312427294f,
526  0.087144312427294f, 0.087144312427294f, 0.032058600957022f, 0.032058600957022f,
527  0.032058600957022f,
528  0.032058600957022f, 7.246299848982885e-08f, 7.246299848982885e-08f, 7.246299848982885e-08f,
529  7.246299848982885e-08f
530  };
531  break;
532  }
533  case -2:
534  case 2:
535  {
536  inputShape = {2, 2, 5, 2};
537 
538  inputData =
539  {
540  17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f,
541  17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f,
542  17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f,
543  17.0f, -1.0f, 16.0f, -2.0f, 15.0f, -3.0f, 14.0f, -4.0f, 1.0f, -17.0f
544  };
545 
546  outputData =
547  {
548  0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f,
549  0.087144312427294f,
550  0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f,
551  7.246299848982885e-08f,
552  0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f,
553  0.087144312427294f,
554  0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f,
555  7.246299848982885e-08f,
556 
557  0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f,
558  0.087144312427294f,
559  0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f,
560  7.246299848982885e-08f,
561  0.643914213228014f, 0.643914213228014f, 0.236882800924671f, 0.236882800924671f,
562  0.087144312427294f,
563  0.087144312427294f, 0.032058600957022f, 0.032058600957022f, 7.246299848982885e-08f,
564  7.246299848982885e-08f
565  };
566  break;
567  }
568  case -1:
569  case 3:
570  {
571  inputShape = {2, 2, 2, 5};
572 
573  inputData =
574  {
575  17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f,
576  17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f,
577  17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f,
578  17.0f, 16.0f, 15.0f, 14.0f, 1.0f, -1.0f, -2.0f, -3.0f, -4.0f, -17.0f
579  };
580 
581  outputData =
582  {
583  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
584  7.246299848982885e-08f,
585  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
586  7.246299848982885e-08f,
587  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
588  7.246299848982885e-08f,
589  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
590  7.246299848982885e-08f,
591 
592  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
593  7.246299848982885e-08f,
594  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
595  7.246299848982885e-08f,
596  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
597  7.246299848982885e-08f,
598  0.643914213228014f, 0.236882800924671f, 0.087144312427294f, 0.032058600957022f,
599  7.246299848982885e-08f
600  };
601  break;
602  }
603  }
604 
605  return Simple4dSoftmaxTestImpl<armnn::DataType::Float32>(
606  workloadFactory,
607  memoryManager,
608  tensorHandleFactory,
609  beta,
610  inputShape,
611  outputData,
612  inputData,
613  axis);
614 }
615 
617  armnn::IWorkloadFactory& workloadFactory,
619  const armnn::ITensorHandleFactory& tensorHandleFactory,
620  float beta)
621 {
622  return SimpleSoftmaxTestImpl<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, tensorHandleFactory, beta);
623 }
624 
626  armnn::IWorkloadFactory& workloadFactory,
628  const armnn::ITensorHandleFactory& tensorHandleFactory,
629  float beta)
630 {
631  Simple3dSoftmaxOutputData data;
632  return Simple3dSoftmaxTestImpl<armnn::DataType::QAsymmU8>(
633  workloadFactory,
634  memoryManager,
635  tensorHandleFactory,
636  beta,
637  data.inputShape,
638  data.outputData,
639  data.inputData);
640 }
641 
643  armnn::IWorkloadFactory& workloadFactory,
645  const armnn::ITensorHandleFactory& tensorHandleFactory,
646  float beta)
647 {
648  Simple4dSoftmaxData data;
649 
650  return Simple4dSoftmaxTestImpl<armnn::DataType::QAsymmU8>(workloadFactory, memoryManager, tensorHandleFactory, beta,
651  data.inputShape, data.outputData, data.inputData);
652 }
653 
655  armnn::IWorkloadFactory& workloadFactory,
657  const armnn::ITensorHandleFactory& tensorHandleFactory,
658  float beta)
659 {
660  return SimpleSoftmaxTestImpl<armnn::DataType::Float16>(workloadFactory, memoryManager, tensorHandleFactory, beta);
661 }
662 
664  armnn::IWorkloadFactory& workloadFactory,
666  const armnn::ITensorHandleFactory& tensorHandleFactory,
667  float beta)
668 {
669  Simple3dSoftmaxOutputData data;
670  return Simple3dSoftmaxTestImpl<armnn::DataType::Float16>(workloadFactory, memoryManager, tensorHandleFactory, beta,
671  data.inputShape, data.outputData, data.inputData);
672 }
673 
675  armnn::IWorkloadFactory& workloadFactory,
677  const armnn::ITensorHandleFactory& tensorHandleFactory,
678  float beta)
679 {
680  Simple4dSoftmaxData data;
681  return Simple4dSoftmaxTestImpl<armnn::DataType::Float16>(workloadFactory, memoryManager, tensorHandleFactory, beta,
682  data.inputShape, data.outputData, data.inputData);
683 }
684 
686  armnn::IWorkloadFactory& workloadFactory,
688  const armnn::ITensorHandleFactory& tensorHandleFactory,
689  float beta)
690 {
691  return SimpleSoftmaxTestImpl<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, tensorHandleFactory, beta);
692 }
693 
695  armnn::IWorkloadFactory& workloadFactory,
697  const armnn::ITensorHandleFactory& tensorHandleFactory,
698  float beta)
699 {
700  Simple3dSoftmaxOutputData data;
701  return Simple3dSoftmaxTestImpl<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, tensorHandleFactory, beta,
702  data.inputShape, data.outputData, data.inputData);
703 }
704 
706  armnn::IWorkloadFactory& workloadFactory,
708  const armnn::ITensorHandleFactory& tensorHandleFactory,
709  float beta)
710 {
711  Simple4dSoftmaxData data;
712 
713  return Simple4dSoftmaxTestImpl<armnn::DataType::QSymmS16>(workloadFactory, memoryManager, tensorHandleFactory, beta,
714  data.inputShape, data.outputData, data.inputData);
715 }
716 
718  armnn::IWorkloadFactory& workloadFactory,
720  armnn::IWorkloadFactory& refWorkloadFactory,
721  const armnn::ITensorHandleFactory& tensorHandleFactory,
722  const armnn::ITensorHandleFactory& refTensorHandleFactory,
723  float beta)
724 {
725  return CompareSoftmaxTestImpl<armnn::DataType::Float32>(
726  workloadFactory, memoryManager, refWorkloadFactory, tensorHandleFactory, refTensorHandleFactory, beta);
727 }
728 
730  armnn::IWorkloadFactory& workloadFactory,
732  armnn::IWorkloadFactory& refWorkloadFactory,
733  const armnn::ITensorHandleFactory& tensorHandleFactory,
734  const armnn::ITensorHandleFactory& refTensorHandleFactory,
735  float beta)
736 {
737  return CompareSoftmaxTestImpl<armnn::DataType::QAsymmU8>(
738  workloadFactory, memoryManager, refWorkloadFactory, tensorHandleFactory, refTensorHandleFactory, beta);
739 }
LayerTestResult< float, 4 > Simple4dAxisSoftmaxTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta, int axis)
LayerTestResult< float, 4 > Simple4dSoftmaxTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
LayerTestResult< int16_t, 3 > Simple3dSoftmaxUint16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
int m_Axis
Scalar, defaulted to the last index (-1), specifying the dimension the activation will be performed o...
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
LayerTestResult< armnn::Half, 3 > Simple3dSoftmaxFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
LayerTestResult< int16_t, 4 > Simple4dSoftmaxUint16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
float m_Beta
Exponentiation value.
LayerTestResult< uint8_t, 2 > SimpleSoftmaxUint8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
LayerTestResult< uint8_t, 2 > CompareSoftmaxUint8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, const armnn::ITensorHandleFactory &tensorHandleFactory, const armnn::ITensorHandleFactory &refTensorHandleFactory, float beta)
LayerTestResult< uint8_t, 4 > Simple4dSoftmaxUint8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
LayerTestResult< float, 3 > Simple3dAxisSoftmaxTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta, int axis)
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:475
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
void CopyDataFromITensorHandle(void *memory, const armnn::ITensorHandle *tensorHandle)
LayerTestResult< float, 2 > CompareSoftmaxTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, armnn::IWorkloadFactory &refWorkloadFactory, const armnn::ITensorHandleFactory &tensorHandleFactory, const armnn::ITensorHandleFactory &refTensorHandleFactory, float beta)
LayerTestResult< uint8_t, 3 > Simple3dSoftmaxUint8Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
LayerTestResult< armnn::Half, 4 > Simple4dSoftmaxFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
LayerTestResult< armnn::Half, 2 > SimpleSoftmaxFloat16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
virtual std::unique_ptr< IWorkload > CreateSoftmax(const SoftmaxQueueDescriptor &descriptor, const WorkloadInfo &info) const
Contains information about TensorInfos of a layer.
void SetQuantizationOffset(int32_t offset)
Definition: Tensor.cpp:491
LayerTestResult< float, 3 > Simple3dSoftmaxTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
LayerTestResult< float, 2 > SimpleSoftmaxTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
unsigned int GetNumElements() const
Definition: Tensor.hpp:196
LayerTestResult< float, 2 > SimpleAxisSoftmaxTest(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta, int axis)
void CopyDataToITensorHandle(armnn::ITensorHandle *tensorHandle, const void *memory)
LayerTestResult< int16_t, 2 > SimpleSoftmaxUint16Test(armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, float beta)