ArmNN
 23.08
ArmnnDriver Class Reference

#include <ArmnnDriver.hpp>

Inheritance diagram for ArmnnDriver:
[legend]
Collaboration diagram for ArmnnDriver:
[legend]

Public Member Functions

 ArmnnDriver (DriverOptions options)
 
const std::string & getName () const override
 
const std::string & getVersionString () const override
 
Version getFeatureLevel () const override
 
DeviceType getType () const override
 
const std::vector< Extension > & getSupportedExtensions () const override
 
const Capabilities & getCapabilities () const override
 
std::pair< uint32_t, uint32_t > getNumberOfCacheFilesNeeded () const override
 
GeneralResult< void > wait () const override
 
GeneralResult< std::vector< bool > > getSupportedOperations (const Model &model) const override
 
GeneralResult< SharedPreparedModel > prepareModel (const Model &model, ExecutionPreference preference, Priority priority, OptionalTimePoint deadline, const std::vector< SharedHandle > &modelCache, const std::vector< SharedHandle > &dataCache, const CacheToken &token, const std::vector< android::nn::TokenValuePair > &hints, const std::vector< android::nn::ExtensionNameAndPrefix > &extensionNameToPrefix) const override
 
GeneralResult< SharedPreparedModel > prepareModelFromCache (OptionalTimePoint deadline, const std::vector< SharedHandle > &modelCache, const std::vector< SharedHandle > &dataCache, const CacheToken &token) const override
 
GeneralResult< SharedBuffer > allocate (const BufferDesc &, const std::vector< SharedPreparedModel > &, const std::vector< BufferRole > &, const std::vector< BufferRole > &) const override
 

Detailed Description

Definition at line 31 of file ArmnnDriver.hpp.

Constructor & Destructor Documentation

◆ ArmnnDriver()

ArmnnDriver ( DriverOptions  options)
inline

Definition at line 36 of file ArmnnDriver.hpp.

37  {
38  try
39  {
40  VLOG(DRIVER) << "ArmnnDriver::ArmnnDriver()";
41  m_Device = std::unique_ptr<ArmnnDevice>(new ArmnnDevice(std::move(options)));
42  }
44  {
45  VLOG(DRIVER) << "ArmnnDevice failed to initialise: " << ex.what();
46  }
47  catch (...)
48  {
49  VLOG(DRIVER) << "ArmnnDevice failed to initialise with an unknown error";
50  }
51  }

References Exception::what().

Member Function Documentation

◆ allocate()

GeneralResult<SharedBuffer> allocate ( const BufferDesc &  ,
const std::vector< SharedPreparedModel > &  ,
const std::vector< BufferRole > &  ,
const std::vector< BufferRole > &   
) const
inlineoverride

Definition at line 252 of file ArmnnDriver.hpp.

256  {
257  VLOG(DRIVER) << "ArmnnDriver::allocate()";
258  return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) << "ArmnnDriver::allocate -- does not support allocate.";
259  }

◆ getCapabilities()

const Capabilities& getCapabilities ( ) const
inlineoverride

Definition at line 88 of file ArmnnDriver.hpp.

89  {
90  VLOG(DRIVER) << "ArmnnDriver::GetCapabilities()";
91  return ArmnnDriverImpl::GetCapabilities(m_Device->m_Runtime);
92  }

References ArmnnDriverImpl::GetCapabilities().

◆ getFeatureLevel()

Version getFeatureLevel ( ) const
inlineoverride

Definition at line 69 of file ArmnnDriver.hpp.

70  {
71  VLOG(DRIVER) << "ArmnnDriver::getFeatureLevel()";
72  return kVersionFeatureLevel6;
73  }

◆ getName()

const std::string& getName ( ) const
inlineoverride

Definition at line 55 of file ArmnnDriver.hpp.

56  {
57  VLOG(DRIVER) << "ArmnnDriver::getName()";
58  static const std::string name = "arm-armnn-sl";
59  return name;
60  }

◆ getNumberOfCacheFilesNeeded()

std::pair<uint32_t, uint32_t> getNumberOfCacheFilesNeeded ( ) const
inlineoverride

Definition at line 94 of file ArmnnDriver.hpp.

95  {
96  VLOG(DRIVER) << "ArmnnDriver::getNumberOfCacheFilesNeeded()";
97  unsigned int numberOfCachedModelFiles = 0;
98  for (auto& backend : m_Device->m_Options.GetBackends())
99  {
100  numberOfCachedModelFiles += GetNumberOfCacheFiles(backend);
101  VLOG(DRIVER) << "ArmnnDriver::getNumberOfCacheFilesNeeded() = "
102  << std::to_string(numberOfCachedModelFiles);
103  }
104  return std::make_pair(numberOfCachedModelFiles, 1ul);
105  }

