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;
41 VLOG(DRIVER) <<
"ArmnnDriver::ArmnnDriver()";
42 m_Device = std::unique_ptr<ArmnnDevice>(
new ArmnnDevice(std::move(options)));
46 VLOG(DRIVER) <<
"ArmnnDevice failed to initialise: " << ex.
what();
50 VLOG(DRIVER) <<
"ArmnnDevice failed to initialise with an unknown error";
56 const std::string&
getName()
const override
58 VLOG(DRIVER) <<
"ArmnnDriver::getName()";
59 static const std::string name =
"arm-armnn-sl";
65 VLOG(DRIVER) <<
"ArmnnDriver::getVersionString()";
72 VLOG(DRIVER) <<
"ArmnnDriver::getFeatureLevel()";
73 return kVersionFeatureLevel6;
78 VLOG(DRIVER) <<
"ArmnnDriver::getType()";
79 return DeviceType::CPU;
84 VLOG(DRIVER) <<
"ArmnnDriver::getSupportedExtensions()";
85 static const std::vector<Extension> extensions = {};
91 VLOG(DRIVER) <<
"ArmnnDriver::GetCapabilities()";
97 VLOG(DRIVER) <<
"ArmnnDriver::getNumberOfCacheFilesNeeded()";
98 unsigned int numberOfCachedModelFiles = 0;
99 for (
auto& backend : m_Device->m_Options.GetBackends())
102 VLOG(DRIVER) <<
"ArmnnDriver::getNumberOfCacheFilesNeeded() = "
103 << std::to_string(numberOfCachedModelFiles);
105 return std::make_pair(numberOfCachedModelFiles, 1ul);
108 GeneralResult<void>
wait()
const override
110 VLOG(DRIVER) <<
"ArmnnDriver::wait()";
116 VLOG(DRIVER) <<
"ArmnnDriver::getSupportedOperations()";
117 if (m_Device.get() ==
nullptr)
119 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
122 std::stringstream ss;
123 ss <<
"ArmnnDriverImpl::getSupportedOperations()";
124 std::string fileName;
125 std::string timestamp;
126 if (!m_Device->m_Options.GetRequestInputsAndOutputsDumpDir().empty())
129 << m_Device->m_Options.GetRequestInputsAndOutputsDumpDir()
132 <<
"_getSupportedOperations.txt";
134 VLOG(DRIVER) << ss.str().c_str();
136 if (!m_Device->m_Options.GetRequestInputsAndOutputsDumpDir().empty())
139 std::ofstream fileStream;
140 fileStream.open(fileName, std::ofstream::out | std::ofstream::trunc);
141 if (fileStream.good())
143 fileStream << timestamp << std::endl;
144 fileStream << timestamp << std::endl;
149 std::vector<bool> result;
150 if (!m_Device->m_Runtime)
152 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
156 if (
const auto result = validate(model); !result.ok())
158 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"Invalid Model!";
164 m_Device->m_Options.GetForcedUnsupportedOperations());
169 return NN_ERROR(ErrorStatus::GENERAL_FAILURE) <<
"Conversion Error!";
174 result.reserve(model.main.operations.size());
175 for (uint32_t operationIdx = 0; operationIdx < model.main.operations.size(); ++operationIdx)
178 result.push_back(operationSupported);
185 ExecutionPreference preference,
187 OptionalTimePoint deadline,
188 const std::vector<SharedHandle>& modelCache,
189 const std::vector<SharedHandle>& dataCache,
190 const CacheToken& token,
191 const std::vector<android::nn::TokenValuePair>& hints,
192 const std::vector<android::nn::ExtensionNameAndPrefix>& extensionNameToPrefix)
const override
194 VLOG(DRIVER) <<
"ArmnnDriver::prepareModel()";
196 if (m_Device.get() ==
nullptr)
198 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
201 if (
const auto result = validate(model); !result.ok()) {
202 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"Invalid Model: " << result.error();
204 if (
const auto result = validate(preference); !result.ok()) {
205 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT)
206 <<
"Invalid ExecutionPreference: " << result.error();
208 if (
const auto result = validate(priority); !result.ok()) {
209 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"Invalid Priority: " << result.error();
213 if (hasDeadlinePassed(deadline)) {
214 return NN_ERROR(ErrorStatus::MISSED_DEADLINE_PERSISTENT);
218 m_Device->m_ClTunedParameters,
224 model.relaxComputationFloat32toFloat16 && m_Device->m_Options.GetFp16Enabled(),
230 const std::vector<SharedHandle>& modelCache,
231 const std::vector<SharedHandle>& dataCache,
232 const CacheToken& token)
const override
234 VLOG(DRIVER) <<
"ArmnnDriver::prepareModelFromCache()";
235 if (m_Device.get() ==
nullptr)
237 return NN_ERROR(ErrorStatus::DEVICE_UNAVAILABLE) <<
"Device Unavailable!";
240 if (hasDeadlinePassed(deadline)) {
241 return NN_ERROR(ErrorStatus::MISSED_DEADLINE_PERSISTENT);
247 m_Device->m_ClTunedParameters,
252 m_Device->m_Options.GetFp16Enabled());
256 GeneralResult<SharedBuffer>
allocate(
const BufferDesc&,
257 const std::vector<SharedPreparedModel>&,
258 const std::vector<BufferRole>&,
259 const std::vector<BufferRole>&)
const override
261 VLOG(DRIVER) <<
"ArmnnDriver::allocate()";
262 return NN_ERROR(ErrorStatus::INVALID_ARGUMENT) <<
"ArmnnDriver::allocate -- does not support allocate.";