Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Aron Virginas-Tar | db1a283 | 2019-11-12 16:15:11 +0000 | [diff] [blame] | 5 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 6 | #include "Debug.hpp" |
| 7 | |
Aron Virginas-Tar | db1a283 | 2019-11-12 16:15:11 +0000 | [diff] [blame] | 8 | #include <Half.hpp> |
| 9 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 10 | #include <boost/numeric/conversion/cast.hpp> |
| 11 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | #include <iostream> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | template <typename T> |
| 19 | void Debug(const TensorInfo& inputInfo, |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 20 | const T* inputData, |
Nattapat Chaimanowong | 964e955 | 2019-03-26 11:03:26 +0000 | [diff] [blame] | 21 | LayerGuid guid, |
| 22 | const std::string& layerName, |
| 23 | unsigned int slotIndex) |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 24 | { |
| 25 | const unsigned int numDims = inputInfo.GetNumDimensions(); |
| 26 | const unsigned int numElements = inputInfo.GetNumElements(); |
| 27 | const TensorShape& inputShape = inputInfo.GetShape(); |
| 28 | |
Rob Hughes | 9e10c2b | 2019-07-23 15:37:19 +0100 | [diff] [blame] | 29 | std::vector<unsigned int> strides(numDims, 0); |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 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 << "{ "; |
Nattapat Chaimanowong | 964e955 | 2019-03-26 11:03:26 +0000 | [diff] [blame] | 38 | std::cout << "\"layerGuid\": " << guid << ", "; |
| 39 | std::cout << "\"layerName\": \"" << layerName << "\", "; |
| 40 | std::cout << "\"outputSlot\": " << slotIndex << ", "; |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 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 | << boost::numeric_cast<float>(*std::min_element(inputData, inputData + numElements)) << ", "; |
| 56 | |
| 57 | std::cout << "\"max\": " |
| 58 | << boost::numeric_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 << boost::numeric_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; |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Aron Virginas-Tar | db1a283 | 2019-11-12 16:15:11 +0000 | [diff] [blame] | 91 | template void Debug<Half>(const TensorInfo& inputInfo, |
| 92 | const Half* inputData, |
| 93 | LayerGuid guid, |
| 94 | const std::string& layerName, |
| 95 | unsigned int slotIndex); |
| 96 | |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 97 | template void Debug<float>(const TensorInfo& inputInfo, |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 98 | const float* inputData, |
Nattapat Chaimanowong | 964e955 | 2019-03-26 11:03:26 +0000 | [diff] [blame] | 99 | LayerGuid guid, |
| 100 | const std::string& layerName, |
| 101 | unsigned int slotIndex); |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 102 | |
| 103 | template void Debug<uint8_t>(const TensorInfo& inputInfo, |
Nattapat Chaimanowong | cfdcadf | 2018-12-06 11:54:33 +0000 | [diff] [blame] | 104 | const uint8_t* inputData, |
Nattapat Chaimanowong | 964e955 | 2019-03-26 11:03:26 +0000 | [diff] [blame] | 105 | LayerGuid guid, |
| 106 | const std::string& layerName, |
| 107 | unsigned int slotIndex); |
| 108 | |
Narumol Prangnawarat | 47cfee9 | 2019-07-04 10:29:00 +0100 | [diff] [blame] | 109 | template void Debug<int16_t>(const TensorInfo& inputInfo, |
| 110 | const int16_t* inputData, |
| 111 | LayerGuid guid, |
| 112 | const std::string& layerName, |
| 113 | unsigned int slotIndex); |
Aron Virginas-Tar | db1a283 | 2019-11-12 16:15:11 +0000 | [diff] [blame] | 114 | |
Narumol Prangnawarat | d2d917d | 2020-01-09 10:16:39 +0000 | [diff] [blame] | 115 | template void Debug<int32_t>(const TensorInfo& inputInfo, |
| 116 | const int32_t* inputData, |
| 117 | LayerGuid guid, |
| 118 | const std::string& layerName, |
| 119 | unsigned int slotIndex); |
| 120 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 121 | } // namespace armnn |