blob: 3f3c998f3a81e4d84e98fd4d834c07cd5bbeaff1 [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;
telsoa014fcda012018-03-09 14:13:49 +000047 };
48
49 static IRuntime* CreateRaw(const CreationOptions& options);
50 static IRuntimePtr Create(const CreationOptions& options);
51 static void Destroy(IRuntime* runtime);
52
telsoa01c577f2c2018-08-31 09:22:23 +010053 /// Loads a complete network into the IRuntime.
54 /// @param [out] networkIdOut - Unique identifier for the network is returned in this reference.
55 /// @param [in] network - Complete network to load into the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +000056 /// The runtime takes ownership of the network once passed in.
57 /// @return armnn::Status
58 virtual Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network) = 0;
59
telsoa01c577f2c2018-08-31 09:22:23 +010060 /// Load a complete network into the IRuntime.
61 /// @param [out] networkIdOut Unique identifier for the network is returned in this reference.
62 /// @param [in] network Complete network to load into the IRuntime.
63 /// @param [out] errorMessage Error message if there were any errors.
64 /// The runtime takes ownership of the network once passed in.
65 /// @return armnn::Status
66 virtual Status LoadNetwork(NetworkId& networkIdOut,
67 IOptimizedNetworkPtr network,
68 std::string & errorMessage) = 0;
69
telsoa014fcda012018-03-09 14:13:49 +000070 virtual TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
71 virtual TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
72
telsoa01c577f2c2018-08-31 09:22:23 +010073 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors
telsoa014fcda012018-03-09 14:13:49 +000074 virtual Status EnqueueWorkload(NetworkId networkId,
telsoa01c577f2c2018-08-31 09:22:23 +010075 const InputTensors& inputTensors,
76 const OutputTensors& outputTensors) = 0;
telsoa014fcda012018-03-09 14:13:49 +000077
telsoa01c577f2c2018-08-31 09:22:23 +010078 /// Unloads a network from the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +000079 /// At the moment this only removes the network from the m_Impl->m_Network.
80 /// This might need more work in the future to be AndroidNN compliant.
telsoa01c577f2c2018-08-31 09:22:23 +010081 /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork().
telsoa014fcda012018-03-09 14:13:49 +000082 /// @return armnn::Status
83 virtual Status UnloadNetwork(NetworkId networkId) = 0;
84
telsoa01c577f2c2018-08-31 09:22:23 +010085 virtual const IDeviceSpec& GetDeviceSpec() const = 0;
86
87 /// Gets the profiler corresponding to the given network id.
88 /// @param networkId The id of the network for which to get the profile.
89 /// @return A pointer to the requested profiler, or nullptr if not found.
90 virtual const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const = 0;
telsoa014fcda012018-03-09 14:13:49 +000091
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +000092 /// Registers a callback function to debug layers performing custom computations on intermediate tensors.
93 /// @param networkId The id of the network to register the callback.
94 /// @param func callback function to pass to the debug layer.
95 virtual void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func) = 0;
96
telsoa014fcda012018-03-09 14:13:49 +000097protected:
98 ~IRuntime() {}
99};
100
telsoa01c577f2c2018-08-31 09:22:23 +0100101using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
telsoa014fcda012018-03-09 14:13:49 +0000102
telsoa01c577f2c2018-08-31 09:22:23 +0100103/// Manages a set of GpuAcc parameters which have been tuned for maximum performance.
104/// Passes an instance of this object to the IRuntime::Create() method (via IRuntime::CreationOptions) to use it
105/// for all GPU workload execution.
telsoa014fcda012018-03-09 14:13:49 +0000106///
107/// Can be created in two modes:
telsoa01c577f2c2018-08-31 09:22:23 +0100108/// - In UseTunedParameters mode, the parameters stored in this object are used to execute GPU workloads.
109/// - In UpdateTunedParameters mode, additionally, whenever a GPU workload is executed for the first time, the
telsoa014fcda012018-03-09 14:13:49 +0000110/// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
111///
telsoa01c577f2c2018-08-31 09:22:23 +0100112/// 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 +0000113/// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
telsoa01c577f2c2018-08-31 09:22:23 +0100114class IGpuAccTunedParameters
telsoa014fcda012018-03-09 14:13:49 +0000115{
116public:
117 enum class Mode
118 {
119 UseTunedParameters,
120 UpdateTunedParameters
121 };
122
Ruomei Yan49937f32019-04-25 14:24:05 +0100123 enum class TuningLevel
124 {
125 Rapid = 0,
126 Normal = 1,
127 Exhaustive = 2
128 };
129
telsoa014fcda012018-03-09 14:13:49 +0000130 /// Creates an IClTunedParameters with the given mode.
131 /// @{
Ruomei Yan49937f32019-04-25 14:24:05 +0100132 static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode);
133 static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode);
telsoa014fcda012018-03-09 14:13:49 +0000134 /// @}
telsoa01c577f2c2018-08-31 09:22:23 +0100135 static void Destroy(IGpuAccTunedParameters* params);
telsoa014fcda012018-03-09 14:13:49 +0000136
137 /// Loads an existing set of tuned parameters from the given file.
138 /// If there is an error loading the file, an armnn::Exception is thrown.
139 virtual void Load(const char* filename) = 0;
140
141 /// Saves the current set of tuned parameters to the given file.
142 /// If there is an error saving to the file, an armnn::Exception is thrown.
143 virtual void Save(const char* filename) const = 0;
144
145protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100146 virtual ~IGpuAccTunedParameters() {};
telsoa014fcda012018-03-09 14:13:49 +0000147};
148
149}