8 #include <android-base/logging.h>
9 #include <nnapi/IBuffer.h>
10 #include <nnapi/IDevice.h>
11 #include <nnapi/IPreparedModel.h>
12 #include <nnapi/OperandTypes.h>
13 #include <nnapi/Result.h>
14 #include <nnapi/Types.h>
15 #include <nnapi/Validation.h>
34 std::unique_ptr<ArmnnDevice> m_Device;
40 VLOG(DRIVER) <<
"ArmnnDriver::ArmnnDriver()";
41 m_Device = std::unique_ptr<ArmnnDevice>(
new ArmnnDevice(std::move(options)));
45 VLOG(DRIVER) <<
"ArmnnDevice failed to initialise: " << ex.
what();
49 VLOG(DRIVER) <<
"ArmnnDevice failed to initialise with an unknown error";
55 const std::string&
getName()
const override
57 VLOG(DRIVER) <<
"ArmnnDriver::getName()";
58 static const std::string name =
"arm-armnn-sl";
64 VLOG(DRIVER) <<
"ArmnnDriver::getVersionString()";
71 VLOG(DRIVER) <<
"ArmnnDriver::getFeatureLevel()";
72 return kVersionFeatureLevel6;
77 VLOG(DRIVER) <<
"ArmnnDriver::getType()";
78 return DeviceType::CPU;
83 VLOG(DRIVER) <<
"ArmnnDriver::getSupportedExtensions()";
84 static const std::vector<Extension> extensions = {};
90 VLOG(DRIVER) <<
"ArmnnDriver::GetCapabilities()";
96 VLOG(DRIVER) <<
"ArmnnDriver::getNumberOfCacheFilesNeeded()";
97 unsigned int numberOfCachedModelFiles = 0;
98 for (
auto& backend : m_Device->m_Options.GetBackends())
101 VLOG(DRIVER) <<
"ArmnnDriver::getNumberOfCacheFilesNeeded() = "
102 << std::to_string(numberOfCachedModelFiles);
104 return std::make_pair(numberOfCachedModelFiles, 1ul);
107 GeneralResult<void>
wait()
const override
109 VLOG(DRIVER) <<
"ArmnnDriver::wait()";
115 VLOG(DRIVER) <<
"ArmnnDriver::getSupportedOperations()";
116 if (m_Device.get() ==
nullptr)
118 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
121 std::stringstream ss;
122 ss <<
"ArmnnDriverImpl::getSupportedOperations()";
123 std::string fileName;
124 std::string timestamp;
125 if (!m_Device->m_Options.GetRequestInputsAndOutputsDumpDir().empty())
128 << m_Device->m_Options.GetRequestInputsAndOutputsDumpDir()
131 <<
"_getSupportedOperations.txt";
133 VLOG(DRIVER) << ss.str().c_str();
135 if (!m_Device->m_Options.GetRequestInputsAndOutputsDumpDir().empty())
138 std::ofstream fileStream;
139 fileStream.open(fileName, std::ofstream::out | std::ofstream::trunc);
140 if (fileStream.good())
142 fileStream << timestamp << std::endl;
143 fileStream << timestamp << std::endl;
148 std::vector<bool> result;
149 if (!m_Device->m_Runtime)
151 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
155 if (
const auto result = validate(model); !result.ok())
157 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"Invalid Model!";
163 m_Device->m_Options.GetForcedUnsupportedOperations());
168 return NN_ERROR(ErrorStatus::GENERAL_FAILURE) <<
"Conversion Error!";
173 result.reserve(model.main.operations.size());
174 for (uint32_t operationIdx = 0; operationIdx < model.main.operations.size(); ++operationIdx)
177 result.push_back(operationSupported);
184 ExecutionPreference preference,
186 OptionalTimePoint deadline,
187 const std::vector<SharedHandle>& modelCache,
188 const std::vector<SharedHandle>& dataCache,
189 const CacheToken& token,
190 const std::vector<android::nn::TokenValuePair>& hints,
191 const std::vector<android::nn::ExtensionNameAndPrefix>& extensionNameToPrefix)
const override
193 VLOG(DRIVER) <<
"ArmnnDriver::prepareModel()";
195 if (m_Device.get() ==
nullptr)
197 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
200 if (
const auto result = validate(model); !result.ok()) {
201 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"Invalid Model: " << result.error();
203 if (
const auto result = validate(preference); !result.ok()) {
204 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT)
205 <<
"Invalid ExecutionPreference: " << result.error();
207 if (
const auto result = validate(priority); !result.ok()) {
208 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"Invalid Priority: " << result.error();
212 if (hasDeadlinePassed(deadline)) {
213 return NN_ERROR(ErrorStatus::MISSED_DEADLINE_PERSISTENT);
217 m_Device->m_ClTunedParameters,
223 model.relaxComputationFloat32toFloat16 && m_Device->m_Options.GetFp16Enabled(),
228 const std::vector<SharedHandle>& modelCache,
229 const std::vector<SharedHandle>& dataCache,
230 const CacheToken& token)
const override
232 VLOG(DRIVER) <<
"ArmnnDriver::prepareModelFromCache()";
233 if (m_Device.get() ==
nullptr)
235 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
238 if (hasDeadlinePassed(deadline)) {
239 return NN_ERROR(ErrorStatus::MISSED_DEADLINE_PERSISTENT);
244 m_Device->m_ClTunedParameters,
249 m_Device->m_Options.GetFp16Enabled());
252 GeneralResult<SharedBuffer>
allocate(
const BufferDesc&,
253 const std::vector<SharedPreparedModel>&,
254 const std::vector<BufferRole>&,
255 const std::vector<BufferRole>&)
const override
257 VLOG(DRIVER) <<
"ArmnnDriver::allocate()";
258 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"ArmnnDriver::allocate -- does not support allocate.";