blob: 6256655f3f363bf3d9e8a376389c7461e120d339 [file] [log] [blame]
telsoa015307bc12018-03-09 13:51:08 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beck93e48982018-09-05 13:05:09 +01003// SPDX-License-Identifier: MIT
telsoa015307bc12018-03-09 13:51:08 +00004//
5
6#pragma once
telsoa015307bc12018-03-09 13:51:08 +00007#include <armnn/ArmNN.hpp>
arovir01b0717b52018-09-05 17:03:25 +01008
telsoa015307bc12018-03-09 13:51:08 +00009#include <CpuExecutor.h>
arovir01b0717b52018-09-05 17:03:25 +010010#include <HalInterfaces.h>
11#include <NeuralNetworks.h>
telsoa015307bc12018-03-09 13:51:08 +000012
Matteo Martincighe48bdff2018-09-03 13:50:50 +010013#include <boost/format.hpp>
14#include <log/log.h>
15
telsoa015307bc12018-03-09 13:51:08 +000016#include <vector>
17#include <string>
Matteo Martincighe48bdff2018-09-03 13:50:50 +010018#include <fstream>
19#include <iomanip>
telsoa015307bc12018-03-09 13:51:08 +000020
Matthew Bentham912b3622019-05-03 15:49:14 +010021namespace V1_0 = ::android::hardware::neuralnetworks::V1_0;
22
Mike Kellyb5fdf382019-06-11 16:35:25 +010023#ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2
24namespace V1_2 = ::android::hardware::neuralnetworks::V1_2;
25#endif
26
telsoa015307bc12018-03-09 13:51:08 +000027namespace armnn_driver
28{
29
Kevin Mayec1e5b82020-02-26 17:00:39 +000030#ifdef ARMNN_ANDROID_R
31using DataLocation = ::android::nn::hal::DataLocation;
32#endif
33
telsoa015307bc12018-03-09 13:51:08 +000034extern const armnn::PermutationVector g_DontPermute;
35
Mike Kellyb5fdf382019-06-11 16:35:25 +010036template <typename OperandType>
telsoa015307bc12018-03-09 13:51:08 +000037class UnsupportedOperand: public std::runtime_error
38{
39public:
Mike Kellyb5fdf382019-06-11 16:35:25 +010040 UnsupportedOperand(const OperandType type)
telsoa015307bc12018-03-09 13:51:08 +000041 : std::runtime_error("Operand type is unsupported")
42 , m_type(type)
43 {}
44
Mike Kellyb5fdf382019-06-11 16:35:25 +010045 OperandType m_type;
telsoa015307bc12018-03-09 13:51:08 +000046};
47
48/// Swizzles tensor data in @a input according to the dimension mappings.
49void SwizzleAndroidNn4dTensorToArmNn(const armnn::TensorInfo& tensor, const void* input, void* output,
50 const armnn::PermutationVector& mappings);
51
52/// Returns a pointer to a specific location in a pool
53void* GetMemoryFromPool(DataLocation location,
54 const std::vector<android::nn::RunTimePoolInfo>& memPools);
55
56/// Can throw UnsupportedOperand
Matthew Bentham912b3622019-05-03 15:49:14 +010057armnn::TensorInfo GetTensorInfoForOperand(const V1_0::Operand& operand);
telsoa015307bc12018-03-09 13:51:08 +000058
Mike Kellyb5fdf382019-06-11 16:35:25 +010059#ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2
60armnn::TensorInfo GetTensorInfoForOperand(const V1_2::Operand& operand);
61#endif
62
Matthew Bentham912b3622019-05-03 15:49:14 +010063std::string GetOperandSummary(const V1_0::Operand& operand);
kevmay01bc5f7842018-08-30 12:34:39 +010064
Mike Kellyb5fdf382019-06-11 16:35:25 +010065#ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2
66std::string GetOperandSummary(const V1_2::Operand& operand);
67#endif
68
Matteo Martincighe48bdff2018-09-03 13:50:50 +010069template <typename HalModel>
70std::string GetModelSummary(const HalModel& model)
kevmay01bc5f7842018-08-30 12:34:39 +010071{
72 std::stringstream result;
73
74 result << model.inputIndexes.size() << " input(s), " << model.operations.size() << " operation(s), " <<
75 model.outputIndexes.size() << " output(s), " << model.operands.size() << " operand(s)" << std::endl;
76
77 result << "Inputs: ";
78 for (uint32_t i = 0; i < model.inputIndexes.size(); i++)
79 {
80 result << GetOperandSummary(model.operands[model.inputIndexes[i]]) << ", ";
81 }
82 result << std::endl;
83
84 result << "Operations: ";
85 for (uint32_t i = 0; i < model.operations.size(); i++)
86 {
87 result << toString(model.operations[i].type).c_str() << ", ";
88 }
89 result << std::endl;
90
91 result << "Outputs: ";
92 for (uint32_t i = 0; i < model.outputIndexes.size(); i++)
93 {
94 result << GetOperandSummary(model.operands[model.outputIndexes[i]]) << ", ";
95 }
96 result << std::endl;
97
98 return result.str();
99}
telsoa015307bc12018-03-09 13:51:08 +0000100
101void DumpTensor(const std::string& dumpDir,
telsoa01ce3e84a2018-08-31 09:31:35 +0100102 const std::string& requestName,
103 const std::string& tensorName,
104 const armnn::ConstTensor& tensor);
105
106void DumpJsonProfilingIfRequired(bool gpuProfilingEnabled,
107 const std::string& dumpDir,
108 armnn::NetworkId networkId,
109 const armnn::IProfiler* profiler);
telsoa015307bc12018-03-09 13:51:08 +0000110
Jim Flynn829ad302019-12-13 14:43:24 +0000111std::string ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork,
112 const std::string& dumpDir);
telsoa01ce3e84a2018-08-31 09:31:35 +0100113
Jim Flynn829ad302019-12-13 14:43:24 +0000114void RenameGraphDotFile(const std::string& oldName, const std::string& dumpDir, const armnn::NetworkId networkId);
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100115
Aron Virginas-Tar573a8fa2019-07-23 14:01:37 +0100116/// Checks if a tensor info represents a dynamic tensor
117bool IsDynamicTensor(const armnn::TensorInfo& outputInfo);
118
Jim Flynn829ad302019-12-13 14:43:24 +0000119std::string GetFileTimestamp();
120
Matthew Bentham912b3622019-05-03 15:49:14 +0100121} // namespace armnn_driver