blob: 44864ce86d644ddc71b56f96664a201b350a83b6 [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
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
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +000086 /// Registers a callback function to debug layers performing custom computations on intermediate tensors.
87 /// @param networkId The id of the network to register the callback.
88 /// @param func callback function to pass to the debug layer.
89 virtual void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func) = 0;
90
telsoa014fcda012018-03-09 14:13:49 +000091protected:
92 ~IRuntime() {}
93};
94
telsoa01c577f2c2018-08-31 09:22:23 +010095using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
telsoa014fcda012018-03-09 14:13:49 +000096
telsoa01c577f2c2018-08-31 09:22:23 +010097/// Manages a set of GpuAcc parameters which have been tuned for maximum performance.
98/// Passes an instance of this object to the IRuntime::Create() method (via IRuntime::CreationOptions) to use it
99/// for all GPU workload execution.
telsoa014fcda012018-03-09 14:13:49 +0000100///
101/// Can be created in two modes:
telsoa01c577f2c2018-08-31 09:22:23 +0100102/// - In UseTunedParameters mode, the parameters stored in this object are used to execute GPU workloads.
103/// - In UpdateTunedParameters mode, additionally, whenever a GPU workload is executed for the first time, the
telsoa014fcda012018-03-09 14:13:49 +0000104/// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
105///
telsoa01c577f2c2018-08-31 09:22:23 +0100106/// 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 +0000107/// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
telsoa01c577f2c2018-08-31 09:22:23 +0100108class IGpuAccTunedParameters
telsoa014fcda012018-03-09 14:13:49 +0000109{
110public:
111 enum class Mode
112 {
113 UseTunedParameters,
114 UpdateTunedParameters
115 };
116
117 /// Creates an IClTunedParameters with the given mode.
118 /// @{
telsoa01c577f2c2018-08-31 09:22:23 +0100119 static IGpuAccTunedParameters* CreateRaw(Mode mode);
120 static IGpuAccTunedParametersPtr Create(Mode mode);
telsoa014fcda012018-03-09 14:13:49 +0000121 /// @}
telsoa01c577f2c2018-08-31 09:22:23 +0100122 static void Destroy(IGpuAccTunedParameters* params);
telsoa014fcda012018-03-09 14:13:49 +0000123
124 /// Loads an existing set of tuned parameters from the given file.
125 /// If there is an error loading the file, an armnn::Exception is thrown.
126 virtual void Load(const char* filename) = 0;
127
128 /// Saves the current set of tuned parameters to the given file.
129 /// If there is an error saving to the file, an armnn::Exception is thrown.
130 virtual void Save(const char* filename) const = 0;
131
132protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100133 virtual ~IGpuAccTunedParameters() {};
telsoa014fcda012018-03-09 14:13:49 +0000134};
135
136}