2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
11 #include "INetwork.hpp"
12 #include "IProfiler.hpp"
13 #include "TypesUtils.hpp"
18 using NetworkId = int;
20 class IGpuAccTunedParameters;
23 using IRuntimePtr = std::unique_ptr<IRuntime, void(*)(IRuntime* runtime)>;
28 struct CreationOptions
31 : m_GpuAccTunedParameters(nullptr)
32 , m_EnableGpuProfiling(false)
35 /// 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;
39 // Setting this flag will allow the user to obtain GPU profiling information from the runtime.
40 bool m_EnableGpuProfiling;
43 static IRuntime* CreateRaw(const CreationOptions& options);
44 static IRuntimePtr Create(const CreationOptions& options);
45 static void Destroy(IRuntime* runtime);
47 /// 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.
50 /// The runtime takes ownership of the network once passed in.
51 /// @return armnn::Status
52 virtual Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network) = 0;
54 /// 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;
64 virtual TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
65 virtual TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
67 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors
68 virtual Status EnqueueWorkload(NetworkId networkId,
69 const InputTensors& inputTensors,
70 const OutputTensors& outputTensors) = 0;
72 /// Unloads a network from the IRuntime.
73 /// 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.
75 /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork().
76 /// @return armnn::Status
77 virtual Status UnloadNetwork(NetworkId networkId) = 0;
79 virtual const IDeviceSpec& GetDeviceSpec() const = 0;
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;
90 using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
92 /// 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.
96 /// Can be created in two modes:
97 /// - 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
99 /// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
101 /// The parameters can be loaded from and saved to a file so that you can first run a slow initial read-write
102 /// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
103 class IGpuAccTunedParameters
109 UpdateTunedParameters
112 /// Creates an IClTunedParameters with the given mode.
114 static IGpuAccTunedParameters* CreateRaw(Mode mode);
115 static IGpuAccTunedParametersPtr Create(Mode mode);
117 static void Destroy(IGpuAccTunedParameters* params);
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;
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;
128 virtual ~IGpuAccTunedParameters() {};