blob: 24000d45e68fe22cb2913496dbf6c327d7673349 [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"
Nikhil Raj7dcc6972021-04-30 15:44:24 +01007#include <common/include/ProfilingGuid.hpp>
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +00008
Narumol Prangnawarat403a1852020-03-12 14:24:13 +00009#include <BFloat16.hpp>
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +000010#include <Half.hpp>
11
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000012#include <algorithm>
13#include <iostream>
14
15namespace armnn
16{
17
18template <typename T>
19void Debug(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000020 const T* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +000021 LayerGuid guid,
22 const std::string& layerName,
23 unsigned int slotIndex)
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000024{
25 const unsigned int numDims = inputInfo.GetNumDimensions();
26 const unsigned int numElements = inputInfo.GetNumElements();
27 const TensorShape& inputShape = inputInfo.GetShape();
28
Rob Hughes9e10c2b2019-07-23 15:37:19 +010029 std::vector<unsigned int> strides(numDims, 0);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000030 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 << "{ ";
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +000038 std::cout << "\"layerGuid\": " << guid << ", ";
39 std::cout << "\"layerName\": \"" << layerName << "\", ";
40 std::cout << "\"outputSlot\": " << slotIndex << ", ";
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000041 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\": "
Matthew Sloyan24ac8592020-09-23 16:57:23 +010055 << static_cast<float>(*std::min_element(inputData, inputData + numElements)) << ", ";
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000056
57 std::cout << "\"max\": "
Matthew Sloyan24ac8592020-09-23 16:57:23 +010058 << static_cast<float>(*std::max_element(inputData, inputData + numElements)) << ", ";
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000059
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
Matthew Sloyan24ac8592020-09-23 16:57:23 +010072 std::cout << static_cast<float>(inputData[i]);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000073
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;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000089}
90
Narumol Prangnawarat403a1852020-03-12 14:24:13 +000091template void Debug<BFloat16>(const TensorInfo& inputInfo,
92 const BFloat16* inputData,
93 LayerGuid guid,
94 const std::string& layerName,
95 unsigned int slotIndex);
96
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +000097template void Debug<Half>(const TensorInfo& inputInfo,
98 const Half* inputData,
99 LayerGuid guid,
100 const std::string& layerName,
101 unsigned int slotIndex);
102
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000103template void Debug<float>(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000104 const float* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000105 LayerGuid guid,
106 const std::string& layerName,
107 unsigned int slotIndex);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000108
109template void Debug<uint8_t>(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000110 const uint8_t* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000111 LayerGuid guid,
112 const std::string& layerName,
113 unsigned int slotIndex);
114
Keith Davis5204aa82020-01-27 15:24:59 +0000115template 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
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100121template void Debug<int16_t>(const TensorInfo& inputInfo,
122 const int16_t* inputData,
123 LayerGuid guid,
124 const std::string& layerName,
125 unsigned int slotIndex);
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000126
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000127template 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
Matteo Martincigh49124022019-01-11 13:25:59 +0000133} // namespace armnn