telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #pragma once |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 7 | #include <armnn/ArmNN.hpp> |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 8 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 9 | #include <CpuExecutor.h> |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 10 | #include <HalInterfaces.h> |
| 11 | #include <NeuralNetworks.h> |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 12 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 13 | #include <boost/format.hpp> |
| 14 | #include <log/log.h> |
| 15 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 16 | #include <vector> |
| 17 | #include <string> |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 18 | #include <fstream> |
| 19 | #include <iomanip> |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 20 | |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 21 | namespace V1_0 = ::android::hardware::neuralnetworks::V1_0; |
| 22 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 23 | #ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2 |
| 24 | namespace V1_2 = ::android::hardware::neuralnetworks::V1_2; |
| 25 | #endif |
| 26 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 27 | namespace armnn_driver |
| 28 | { |
| 29 | |
| 30 | extern const armnn::PermutationVector g_DontPermute; |
| 31 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 32 | template <typename OperandType> |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 33 | class UnsupportedOperand: public std::runtime_error |
| 34 | { |
| 35 | public: |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 36 | UnsupportedOperand(const OperandType type) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 37 | : std::runtime_error("Operand type is unsupported") |
| 38 | , m_type(type) |
| 39 | {} |
| 40 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 41 | OperandType m_type; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /// Swizzles tensor data in @a input according to the dimension mappings. |
| 45 | void SwizzleAndroidNn4dTensorToArmNn(const armnn::TensorInfo& tensor, const void* input, void* output, |
| 46 | const armnn::PermutationVector& mappings); |
| 47 | |
| 48 | /// Returns a pointer to a specific location in a pool |
| 49 | void* GetMemoryFromPool(DataLocation location, |
| 50 | const std::vector<android::nn::RunTimePoolInfo>& memPools); |
| 51 | |
| 52 | /// Can throw UnsupportedOperand |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 53 | armnn::TensorInfo GetTensorInfoForOperand(const V1_0::Operand& operand); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 54 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 55 | #ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2 |
| 56 | armnn::TensorInfo GetTensorInfoForOperand(const V1_2::Operand& operand); |
| 57 | #endif |
| 58 | |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 59 | std::string GetOperandSummary(const V1_0::Operand& operand); |
kevmay01 | bc5f784 | 2018-08-30 12:34:39 +0100 | [diff] [blame] | 60 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 61 | #ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2 |
| 62 | std::string GetOperandSummary(const V1_2::Operand& operand); |
| 63 | #endif |
| 64 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 65 | template <typename HalModel> |
| 66 | std::string GetModelSummary(const HalModel& model) |
kevmay01 | bc5f784 | 2018-08-30 12:34:39 +0100 | [diff] [blame] | 67 | { |
| 68 | std::stringstream result; |
| 69 | |
| 70 | result << model.inputIndexes.size() << " input(s), " << model.operations.size() << " operation(s), " << |
| 71 | model.outputIndexes.size() << " output(s), " << model.operands.size() << " operand(s)" << std::endl; |
| 72 | |
| 73 | result << "Inputs: "; |
| 74 | for (uint32_t i = 0; i < model.inputIndexes.size(); i++) |
| 75 | { |
| 76 | result << GetOperandSummary(model.operands[model.inputIndexes[i]]) << ", "; |
| 77 | } |
| 78 | result << std::endl; |
| 79 | |
| 80 | result << "Operations: "; |
| 81 | for (uint32_t i = 0; i < model.operations.size(); i++) |
| 82 | { |
| 83 | result << toString(model.operations[i].type).c_str() << ", "; |
| 84 | } |
| 85 | result << std::endl; |
| 86 | |
| 87 | result << "Outputs: "; |
| 88 | for (uint32_t i = 0; i < model.outputIndexes.size(); i++) |
| 89 | { |
| 90 | result << GetOperandSummary(model.operands[model.outputIndexes[i]]) << ", "; |
| 91 | } |
| 92 | result << std::endl; |
| 93 | |
| 94 | return result.str(); |
| 95 | } |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 96 | |
| 97 | void DumpTensor(const std::string& dumpDir, |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 98 | const std::string& requestName, |
| 99 | const std::string& tensorName, |
| 100 | const armnn::ConstTensor& tensor); |
| 101 | |
| 102 | void DumpJsonProfilingIfRequired(bool gpuProfilingEnabled, |
| 103 | const std::string& dumpDir, |
| 104 | armnn::NetworkId networkId, |
| 105 | const armnn::IProfiler* profiler); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 106 | |
Jim Flynn | 14557e7 | 2019-12-16 11:50:29 +0000 | [diff] [blame] | 107 | std::string ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork, |
| 108 | const std::string& dumpDir); |
| 109 | |
| 110 | void RenameGraphDotFile(const std::string& oldName, const std::string& dumpDir, const armnn::NetworkId networkId); |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 111 | |
Aron Virginas-Tar | 573a8fa | 2019-07-23 14:01:37 +0100 | [diff] [blame] | 112 | /// Checks if a tensor info represents a dynamic tensor |
| 113 | bool IsDynamicTensor(const armnn::TensorInfo& outputInfo); |
| 114 | |
Jim Flynn | 14557e7 | 2019-12-16 11:50:29 +0000 | [diff] [blame] | 115 | std::string GetFileTimestamp(); |
| 116 | |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 117 | } // namespace armnn_driver |