blob: 41e1c47c5c82f00de61d10ec63ed544aa997e5a4 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
telsoa014fcda012018-03-09 14:13:49 +00007
telsoa014fcda012018-03-09 14:13:49 +00008#include "INetwork.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01009#include "IProfiler.hpp"
Matthew Bentham313e1c82019-03-25 17:37:47 +000010#include "Tensor.hpp"
11#include "Types.hpp"
telsoa014fcda012018-03-09 14:13:49 +000012#include "TypesUtils.hpp"
13
Matthew Bentham313e1c82019-03-25 17:37:47 +000014#include <memory>
15
telsoa014fcda012018-03-09 14:13:49 +000016namespace armnn
17{
18
19using NetworkId = int;
20
telsoa01c577f2c2018-08-31 09:22:23 +010021class IGpuAccTunedParameters;
telsoa014fcda012018-03-09 14:13:49 +000022
23class IRuntime;
24using IRuntimePtr = std::unique_ptr<IRuntime, void(*)(IRuntime* runtime)>;
25
26class IRuntime
27{
28public:
29 struct CreationOptions
30 {
telsoa01c577f2c2018-08-31 09:22:23 +010031 CreationOptions()
32 : m_GpuAccTunedParameters(nullptr)
33 , m_EnableGpuProfiling(false)
Matteo Martincighe7d44982019-08-05 12:16:47 +010034 , m_DynamicBackendsPath("")
telsoa01c577f2c2018-08-31 09:22:23 +010035 {}
telsoa014fcda012018-03-09 14:13:49 +000036
telsoa01c577f2c2018-08-31 09:22:23 +010037 /// If set, uses the GpuAcc tuned parameters from the given object when executing GPU workloads.
38 /// It will also be updated with new tuned parameters if it is configured to do so.
39 std::shared_ptr<IGpuAccTunedParameters> m_GpuAccTunedParameters;
40
41 // Setting this flag will allow the user to obtain GPU profiling information from the runtime.
42 bool m_EnableGpuProfiling;
Matteo Martincighe7d44982019-08-05 12:16:47 +010043
44 // Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive
45 // Only a single path is allowed for the override
46 std::string m_DynamicBackendsPath;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +010047
48 struct ExternalProfilingOptions
49 {
50 ExternalProfilingOptions()
51 : m_EnableProfiling(false)
52 , m_OutgoingCaptureFile("")
53 , m_IncomingCaptureFile("")
54 , m_FileOnly(false)
55 , m_CapturePeriod(150u)
56 {}
57
58 bool m_EnableProfiling;
59 std::string m_OutgoingCaptureFile;
60 std::string m_IncomingCaptureFile;
61 bool m_FileOnly;
62 uint32_t m_CapturePeriod;
63 };
telsoa014fcda012018-03-09 14:13:49 +000064 };
65
66 static IRuntime* CreateRaw(const CreationOptions& options);
67 static IRuntimePtr Create(const CreationOptions& options);
68 static void Destroy(IRuntime* runtime);
69
telsoa01c577f2c2018-08-31 09:22:23 +010070 /// Loads a complete network into the IRuntime.
71 /// @param [out] networkIdOut - Unique identifier for the network is returned in this reference.
72 /// @param [in] network - Complete network to load into the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +000073 /// The runtime takes ownership of the network once passed in.
74 /// @return armnn::Status
75 virtual Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network) = 0;
76
telsoa01c577f2c2018-08-31 09:22:23 +010077 /// Load a complete network into the IRuntime.
78 /// @param [out] networkIdOut Unique identifier for the network is returned in this reference.
79 /// @param [in] network Complete network to load into the IRuntime.
80 /// @param [out] errorMessage Error message if there were any errors.
81 /// The runtime takes ownership of the network once passed in.
82 /// @return armnn::Status
83 virtual Status LoadNetwork(NetworkId& networkIdOut,
84 IOptimizedNetworkPtr network,
85 std::string & errorMessage) = 0;
86
telsoa014fcda012018-03-09 14:13:49 +000087 virtual TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
88 virtual TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
89
telsoa01c577f2c2018-08-31 09:22:23 +010090 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors
telsoa014fcda012018-03-09 14:13:49 +000091 virtual Status EnqueueWorkload(NetworkId networkId,
telsoa01c577f2c2018-08-31 09:22:23 +010092 const InputTensors& inputTensors,
93 const OutputTensors& outputTensors) = 0;
telsoa014fcda012018-03-09 14:13:49 +000094
telsoa01c577f2c2018-08-31 09:22:23 +010095 /// Unloads a network from the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +000096 /// At the moment this only removes the network from the m_Impl->m_Network.
97 /// This might need more work in the future to be AndroidNN compliant.
telsoa01c577f2c2018-08-31 09:22:23 +010098 /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork().
telsoa014fcda012018-03-09 14:13:49 +000099 /// @return armnn::Status
100 virtual Status UnloadNetwork(NetworkId networkId) = 0;
101
telsoa01c577f2c2018-08-31 09:22:23 +0100102 virtual const IDeviceSpec& GetDeviceSpec() const = 0;
103
104 /// Gets the profiler corresponding to the given network id.
105 /// @param networkId The id of the network for which to get the profile.
106 /// @return A pointer to the requested profiler, or nullptr if not found.
107 virtual const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const = 0;
telsoa014fcda012018-03-09 14:13:49 +0000108
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000109 /// Registers a callback function to debug layers performing custom computations on intermediate tensors.
110 /// @param networkId The id of the network to register the callback.
111 /// @param func callback function to pass to the debug layer.
112 virtual void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func) = 0;
113
telsoa014fcda012018-03-09 14:13:49 +0000114protected:
115 ~IRuntime() {}
116};
117
telsoa01c577f2c2018-08-31 09:22:23 +0100118using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
telsoa014fcda012018-03-09 14:13:49 +0000119
telsoa01c577f2c2018-08-31 09:22:23 +0100120/// Manages a set of GpuAcc parameters which have been tuned for maximum performance.
121/// Passes an instance of this object to the IRuntime::Create() method (via IRuntime::CreationOptions) to use it
122/// for all GPU workload execution.
telsoa014fcda012018-03-09 14:13:49 +0000123///
124/// Can be created in two modes:
telsoa01c577f2c2018-08-31 09:22:23 +0100125/// - In UseTunedParameters mode, the parameters stored in this object are used to execute GPU workloads.
126/// - In UpdateTunedParameters mode, additionally, whenever a GPU workload is executed for the first time, the
telsoa014fcda012018-03-09 14:13:49 +0000127/// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
128///
telsoa01c577f2c2018-08-31 09:22:23 +0100129/// The parameters can be loaded from and saved to a file so that you can first run a slow initial read-write
telsoa014fcda012018-03-09 14:13:49 +0000130/// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
telsoa01c577f2c2018-08-31 09:22:23 +0100131class IGpuAccTunedParameters
telsoa014fcda012018-03-09 14:13:49 +0000132{
133public:
134 enum class Mode
135 {
136 UseTunedParameters,
137 UpdateTunedParameters
138 };
139
Ruomei Yan49937f32019-04-25 14:24:05 +0100140 enum class TuningLevel
141 {
142 Rapid = 0,
143 Normal = 1,
144 Exhaustive = 2
145 };
146
telsoa014fcda012018-03-09 14:13:49 +0000147 /// Creates an IClTunedParameters with the given mode.
148 /// @{
Ruomei Yan49937f32019-04-25 14:24:05 +0100149 static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode);
150 static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode);
telsoa014fcda012018-03-09 14:13:49 +0000151 /// @}
telsoa01c577f2c2018-08-31 09:22:23 +0100152 static void Destroy(IGpuAccTunedParameters* params);
telsoa014fcda012018-03-09 14:13:49 +0000153
154 /// Loads an existing set of tuned parameters from the given file.
155 /// If there is an error loading the file, an armnn::Exception is thrown.
156 virtual void Load(const char* filename) = 0;
157
158 /// Saves the current set of tuned parameters to the given file.
159 /// If there is an error saving to the file, an armnn::Exception is thrown.
160 virtual void Save(const char* filename) const = 0;
161
162protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100163 virtual ~IGpuAccTunedParameters() {};
telsoa014fcda012018-03-09 14:13:49 +0000164};
165
166}