References armnn::GetNumberOfCacheFiles().

◆ getSupportedExtensions()

const std::vector<Extension>& getSupportedExtensions ( ) const
inlineoverride

Definition at line 81 of file ArmnnDriver.hpp.

82  {
83  VLOG(DRIVER) << "ArmnnDriver::getSupportedExtensions()";
84  static const std::vector<Extension> extensions = {};
85  return extensions;
86  }

◆ getSupportedOperations()

GeneralResult<std::vector<bool> > getSupportedOperations ( const Model model) const
inlineoverride

Definition at line 113 of file ArmnnDriver.hpp.

114  {
115  VLOG(DRIVER) << "ArmnnDriver::getSupportedOperations()";
116  if (m_Device.get() == nullptr)
117  {
118  return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) << "Device Unavailable!";
119  }
120 
121  std::stringstream ss;
122  ss << "ArmnnDriverImpl::getSupportedOperations()";
123  std::string fileName;
124  std::string timestamp;
125  if (!m_Device->m_Options.GetRequestInputsAndOutputsDumpDir().empty())
126  {
127  ss << " : "
128  << m_Device->m_Options.GetRequestInputsAndOutputsDumpDir()
129  << "/"
130  // << GetFileTimestamp()
131  << "_getSupportedOperations.txt";
132  }
133  VLOG(DRIVER) << ss.str().c_str();
134 
135  if (!m_Device->m_Options.GetRequestInputsAndOutputsDumpDir().empty())
136  {
137  //dump the marker file
138  std::ofstream fileStream;
139  fileStream.open(fileName, std::ofstream::out | std::ofstream::trunc);
140  if (fileStream.good())
141  {
142  fileStream << timestamp << std::endl;
143  fileStream << timestamp << std::endl;
144  }
145  fileStream.close();
146  }
147 
148  std::vector<bool> result;
149  if (!m_Device->m_Runtime)
150  {
151  return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) << "Device Unavailable!";
152  }
153 
154  // Run general model validation, if this doesn't pass we shouldn't analyse the model anyway.
155  if (const auto result = validate(model); !result.ok())
156  {
157  return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) << "Invalid Model!";
158  }
159 
160  // Attempt to convert the model to an ArmNN input network (INetwork).
161  ModelToINetworkTransformer modelConverter(m_Device->m_Options.GetBackends(),
162  model,
163  m_Device->m_Options.GetForcedUnsupportedOperations());
164 
165  if (modelConverter.GetConversionResult() != ConversionResult::Success
166  && modelConverter.GetConversionResult() != ConversionResult::UnsupportedFeature)
167  {
168  return NN_ERROR(ErrorStatus::GENERAL_FAILURE) << "Conversion Error!";
169  }
170 
171  // Check each operation if it was converted successfully and copy the flags
172  // into the result (vector<bool>) that we need to return to Android.
173  result.reserve(model.main.operations.size());
174  for (uint32_t operationIdx = 0; operationIdx < model.main.operations.size(); ++operationIdx)
175  {
176  bool operationSupported = modelConverter.IsOperationSupported(operationIdx);
177  result.push_back(operationSupported);
178  }
179 
180  return result;
181  }

References ModelToINetworkTransformer::GetConversionResult(), ModelToINetworkTransformer::IsOperationSupported(), armnn_driver::Success, and armnn_driver::UnsupportedFeature.

◆ getType()

DeviceType getType ( ) const
inlineoverride

Definition at line 75 of file ArmnnDriver.hpp.

76  {
77  VLOG(DRIVER) << "ArmnnDriver::getType()";
78  return DeviceType::CPU;
79  }

◆ getVersionString()

const std::string& getVersionString ( ) const
inlineoverride

Definition at line 62 of file ArmnnDriver.hpp.

63  {
64  VLOG(DRIVER) << "ArmnnDriver::getVersionString()";
65  static const std::string versionString = ARMNN_VERSION;
66  return versionString;
67  }

References ARMNN_VERSION.

◆ prepareModel()

GeneralResult<SharedPreparedModel> prepareModel ( const Model model,
ExecutionPreference  preference,
Priority  priority,
OptionalTimePoint  deadline,
const std::vector< SharedHandle > &  modelCache,
const std::vector< SharedHandle > &  dataCache,
const CacheToken &  token,
const std::vector< android::nn::TokenValuePair > &  hints,
const std::vector< android::nn::ExtensionNameAndPrefix > &  extensionNameToPrefix 
) const
inlineoverride

Definition at line 183 of file ArmnnDriver.hpp.

