ArmNN
 21.05
Debug.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "Debug.hpp"
7 
8 #include <BFloat16.hpp>
9 #include <Half.hpp>
10 
11 #include <algorithm>
12 #include <iostream>
13 
14 namespace armnn
15 {
16 
17 template <typename T>
18 void Debug(const TensorInfo& inputInfo,
19  const T* inputData,
20  LayerGuid guid,
21  const std::string& layerName,
22  unsigned int slotIndex)
23 {
24  const unsigned int numDims = inputInfo.GetNumDimensions();
25  const unsigned int numElements = inputInfo.GetNumElements();
26  const TensorShape& inputShape = inputInfo.GetShape();
27 
28  std::vector<unsigned int> strides(numDims, 0);
29  strides[numDims - 1] = inputShape[numDims - 1];
30 
31  for (unsigned int i = 2; i <= numDims; i++)
32  {
33  strides[numDims - i] = strides[numDims - i + 1] * inputShape[numDims - i];
34  }
35 
36  std::cout << "{ ";
37  std::cout << "\"layerGuid\": " << guid << ", ";
38  std::cout << "\"layerName\": \"" << layerName << "\", ";
39  std::cout << "\"outputSlot\": " << slotIndex << ", ";
40  std::cout << "\"shape\": ";
41 
42  std::cout << "[";
43  for (unsigned int i = 0; i < numDims; i++)
44  {
45  std::cout << inputShape[i];
46  if (i != numDims - 1)
47  {
48  std::cout << ", ";
49  }
50  }
51  std::cout << "], ";
52 
53  std::cout << "\"min\": "
54  << static_cast<float>(*std::min_element(inputData, inputData + numElements)) << ", ";
55 
56  std::cout << "\"max\": "
57  << static_cast<float>(*std::max_element(inputData, inputData + numElements)) << ", ";
58 
59  std::cout << "\"data\": ";
60 
61  for (unsigned int i = 0; i < numElements; i++)
62  {
63  for (unsigned int j = 0; j < numDims; j++)
64  {
65  if (i % strides[j] == 0)
66  {
67  std::cout << "[" ;
68  }
69  }
70 
71  std::cout << static_cast<float>(inputData[i]);
72 
73  for (unsigned int j = 0; j < numDims; j++)
74  {
75  if ((i+1) % strides[j] == 0)
76  {
77  std::cout << "]" ;
78  }
79  }
80 
81  if (i != numElements - 1)
82  {
83  std::cout << ", ";
84  }
85  }
86 
87  std::cout << " }" << std::endl;
88 }
89 
90 template void Debug<BFloat16>(const TensorInfo& inputInfo,
91  const BFloat16* inputData,
92  LayerGuid guid,
93  const std::string& layerName,
94  unsigned int slotIndex);
95 
96 template void Debug<Half>(const TensorInfo& inputInfo,
97  const Half* inputData,
98  LayerGuid guid,
99  const std::string& layerName,
100  unsigned int slotIndex);
101 
102 template void Debug<float>(const TensorInfo& inputInfo,
103  const float* inputData,
104  LayerGuid guid,
105  const std::string& layerName,
106  unsigned int slotIndex);
107 
108 template void Debug<uint8_t>(const TensorInfo& inputInfo,
109  const uint8_t* inputData,
110  LayerGuid guid,
111  const std::string& layerName,
112  unsigned int slotIndex);
113 
114 template void Debug<int8_t>(const TensorInfo& inputInfo,
115  const int8_t* inputData,
116  LayerGuid guid,
117  const std::string& layerName,
118  unsigned int slotIndex);
119 
120 template void Debug<int16_t>(const TensorInfo& inputInfo,
121  const int16_t* inputData,
122  LayerGuid guid,
123  const std::string& layerName,
124  unsigned int slotIndex);
125 
126 template void Debug<int32_t>(const TensorInfo& inputInfo,
127  const int32_t* inputData,
128  LayerGuid guid,
129  const std::string& layerName,
130  unsigned int slotIndex);
131 
132 } // namespace armnn
const TensorShape & GetShape() const
Definition: Tensor.hpp:187
template void Debug< int8_t >(const TensorInfo &inputInfo, const int8_t *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
Copyright (c) 2021 ARM Limited and Contributors.
template void Debug< BFloat16 >(const TensorInfo &inputInfo, const BFloat16 *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
template void Debug< float >(const TensorInfo &inputInfo, const float *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
template void Debug< int16_t >(const TensorInfo &inputInfo, const int16_t *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
template void Debug< uint8_t >(const TensorInfo &inputInfo, const uint8_t *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
void Debug(const TensorInfo &inputInfo, const T *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
Definition: Debug.cpp:18
template void Debug< Half >(const TensorInfo &inputInfo, const Half *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
template void Debug< int32_t >(const TensorInfo &inputInfo, const int32_t *inputData, LayerGuid guid, const std::string &layerName, unsigned int slotIndex)
half_float::half Half
Definition: Half.hpp:16
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:191
unsigned int GetNumElements() const
Definition: Tensor.hpp:192