blob: c5a2e650209e098ecea0d373c8dbf4e85c61be42 [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
30extern const armnn::PermutationVector g_DontPermute;
31
Mike Kellyb5fdf382019-06-11 16:35:25 +010032template <typename OperandType>
telsoa015307bc12018-03-09 13:51:08 +000033class UnsupportedOperand: public std::runtime_error
34{
35public:
Mike Kellyb5fdf382019-06-11 16:35:25 +010036 UnsupportedOperand(const OperandType type)
telsoa015307bc12018-03-09 13:51:08 +000037 : std::runtime_error("Operand type is unsupported")
38 , m_type(type)
39 {}
40
Mike Kellyb5fdf382019-06-11 16:35:25 +010041 OperandType m_type;
telsoa015307bc12018-03-09 13:51:08 +000042};
43
44/// Swizzles tensor data in @a input according to the dimension mappings.
45void 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
49void* GetMemoryFromPool(DataLocation location,
50 const std::vector<android::nn::RunTimePoolInfo>& memPools);
51
52/// Can throw UnsupportedOperand
Matthew Bentham912b3622019-05-03 15:49:14 +010053armnn::TensorInfo GetTensorInfoForOperand(const V1_0::Operand& operand);
telsoa015307bc12018-03-09 13:51:08 +000054
Mike Kellyb5fdf382019-06-11 16:35:25 +010055#ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2
56armnn::TensorInfo GetTensorInfoForOperand(const V1_2::Operand& operand);
57#endif
58
Matthew Bentham912b3622019-05-03 15:49:14 +010059std::string GetOperandSummary(const V1_0::Operand& operand);
kevmay01bc5f7842018-08-30 12:34:39 +010060
Mike Kellyb5fdf382019-06-11 16:35:25 +010061#ifdef ARMNN_ANDROID_NN_V1_2 // Using ::android::hardware::neuralnetworks::V1_2
62std::string GetOperandSummary(const V1_2::Operand& operand);
63#endif
64
Matteo Martincighe48bdff2018-09-03 13:50:50 +010065template <typename HalModel>
66std::string GetModelSummary(const HalModel& model)
kevmay01bc5f7842018-08-30 12:34:39 +010067{
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}
telsoa015307bc12018-03-09 13:51:08 +000096
97void DumpTensor(const std::string& dumpDir,
telsoa01ce3e84a2018-08-31 09:31:35 +010098 const std::string& requestName,
99 const std::string& tensorName,
100 const armnn::ConstTensor& tensor);
101
102void DumpJsonProfilingIfRequired(bool gpuProfilingEnabled,
103 const std::string& dumpDir,
104 armnn::NetworkId networkId,
105 const armnn::IProfiler* profiler);
telsoa015307bc12018-03-09 13:51:08 +0000106
Jim Flynn829ad302019-12-13 14:43:24 +0000107std::string ExportNetworkGraphToDotFile(const armnn::IOptimizedNetwork& optimizedNetwork,
108 const std::string& dumpDir);
telsoa01ce3e84a2018-08-31 09:31:35 +0100109
Jim Flynn829ad302019-12-13 14:43:24 +0000110void RenameGraphDotFile(const std::string& oldName, const std::string& dumpDir, const armnn::NetworkId networkId);
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100111
Aron Virginas-Tar573a8fa2019-07-23 14:01:37 +0100112/// Checks if a tensor info represents a dynamic tensor
113bool IsDynamicTensor(const armnn::TensorInfo& outputInfo);
114
Jim Flynn829ad302019-12-13 14:43:24 +0000115std::string GetFileTimestamp();
116
Matthew Bentham912b3622019-05-03 15:49:14 +0100117} // namespace armnn_driver