telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 4 | // |
| 5 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 6 | #define LOG_TAG "ArmnnDriver" |
| 7 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 8 | #include "ArmnnDriverImpl.hpp" |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 9 | #include "ArmnnPreparedModel.hpp" |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 10 | |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 11 | #if defined(ARMNN_ANDROID_NN_V1_2) || defined(ARMNN_ANDROID_NN_V1_3) // Using ::android::hardware::neuralnetworks::V1_2 |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 12 | #include "ArmnnPreparedModel_1_2.hpp" |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 13 | #endif |
| 14 | |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 15 | #ifdef ARMNN_ANDROID_NN_V1_3 // Using ::android::hardware::neuralnetworks::V1_2 |
| 16 | #include "ArmnnPreparedModel_1_3.hpp" |
| 17 | #endif |
| 18 | |
| 19 | #include "Utils.hpp" |
| 20 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 21 | #include "ModelToINetworkConverter.hpp" |
| 22 | #include "SystemPropertiesUtils.hpp" |
Colm Donelan | 08d9a1c | 2020-09-09 17:56:55 +0100 | [diff] [blame] | 23 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 24 | #include <ValidateHal.h> |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 25 | #include <log/log.h> |
| 26 | |
| 27 | using namespace std; |
| 28 | using namespace android; |
| 29 | using namespace android::nn; |
| 30 | using namespace android::hardware; |
| 31 | |
| 32 | namespace |
| 33 | { |
| 34 | |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 35 | void NotifyCallbackAndCheck(const sp<V1_0::IPreparedModelCallback>& callback, |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 36 | V1_0::ErrorStatus errorStatus, |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 37 | const sp<V1_0::IPreparedModel>& preparedModelPtr) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 38 | { |
| 39 | Return<void> returned = callback->notify(errorStatus, preparedModelPtr); |
| 40 | // This check is required, if the callback fails and it isn't checked it will bring down the service |
| 41 | if (!returned.isOk()) |
| 42 | { |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 43 | ALOGE("ArmnnDriverImpl::prepareModel: hidl callback failed to return properly: %s ", |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 44 | returned.description().c_str()); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 48 | Return<V1_0::ErrorStatus> FailPrepareModel(V1_0::ErrorStatus error, |
| 49 | const string& message, |
| 50 | const sp<V1_0::IPreparedModelCallback>& callback) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 51 | { |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 52 | ALOGW("ArmnnDriverImpl::prepareModel: %s", message.c_str()); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 53 | NotifyCallbackAndCheck(callback, error, nullptr); |
| 54 | return error; |
| 55 | } |
| 56 | |
| 57 | } // namespace |
| 58 | |
| 59 | namespace armnn_driver |
| 60 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 61 | |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 62 | template<typename HalPolicy> |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 63 | Return<V1_0::ErrorStatus> ArmnnDriverImpl<HalPolicy>::prepareModel( |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 64 | const armnn::IRuntimePtr& runtime, |
| 65 | const armnn::IGpuAccTunedParametersPtr& clTunedParameters, |
| 66 | const DriverOptions& options, |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 67 | const HalModel& model, |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 68 | const sp<V1_0::IPreparedModelCallback>& cb, |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 69 | bool float32ToFloat16) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 70 | { |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 71 | ALOGV("ArmnnDriverImpl::prepareModel()"); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 72 | |
| 73 | if (cb.get() == nullptr) |
| 74 | { |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 75 | ALOGW("ArmnnDriverImpl::prepareModel: Invalid callback passed to prepareModel"); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 76 | return V1_0::ErrorStatus::INVALID_ARGUMENT; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | if (!runtime) |
| 80 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 81 | return FailPrepareModel(V1_0::ErrorStatus::DEVICE_UNAVAILABLE, "Device unavailable", cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (!android::nn::validateModel(model)) |
| 85 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 86 | return FailPrepareModel(V1_0::ErrorStatus::INVALID_ARGUMENT, "Invalid model passed as input", cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | // Deliberately ignore any unsupported operations requested by the options - |
| 90 | // at this point we're being asked to prepare a model that we've already declared support for |
| 91 | // and the operation indices may be different to those in getSupportedOperations anyway. |
| 92 | set<unsigned int> unsupportedOperations; |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 93 | ModelToINetworkConverter<HalPolicy> modelConverter(options.GetBackends(), |
| 94 | model, |
| 95 | unsupportedOperations); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 96 | |
| 97 | if (modelConverter.GetConversionResult() != ConversionResult::Success) |
| 98 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 99 | FailPrepareModel(V1_0::ErrorStatus::GENERAL_FAILURE, "ModelToINetworkConverter failed", cb); |
| 100 | return V1_0::ErrorStatus::NONE; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Sadik Armagan | b302143 | 2021-01-13 15:56:51 +0000 | [diff] [blame] | 103 | // Serialize the network graph to a .armnn file if an output directory |
| 104 | // has been specified in the drivers' arguments. |
Sadik Armagan | 0a2dfab | 2021-10-06 16:41:44 +0100 | [diff] [blame] | 105 | std::vector<uint8_t> dataCacheData; |
Sadik Armagan | b302143 | 2021-01-13 15:56:51 +0000 | [diff] [blame] | 106 | auto serializedNetworkFileName = |
Sadik Armagan | 0a2dfab | 2021-10-06 16:41:44 +0100 | [diff] [blame] | 107 | SerializeNetwork(*modelConverter.GetINetwork(), |
| 108 | options.GetRequestInputsAndOutputsDumpDir(), |
| 109 | dataCacheData, |
| 110 | false); |
Sadik Armagan | b302143 | 2021-01-13 15:56:51 +0000 | [diff] [blame] | 111 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 112 | // Optimize the network |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 113 | armnn::IOptimizedNetworkPtr optNet(nullptr, nullptr); |
| 114 | armnn::OptimizerOptions OptOptions; |
| 115 | OptOptions.m_ReduceFp32ToFp16 = float32ToFloat16; |
| 116 | |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 117 | armnn::BackendOptions gpuAcc("GpuAcc", |
| 118 | { |
Sadik Armagan | f36e10b | 2021-01-11 16:34:01 +0000 | [diff] [blame] | 119 | { "FastMathEnabled", options.IsFastMathEnabled() }, |
| 120 | { "SaveCachedNetwork", options.SaveCachedNetwork() }, |
Finn Williams | f5ca16c | 2021-02-12 14:26:23 +0000 | [diff] [blame] | 121 | { "CachedNetworkFilePath", options.GetCachedNetworkFilePath() }, |
| 122 | { "MLGOTuningFilePath", options.GetClMLGOTunedParametersFile() } |
| 123 | |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 124 | }); |
Finn Williams | f5ca16c | 2021-02-12 14:26:23 +0000 | [diff] [blame] | 125 | |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 126 | armnn::BackendOptions cpuAcc("CpuAcc", |
| 127 | { |
Matthew Sloyan | cd639c9 | 2021-02-11 16:57:38 +0000 | [diff] [blame] | 128 | { "FastMathEnabled", options.IsFastMathEnabled() }, |
| 129 | { "NumberOfThreads", options.GetNumberOfThreads() } |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 130 | }); |
| 131 | OptOptions.m_ModelOptions.push_back(gpuAcc); |
| 132 | OptOptions.m_ModelOptions.push_back(cpuAcc); |
| 133 | |
jimfly01 | 07dedda | 2018-10-09 12:29:41 +0100 | [diff] [blame] | 134 | std::vector<std::string> errMessages; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 135 | try |
| 136 | { |
| 137 | optNet = armnn::Optimize(*modelConverter.GetINetwork(), |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 138 | options.GetBackends(), |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 139 | runtime->GetDeviceSpec(), |
jimfly01 | 07dedda | 2018-10-09 12:29:41 +0100 | [diff] [blame] | 140 | OptOptions, |
| 141 | errMessages); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 142 | } |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 143 | catch (std::exception &e) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 144 | { |
| 145 | stringstream message; |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 146 | message << "Exception (" << e.what() << ") caught from optimize."; |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 147 | FailPrepareModel(V1_0::ErrorStatus::GENERAL_FAILURE, message.str(), cb); |
| 148 | return V1_0::ErrorStatus::NONE; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | // Check that the optimized network is valid. |
| 152 | if (!optNet) |
| 153 | { |
jimfly01 | 07dedda | 2018-10-09 12:29:41 +0100 | [diff] [blame] | 154 | stringstream message; |
Matteo Martincigh | 8d50f8f | 2018-10-25 15:39:33 +0100 | [diff] [blame] | 155 | message << "Invalid optimized network"; |
| 156 | for (const string& msg : errMessages) |
| 157 | { |
jimfly01 | 07dedda | 2018-10-09 12:29:41 +0100 | [diff] [blame] | 158 | message << "\n" << msg; |
| 159 | } |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 160 | FailPrepareModel(V1_0::ErrorStatus::GENERAL_FAILURE, message.str(), cb); |
| 161 | return V1_0::ErrorStatus::NONE; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // Export the optimized network graph to a dot file if an output dump directory |
| 165 | // has been specified in the drivers' arguments. |
Jim Flynn | 829ad30 | 2019-12-13 14:43:24 +0000 | [diff] [blame] | 166 | std::string dotGraphFileName = ExportNetworkGraphToDotFile(*optNet, options.GetRequestInputsAndOutputsDumpDir()); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 167 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 168 | // Load it into the runtime. |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 169 | armnn::NetworkId netId = 0; |
Finn Williams | d8fb540 | 2021-05-19 20:52:00 +0100 | [diff] [blame] | 170 | std::string msg; |
| 171 | armnn::INetworkProperties networkProperties(options.isAsyncModelExecutionEnabled(), |
| 172 | armnn::MemorySource::Undefined, |
Finn Williams | ca3a3e0 | 2021-06-11 15:04:02 +0100 | [diff] [blame] | 173 | armnn::MemorySource::Undefined); |
Finn Williams | d8fb540 | 2021-05-19 20:52:00 +0100 | [diff] [blame] | 174 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 175 | try |
| 176 | { |
Finn Williams | d8fb540 | 2021-05-19 20:52:00 +0100 | [diff] [blame] | 177 | if (runtime->LoadNetwork(netId, move(optNet), msg, networkProperties) != armnn::Status::Success) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 178 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 179 | return FailPrepareModel(V1_0::ErrorStatus::GENERAL_FAILURE, "Network could not be loaded", cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 180 | } |
| 181 | } |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 182 | catch (std::exception& e) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 183 | { |
| 184 | stringstream message; |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 185 | message << "Exception (" << e.what()<< ") caught from LoadNetwork."; |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 186 | FailPrepareModel(V1_0::ErrorStatus::GENERAL_FAILURE, message.str(), cb); |
| 187 | return V1_0::ErrorStatus::NONE; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Sadik Armagan | b302143 | 2021-01-13 15:56:51 +0000 | [diff] [blame] | 190 | // Now that we have a networkId for the graph rename the exported files to use it |
| 191 | // so that we can associate the graph file and the input/output tensor exported files |
| 192 | RenameExportedFiles(serializedNetworkFileName, |
| 193 | dotGraphFileName, |
| 194 | options.GetRequestInputsAndOutputsDumpDir(), |
| 195 | netId); |
Jim Flynn | 829ad30 | 2019-12-13 14:43:24 +0000 | [diff] [blame] | 196 | |
Kevin May | d5e9465 | 2019-11-07 14:02:14 +0000 | [diff] [blame] | 197 | sp<ArmnnPreparedModel<HalPolicy>> preparedModel( |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 198 | new ArmnnPreparedModel<HalPolicy>( |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 199 | netId, |
| 200 | runtime.get(), |
| 201 | model, |
| 202 | options.GetRequestInputsAndOutputsDumpDir(), |
Finn Williams | d8fb540 | 2021-05-19 20:52:00 +0100 | [diff] [blame] | 203 | options.IsGpuProfilingEnabled(), |
Finn Williams | ca3a3e0 | 2021-06-11 15:04:02 +0100 | [diff] [blame] | 204 | options.isAsyncModelExecutionEnabled(), |
Narumol Prangnawarat | 558a1d4 | 2022-02-07 13:12:24 +0000 | [diff] [blame^] | 205 | options.getNoOfArmnnThreads(), |
| 206 | options.isImportEnabled(), |
| 207 | options.isExportEnabled())); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 208 | |
Narumol Prangnawarat | 558a1d4 | 2022-02-07 13:12:24 +0000 | [diff] [blame^] | 209 | if (std::find(options.GetBackends().begin(), |
| 210 | options.GetBackends().end(), |
| 211 | armnn::Compute::GpuAcc) != options.GetBackends().end()) |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 212 | { |
Narumol Prangnawarat | 558a1d4 | 2022-02-07 13:12:24 +0000 | [diff] [blame^] | 213 | // Run a single 'dummy' inference of the model. This means that CL kernels will get compiled (and tuned if |
| 214 | // this is enabled) before the first 'real' inference which removes the overhead of the first inference. |
| 215 | if (!preparedModel->ExecuteWithDummyInputs()) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 216 | { |
Narumol Prangnawarat | 558a1d4 | 2022-02-07 13:12:24 +0000 | [diff] [blame^] | 217 | return FailPrepareModel(V1_0::ErrorStatus::GENERAL_FAILURE, "Network could not be executed", cb); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 218 | } |
Narumol Prangnawarat | 558a1d4 | 2022-02-07 13:12:24 +0000 | [diff] [blame^] | 219 | |
| 220 | if (clTunedParameters && |
| 221 | options.GetClTunedParametersMode() == armnn::IGpuAccTunedParameters::Mode::UpdateTunedParameters) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 222 | { |
Narumol Prangnawarat | 558a1d4 | 2022-02-07 13:12:24 +0000 | [diff] [blame^] | 223 | // Now that we've done one inference the CL kernel parameters will have been tuned, so save the updated file |
| 224 | try |
| 225 | { |
| 226 | clTunedParameters->Save(options.GetClTunedParametersFile().c_str()); |
| 227 | } |
| 228 | catch (std::exception& error) |
| 229 | { |
| 230 | ALOGE("ArmnnDriverImpl::prepareModel: Failed to save CL tuned parameters file '%s': %s", |
| 231 | options.GetClTunedParametersFile().c_str(), error.what()); |
| 232 | } |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 233 | } |
| 234 | } |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 235 | NotifyCallbackAndCheck(cb, V1_0::ErrorStatus::NONE, preparedModel); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 236 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 237 | return V1_0::ErrorStatus::NONE; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 238 | } |
| 239 | |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 240 | template<typename HalPolicy> |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 241 | Return<void> ArmnnDriverImpl<HalPolicy>::getSupportedOperations(const armnn::IRuntimePtr& runtime, |
| 242 | const DriverOptions& options, |
| 243 | const HalModel& model, |
| 244 | HalGetSupportedOperations_cb cb) |
| 245 | { |
Jim Flynn | 829ad30 | 2019-12-13 14:43:24 +0000 | [diff] [blame] | 246 | std::stringstream ss; |
| 247 | ss << "ArmnnDriverImpl::getSupportedOperations()"; |
| 248 | std::string fileName; |
| 249 | std::string timestamp; |
| 250 | if (!options.GetRequestInputsAndOutputsDumpDir().empty()) |
| 251 | { |
Colm Donelan | 08d9a1c | 2020-09-09 17:56:55 +0100 | [diff] [blame] | 252 | ss << " : " |
| 253 | << options.GetRequestInputsAndOutputsDumpDir() |
| 254 | << "/" |
| 255 | << GetFileTimestamp() |
| 256 | << "_getSupportedOperations.txt"; |
Jim Flynn | 829ad30 | 2019-12-13 14:43:24 +0000 | [diff] [blame] | 257 | } |
| 258 | ALOGV(ss.str().c_str()); |
| 259 | |
| 260 | if (!options.GetRequestInputsAndOutputsDumpDir().empty()) |
| 261 | { |
| 262 | //dump the marker file |
| 263 | std::ofstream fileStream; |
| 264 | fileStream.open(fileName, std::ofstream::out | std::ofstream::trunc); |
| 265 | if (fileStream.good()) |
| 266 | { |
| 267 | fileStream << timestamp << std::endl; |
| 268 | } |
| 269 | fileStream.close(); |
| 270 | } |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 271 | |
| 272 | vector<bool> result; |
| 273 | |
| 274 | if (!runtime) |
| 275 | { |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 276 | cb(HalErrorStatus::DEVICE_UNAVAILABLE, result); |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 277 | return Void(); |
| 278 | } |
| 279 | |
| 280 | // Run general model validation, if this doesn't pass we shouldn't analyse the model anyway. |
| 281 | if (!android::nn::validateModel(model)) |
| 282 | { |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 283 | cb(HalErrorStatus::INVALID_ARGUMENT, result); |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 284 | return Void(); |
| 285 | } |
| 286 | |
| 287 | // Attempt to convert the model to an ArmNN input network (INetwork). |
| 288 | ModelToINetworkConverter<HalPolicy> modelConverter(options.GetBackends(), |
| 289 | model, |
| 290 | options.GetForcedUnsupportedOperations()); |
| 291 | |
| 292 | if (modelConverter.GetConversionResult() != ConversionResult::Success |
| 293 | && modelConverter.GetConversionResult() != ConversionResult::UnsupportedFeature) |
| 294 | { |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 295 | cb(HalErrorStatus::GENERAL_FAILURE, result); |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 296 | return Void(); |
| 297 | } |
| 298 | |
| 299 | // Check each operation if it was converted successfully and copy the flags |
| 300 | // into the result (vector<bool>) that we need to return to Android. |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 301 | result.reserve(getMainModel(model).operations.size()); |
| 302 | for (uint32_t operationIdx = 0; |
| 303 | operationIdx < getMainModel(model).operations.size(); |
| 304 | ++operationIdx) |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 305 | { |
| 306 | bool operationSupported = modelConverter.IsOperationSupported(operationIdx); |
| 307 | result.push_back(operationSupported); |
| 308 | } |
| 309 | |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 310 | cb(HalErrorStatus::NONE, result); |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 311 | return Void(); |
| 312 | } |
| 313 | |
| 314 | template<typename HalPolicy> |
Sadik Armagan | 188675f | 2021-02-12 17:16:42 +0000 | [diff] [blame] | 315 | Return<V1_0::DeviceStatus> ArmnnDriverImpl<HalPolicy>::getStatus() |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 316 | { |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 317 | ALOGV("ArmnnDriver::getStatus()"); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 318 | |
Sadik Armagan | 188675f | 2021-02-12 17:16:42 +0000 | [diff] [blame] | 319 | return V1_0::DeviceStatus::AVAILABLE; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 320 | } |
| 321 | |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 322 | /// |
| 323 | /// Class template specializations |
| 324 | /// |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 325 | |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 326 | template class ArmnnDriverImpl<hal_1_0::HalPolicy>; |
| 327 | |
Matteo Martincigh | 8b287c2 | 2018-09-07 09:25:10 +0100 | [diff] [blame] | 328 | #ifdef ARMNN_ANDROID_NN_V1_1 |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 329 | template class ArmnnDriverImpl<hal_1_1::HalPolicy>; |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 330 | #endif |
| 331 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 332 | #ifdef ARMNN_ANDROID_NN_V1_2 |
| 333 | template class ArmnnDriverImpl<hal_1_1::HalPolicy>; |
| 334 | template class ArmnnDriverImpl<hal_1_2::HalPolicy>; |
| 335 | #endif |
| 336 | |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 337 | #ifdef ARMNN_ANDROID_NN_V1_3 |
| 338 | template class ArmnnDriverImpl<hal_1_1::HalPolicy>; |
| 339 | template class ArmnnDriverImpl<hal_1_2::HalPolicy>; |
| 340 | template class ArmnnDriverImpl<hal_1_3::HalPolicy>; |
| 341 | #endif |
| 342 | |
Matteo Martincigh | 8d50f8f | 2018-10-25 15:39:33 +0100 | [diff] [blame] | 343 | } // namespace armnn_driver |