192  {
193  VLOG(DRIVER) << "ArmnnDriver::prepareModel()";
194 
195  if (m_Device.get() == nullptr)
196  {
197  return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) << "Device Unavailable!";
198  }
199  // Validate arguments.
200  if (const auto result = validate(model); !result.ok()) {
201  return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) << "Invalid Model: " << result.error();
202  }
203  if (const auto result = validate(preference); !result.ok()) {
204  return NN_ERROR(ErrorStatus::INVALID_ARGUMENT)
205  << "Invalid ExecutionPreference: " << result.error();
206  }
207  if (const auto result = validate(priority); !result.ok()) {
208  return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) << "Invalid Priority: " << result.error();
209  }
210 
211  // Check if deadline has passed.
212  if (hasDeadlinePassed(deadline)) {
213  return NN_ERROR(ErrorStatus::MISSED_DEADLINE_PERSISTENT);
214  }
215 
216  return ArmnnDriverImpl::PrepareArmnnModel(m_Device->m_Runtime,
217  m_Device->m_ClTunedParameters,
218  m_Device->m_Options,
219  model,
220  modelCache,
221  dataCache,
222  token,
223  model.relaxComputationFloat32toFloat16 && m_Device->m_Options.GetFp16Enabled(),
224  priority);
225  }

References ArmnnDriverImpl::PrepareArmnnModel().

◆ prepareModelFromCache()

GeneralResult<SharedPreparedModel> prepareModelFromCache ( OptionalTimePoint  deadline,
const std::vector< SharedHandle > &  modelCache,
const std::vector< SharedHandle > &  dataCache,
const CacheToken &  token 
) const
inlineoverride

Definition at line 227 of file ArmnnDriver.hpp.

231  {
232  VLOG(DRIVER) << "ArmnnDriver::prepareModelFromCache()";
233  if (m_Device.get() == nullptr)
234  {
235  return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) << "Device Unavailable!";
236  }
237  // Check if deadline has passed.
238  if (hasDeadlinePassed(deadline)) {
239  return NN_ERROR(ErrorStatus::MISSED_DEADLINE_PERSISTENT);
240  }
241 
243  m_Device->m_Runtime,
244  m_Device->m_ClTunedParameters,
245  m_Device->m_Options,
246  modelCache,
247  dataCache,
248  token,
249  m_Device->m_Options.GetFp16Enabled());
250  }

References ArmnnDriverImpl::PrepareArmnnModelFromCache().

◆ wait()

GeneralResult<void> wait ( ) const
inlineoverride

Definition at line 107 of file ArmnnDriver.hpp.

108  {
109  VLOG(DRIVER) << "ArmnnDriver::wait()";
110  return {};
111  }

The documentation for this class was generated from the following file:
armnn_driver::ArmnnDriverImpl::PrepareArmnnModel
static GeneralResult< SharedPreparedModel > PrepareArmnnModel(const armnn::IRuntimePtr &runtime, const armnn::IGpuAccTunedParametersPtr &clTunedParameters, const DriverOptions &options, const Model &model, const std::vector< SharedHandle > &modelCacheHandle, const std::vector< SharedHandle > &dataCacheHandle, const CacheToken &token, bool float32ToFloat16=false, Priority priority=Priority::MEDIUM)
Definition: ArmnnDriverImpl.cpp:99
armnn_driver::ArmnnDevice
Definition: ArmnnDevice.hpp:15
armnn_driver::ConversionResult::UnsupportedFeature
@ UnsupportedFeature
armnn::Exception::what
virtual const char * what() const noexcept override
Definition: Exceptions.cpp:32
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
ARMNN_VERSION
#define ARMNN_VERSION
ARMNN_VERSION: "X.Y.Z" where: X = Major version number Y = Minor version number Z = Patch version num...
Definition: Version.hpp:22
armnn_driver::ArmnnDriverImpl::GetCapabilities
static const Capabilities & GetCapabilities(const armnn::IRuntimePtr &runtime)
Definition: ArmnnDriverImpl.cpp:554
armnn_driver::ConversionResult::Success
@ Success
armnn::GetNumberOfCacheFiles
unsigned int GetNumberOfCacheFiles(const armnn::BackendId &backend)
Returns the number of cached files if backend supports caching.
Definition: BackendHelper.cpp:130
armnn_driver::ArmnnDriverImpl::PrepareArmnnModelFromCache
static GeneralResult< SharedPreparedModel > PrepareArmnnModelFromCache(const armnn::IRuntimePtr &runtime, const armnn::IGpuAccTunedParametersPtr &clTunedParameters, const DriverOptions &options, const std::vector< SharedHandle > &modelCacheHandle, const std::vector< SharedHandle > &dataCacheHandle, const CacheToken &token, bool float32ToFloat16=false)
Definition: ArmnnDriverImpl.cpp:338
armnn_driver::ModelToINetworkTransformer
Definition: ModelToINetworkTransformer.hpp:30