blob: aadbc7613b7b3e4dc4616ccfeabccb7d5c9ede5a [file] [log] [blame]
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +00005
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +00006#include "Debug.hpp"
7
Narumol Prangnawarat403a1852020-03-12 14:24:13 +00008#include <BFloat16.hpp>
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +00009#include <Half.hpp>
10
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000011#include <boost/numeric/conversion/cast.hpp>
12
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000013#include <algorithm>
14#include <iostream>
15
16namespace armnn
17{
18
19template <typename T>
20void Debug(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000021 const T* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +000022 LayerGuid guid,
23 const std::string& layerName,
24 unsigned int slotIndex)
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000025{
26 const unsigned int numDims = inputInfo.GetNumDimensions();
27 const unsigned int numElements = inputInfo.GetNumElements();
28 const TensorShape& inputShape = inputInfo.GetShape();
29
Rob Hughes9e10c2b2019-07-23 15:37:19 +010030 std::vector<unsigned int> strides(numDims, 0);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000031 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 << "{ ";
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +000039 std::cout << "\"layerGuid\": " << guid << ", ";
40 std::cout << "\"layerName\": \"" << layerName << "\", ";
41 std::cout << "\"outputSlot\": " << slotIndex << ", ";
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000042 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;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000090}
91
Narumol Prangnawarat403a1852020-03-12 14:24:13 +000092template void Debug<BFloat16>(const TensorInfo& inputInfo,
93 const BFloat16* inputData,
94 LayerGuid guid,
95 const std::string& layerName,
96 unsigned int slotIndex);
97
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +000098template void Debug<Half>(const TensorInfo& inputInfo,
99 const Half* inputData,
100 LayerGuid guid,
101 const std::string& layerName,
102 unsigned int slotIndex);
103
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000104template void Debug<float>(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000105 const float* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000106 LayerGuid guid,
107 const std::string& layerName,
108 unsigned int slotIndex);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000109
110template void Debug<uint8_t>(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000111 const uint8_t* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000112 LayerGuid guid,
113 const std::string& layerName,
114 unsigned int slotIndex);
115
Keith Davis5204aa82020-01-27 15:24:59 +0000116template 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
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100122template void Debug<int16_t>(const TensorInfo& inputInfo,
123 const int16_t* inputData,
124 LayerGuid guid,
125 const std::string& layerName,
126 unsigned int slotIndex);
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000127
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000128template 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
Matteo Martincigh49124022019-01-11 13:25:59 +0000134} // namespace armnn