blob: df05ad73dc040ac8a1d2cdb12519f9ba7646fb36 [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 <algorithm>
12#include <iostream>
13
14namespace armnn
15{
16
17template <typename T>
18void Debug(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000019 const T* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +000020 LayerGuid guid,
21 const std::string& layerName,
22 unsigned int slotIndex)
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000023{
24 const unsigned int numDims = inputInfo.GetNumDimensions();
25 const unsigned int numElements = inputInfo.GetNumElements();
26 const TensorShape& inputShape = inputInfo.GetShape();
27
Rob Hughes9e10c2b2019-07-23 15:37:19 +010028 std::vector<unsigned int> strides(numDims, 0);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000029 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 << "{ ";
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +000037 std::cout << "\"layerGuid\": " << guid << ", ";
38 std::cout << "\"layerName\": \"" << layerName << "\", ";
39 std::cout << "\"outputSlot\": " << slotIndex << ", ";
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000040 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\": "
Matthew Sloyan24ac8592020-09-23 16:57:23 +010054 << static_cast<float>(*std::min_element(inputData, inputData + numElements)) << ", ";
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000055
56 std::cout << "\"max\": "
Matthew Sloyan24ac8592020-09-23 16:57:23 +010057 << static_cast<float>(*std::max_element(inputData, inputData + numElements)) << ", ";
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000058
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
Matthew Sloyan24ac8592020-09-23 16:57:23 +010071 std::cout << static_cast<float>(inputData[i]);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000072
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;
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +000088}
89
Narumol Prangnawarat403a1852020-03-12 14:24:13 +000090template void Debug<BFloat16>(const TensorInfo& inputInfo,
91 const BFloat16* inputData,
92 LayerGuid guid,
93 const std::string& layerName,
94 unsigned int slotIndex);
95
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +000096template void Debug<Half>(const TensorInfo& inputInfo,
97 const Half* inputData,
98 LayerGuid guid,
99 const std::string& layerName,
100 unsigned int slotIndex);
101
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000102template void Debug<float>(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000103 const float* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000104 LayerGuid guid,
105 const std::string& layerName,
106 unsigned int slotIndex);
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000107
108template void Debug<uint8_t>(const TensorInfo& inputInfo,
Nattapat Chaimanowongcfdcadf2018-12-06 11:54:33 +0000109 const uint8_t* inputData,
Nattapat Chaimanowong964e9552019-03-26 11:03:26 +0000110 LayerGuid guid,
111 const std::string& layerName,
112 unsigned int slotIndex);
113
Keith Davis5204aa82020-01-27 15:24:59 +0000114template 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
Narumol Prangnawarat47cfee92019-07-04 10:29:00 +0100120template void Debug<int16_t>(const TensorInfo& inputInfo,
121 const int16_t* inputData,
122 LayerGuid guid,
123 const std::string& layerName,
124 unsigned int slotIndex);
Aron Virginas-Tardb1a2832019-11-12 16:15:11 +0000125
Narumol Prangnawaratd2d917d2020-01-09 10:16:39 +0000126template 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
Matteo Martincigh49124022019-01-11 13:25:59 +0000132} // namespace armnn