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