blob: 36efdbdcab75748b7a3d04a4e95b1dbe58924cd3 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// See LICENSE file in the project root for full license information.
4//
5#pragma once
6
7#include <memory>
8
9#include "Types.hpp"
10#include "Tensor.hpp"
11#include "INetwork.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +010012#include "IProfiler.hpp"
telsoa014fcda012018-03-09 14:13:49 +000013#include "TypesUtils.hpp"
14
15namespace armnn
16{
17
18using NetworkId = int;
19
telsoa01c577f2c2018-08-31 09:22:23 +010020class IGpuAccTunedParameters;
telsoa014fcda012018-03-09 14:13:49 +000021
22class IRuntime;
23using IRuntimePtr = std::unique_ptr<IRuntime, void(*)(IRuntime* runtime)>;
24
25class IRuntime
26{
27public:
28 struct CreationOptions
29 {
telsoa01c577f2c2018-08-31 09:22:23 +010030 CreationOptions()
31 : m_GpuAccTunedParameters(nullptr)
32 , m_EnableGpuProfiling(false)
33 {}
telsoa014fcda012018-03-09 14:13:49 +000034
telsoa01c577f2c2018-08-31 09:22:23 +010035 /// If set, uses the GpuAcc tuned parameters from the given object when executing GPU workloads.
36 /// It will also be updated with new tuned parameters if it is configured to do so.
37 std::shared_ptr<IGpuAccTunedParameters> m_GpuAccTunedParameters;
38
39 // Setting this flag will allow the user to obtain GPU profiling information from the runtime.
40 bool m_EnableGpuProfiling;
telsoa014fcda012018-03-09 14:13:49 +000041 };
42
43 static IRuntime* CreateRaw(const CreationOptions& options);
44 static IRuntimePtr Create(const CreationOptions& options);
45 static void Destroy(IRuntime* runtime);
46
telsoa01c577f2c2018-08-31 09:22:23 +010047 /// Loads a complete network into the IRuntime.
48 /// @param [out] networkIdOut - Unique identifier for the network is returned in this reference.
49 /// @param [in] network - Complete network to load into the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +000050 /// The runtime takes ownership of the network once passed in.
51 /// @return armnn::Status
52 virtual Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network) = 0;
53
telsoa01c577f2c2018-08-31 09:22:23 +010054 /// Load a complete network into the IRuntime.
55 /// @param [out] networkIdOut Unique identifier for the network is returned in this reference.
56 /// @param [in] network Complete network to load into the IRuntime.
57 /// @param [out] errorMessage Error message if there were any errors.
58 /// The runtime takes ownership of the network once passed in.
59 /// @return armnn::Status
60 virtual Status LoadNetwork(NetworkId& networkIdOut,
61 IOptimizedNetworkPtr network,
62 std::string & errorMessage) = 0;
63
telsoa014fcda012018-03-09 14:13:49 +000064 virtual TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
65 virtual TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
66
telsoa01c577f2c2018-08-31 09:22:23 +010067 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors
telsoa014fcda012018-03-09 14:13:49 +000068 virtual Status EnqueueWorkload(NetworkId networkId,
telsoa01c577f2c2018-08-31 09:22:23 +010069 const InputTensors& inputTensors,
70 const OutputTensors& outputTensors) = 0;
telsoa014fcda012018-03-09 14:13:49 +000071
telsoa01c577f2c2018-08-31 09:22:23 +010072 /// Unloads a network from the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +000073 /// At the moment this only removes the network from the m_Impl->m_Network.
74 /// This might need more work in the future to be AndroidNN compliant.
telsoa01c577f2c2018-08-31 09:22:23 +010075 /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork().
telsoa014fcda012018-03-09 14:13:49 +000076 /// @return armnn::Status
77 virtual Status UnloadNetwork(NetworkId networkId) = 0;
78
telsoa01c577f2c2018-08-31 09:22:23 +010079 virtual const IDeviceSpec& GetDeviceSpec() const = 0;
80
81 /// Gets the profiler corresponding to the given network id.
82 /// @param networkId The id of the network for which to get the profile.
83 /// @return A pointer to the requested profiler, or nullptr if not found.
84 virtual const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const = 0;
telsoa014fcda012018-03-09 14:13:49 +000085
86protected:
87 ~IRuntime() {}
88};
89
telsoa01c577f2c2018-08-31 09:22:23 +010090using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
telsoa014fcda012018-03-09 14:13:49 +000091
telsoa01c577f2c2018-08-31 09:22:23 +010092/// Manages a set of GpuAcc parameters which have been tuned for maximum performance.
93/// Passes an instance of this object to the IRuntime::Create() method (via IRuntime::CreationOptions) to use it
94/// for all GPU workload execution.
telsoa014fcda012018-03-09 14:13:49 +000095///
96/// Can be created in two modes:
telsoa01c577f2c2018-08-31 09:22:23 +010097/// - In UseTunedParameters mode, the parameters stored in this object are used to execute GPU workloads.
98/// - In UpdateTunedParameters mode, additionally, whenever a GPU workload is executed for the first time, the
telsoa014fcda012018-03-09 14:13:49 +000099/// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
100///
telsoa01c577f2c2018-08-31 09:22:23 +0100101/// 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 +0000102/// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
telsoa01c577f2c2018-08-31 09:22:23 +0100103class IGpuAccTunedParameters
telsoa014fcda012018-03-09 14:13:49 +0000104{
105public:
106 enum class Mode
107 {
108 UseTunedParameters,
109 UpdateTunedParameters
110 };
111
112 /// Creates an IClTunedParameters with the given mode.
113 /// @{
telsoa01c577f2c2018-08-31 09:22:23 +0100114 static IGpuAccTunedParameters* CreateRaw(Mode mode);
115 static IGpuAccTunedParametersPtr Create(Mode mode);
telsoa014fcda012018-03-09 14:13:49 +0000116 /// @}
telsoa01c577f2c2018-08-31 09:22:23 +0100117 static void Destroy(IGpuAccTunedParameters* params);
telsoa014fcda012018-03-09 14:13:49 +0000118
119 /// Loads an existing set of tuned parameters from the given file.
120 /// If there is an error loading the file, an armnn::Exception is thrown.
121 virtual void Load(const char* filename) = 0;
122
123 /// Saves the current set of tuned parameters to the given file.
124 /// If there is an error saving to the file, an armnn::Exception is thrown.
125 virtual void Save(const char* filename) const = 0;
126
127protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100128 virtual ~IGpuAccTunedParameters() {};
telsoa014fcda012018-03-09 14:13:49 +0000129};
130
131}