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