Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "PreparedModel.h" |
| 18 | |
| 19 | #include "Callbacks.h" |
| 20 | #include "Conversions.h" |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 21 | #include "Execution.h" |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 22 | #include "Utils.h" |
| 23 | |
| 24 | #include <android/hardware/neuralnetworks/1.0/types.h> |
| 25 | #include <android/hardware/neuralnetworks/1.1/types.h> |
| 26 | #include <android/hardware/neuralnetworks/1.2/types.h> |
| 27 | #include <android/hardware/neuralnetworks/1.3/IPreparedModel.h> |
| 28 | #include <android/hardware/neuralnetworks/1.3/types.h> |
| 29 | #include <nnapi/IPreparedModel.h> |
| 30 | #include <nnapi/Result.h> |
Michael Butler | 6547b2a | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 31 | #include <nnapi/TypeUtils.h> |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 32 | #include <nnapi/Types.h> |
| 33 | #include <nnapi/hal/1.2/Conversions.h> |
Michael Butler | 76e491f | 2020-12-19 01:55:32 -0800 | [diff] [blame] | 34 | #include <nnapi/hal/1.2/ExecutionBurstController.h> |
| 35 | #include <nnapi/hal/1.2/ExecutionBurstUtils.h> |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 36 | #include <nnapi/hal/CommonUtils.h> |
| 37 | #include <nnapi/hal/HandleError.h> |
| 38 | #include <nnapi/hal/ProtectCallback.h> |
| 39 | |
| 40 | #include <memory> |
| 41 | #include <tuple> |
| 42 | #include <utility> |
| 43 | #include <vector> |
| 44 | |
Michael Butler | aad934b | 2020-12-13 23:06:06 -0800 | [diff] [blame] | 45 | // See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface |
| 46 | // lifetimes across processes and for protecting asynchronous calls across HIDL. |
| 47 | |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 48 | namespace android::hardware::neuralnetworks::V1_3::utils { |
| 49 | namespace { |
| 50 | |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 51 | nn::GeneralResult<std::pair<nn::Timing, nn::Timing>> convertFencedExecutionCallbackResults( |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 52 | ErrorStatus status, const V1_2::Timing& timingLaunched, const V1_2::Timing& timingFenced) { |
| 53 | HANDLE_HAL_STATUS(status) << "fenced execution callback info failed with " << toString(status); |
Michael Butler | 6547b2a | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 54 | return std::make_pair(NN_TRY(nn::convert(timingLaunched)), NN_TRY(nn::convert(timingFenced))); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 57 | nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> fencedExecutionCallback( |
| 58 | ErrorStatus status, const hidl_handle& syncFence, |
| 59 | const sp<IFencedExecutionCallback>& callback) { |
| 60 | HANDLE_HAL_STATUS(status) << "fenced execution failed with " << toString(status); |
| 61 | |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 62 | auto resultSyncFence = nn::SyncFence::createAsSignaled(); |
| 63 | if (syncFence.getNativeHandle() != nullptr) { |
Michael Butler | 6547b2a | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 64 | auto sharedHandle = NN_TRY(nn::convert(syncFence)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 65 | resultSyncFence = NN_TRY(hal::utils::makeGeneralFailure( |
Michael Butler | 6547b2a | 2020-11-22 19:36:30 -0800 | [diff] [blame] | 66 | nn::SyncFence::create(std::move(sharedHandle)), nn::ErrorStatus::GENERAL_FAILURE)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | if (callback == nullptr) { |
| 70 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) << "callback is null"; |
| 71 | } |
| 72 | |
| 73 | // Create callback which can be used to retrieve the execution error status and timings. |
| 74 | nn::ExecuteFencedInfoCallback resultCallback = |
| 75 | [callback]() -> nn::GeneralResult<std::pair<nn::Timing, nn::Timing>> { |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 76 | auto cb = hal::utils::CallbackValue(convertFencedExecutionCallbackResults); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 77 | |
| 78 | const auto ret = callback->getExecutionInfo(cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 79 | HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 80 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 81 | return cb.take(); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | return std::make_pair(std::move(resultSyncFence), std::move(resultCallback)); |
| 85 | } |
| 86 | |
| 87 | } // namespace |
| 88 | |
| 89 | nn::GeneralResult<std::shared_ptr<const PreparedModel>> PreparedModel::create( |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 90 | sp<V1_3::IPreparedModel> preparedModel, bool executeSynchronously) { |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 91 | if (preparedModel == nullptr) { |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 92 | return NN_ERROR() << "V1_3::utils::PreparedModel::create must have non-null preparedModel"; |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | auto deathHandler = NN_TRY(hal::utils::DeathHandler::create(preparedModel)); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 96 | return std::make_shared<const PreparedModel>(PrivateConstructorTag{}, executeSynchronously, |
| 97 | std::move(preparedModel), std::move(deathHandler)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 100 | PreparedModel::PreparedModel(PrivateConstructorTag /*tag*/, bool executeSynchronously, |
| 101 | sp<V1_3::IPreparedModel> preparedModel, |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 102 | hal::utils::DeathHandler deathHandler) |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 103 | : kExecuteSynchronously(executeSynchronously), |
| 104 | kPreparedModel(std::move(preparedModel)), |
| 105 | kDeathHandler(std::move(deathHandler)) {} |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 106 | |
| 107 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> |
| 108 | PreparedModel::executeSynchronously(const Request& request, V1_2::MeasureTiming measure, |
| 109 | const OptionalTimePoint& deadline, |
| 110 | const OptionalTimeoutDuration& loopTimeoutDuration) const { |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 111 | auto cb = hal::utils::CallbackValue(executionCallback); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 112 | |
| 113 | const auto ret = kPreparedModel->executeSynchronously_1_3(request, measure, deadline, |
| 114 | loopTimeoutDuration, cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 115 | HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 116 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 117 | return cb.take(); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> |
| 121 | PreparedModel::executeAsynchronously(const Request& request, V1_2::MeasureTiming measure, |
| 122 | const OptionalTimePoint& deadline, |
| 123 | const OptionalTimeoutDuration& loopTimeoutDuration) const { |
| 124 | const auto cb = sp<ExecutionCallback>::make(); |
| 125 | const auto scoped = kDeathHandler.protectCallback(cb.get()); |
| 126 | |
| 127 | const auto ret = |
| 128 | kPreparedModel->execute_1_3(request, measure, deadline, loopTimeoutDuration, cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 129 | const auto status = HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 130 | if (status != ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) { |
| 131 | HANDLE_HAL_STATUS(status) << "execution failed with " << toString(status); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | return cb->get(); |
| 135 | } |
| 136 | |
| 137 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> PreparedModel::execute( |
| 138 | const nn::Request& request, nn::MeasureTiming measure, |
| 139 | const nn::OptionalTimePoint& deadline, |
Michael Butler | 4024d8f | 2020-12-04 17:38:20 -0800 | [diff] [blame] | 140 | const nn::OptionalDuration& loopTimeoutDuration) const { |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 141 | // Ensure that request is ready for IPC. |
| 142 | std::optional<nn::Request> maybeRequestInShared; |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 143 | hal::utils::RequestRelocation relocation; |
| 144 | const nn::Request& requestInShared = |
| 145 | NN_TRY(hal::utils::makeExecutionFailure(hal::utils::convertRequestFromPointerToShared( |
Xusong Wang | 8bfa243 | 2021-05-07 14:13:22 -0700 | [diff] [blame^] | 146 | &request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding, |
| 147 | &maybeRequestInShared, &relocation))); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 148 | |
| 149 | const auto hidlRequest = NN_TRY(hal::utils::makeExecutionFailure(convert(requestInShared))); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 150 | const auto hidlMeasure = NN_TRY(hal::utils::makeExecutionFailure(convert(measure))); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 151 | const auto hidlDeadline = NN_TRY(hal::utils::makeExecutionFailure(convert(deadline))); |
| 152 | const auto hidlLoopTimeoutDuration = |
| 153 | NN_TRY(hal::utils::makeExecutionFailure(convert(loopTimeoutDuration))); |
| 154 | |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 155 | return executeInternal(hidlRequest, hidlMeasure, hidlDeadline, hidlLoopTimeoutDuration, |
| 156 | relocation); |
| 157 | } |
| 158 | |
| 159 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> |
| 160 | PreparedModel::executeInternal(const Request& request, V1_2::MeasureTiming measure, |
| 161 | const OptionalTimePoint& deadline, |
| 162 | const OptionalTimeoutDuration& loopTimeoutDuration, |
| 163 | const hal::utils::RequestRelocation& relocation) const { |
| 164 | if (relocation.input) { |
| 165 | relocation.input->flush(); |
| 166 | } |
| 167 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 168 | auto result = kExecuteSynchronously |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 169 | ? executeSynchronously(request, measure, deadline, loopTimeoutDuration) |
| 170 | : executeAsynchronously(request, measure, deadline, loopTimeoutDuration); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 171 | auto [outputShapes, timing] = NN_TRY(std::move(result)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 172 | |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 173 | if (relocation.output) { |
| 174 | relocation.output->flush(); |
| 175 | } |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 176 | return std::make_pair(std::move(outputShapes), timing); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> |
| 180 | PreparedModel::executeFenced(const nn::Request& request, const std::vector<nn::SyncFence>& waitFor, |
| 181 | nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline, |
Michael Butler | 4024d8f | 2020-12-04 17:38:20 -0800 | [diff] [blame] | 182 | const nn::OptionalDuration& loopTimeoutDuration, |
| 183 | const nn::OptionalDuration& timeoutDurationAfterFence) const { |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 184 | // Ensure that request is ready for IPC. |
| 185 | std::optional<nn::Request> maybeRequestInShared; |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 186 | hal::utils::RequestRelocation relocation; |
| 187 | const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared( |
Xusong Wang | 8bfa243 | 2021-05-07 14:13:22 -0700 | [diff] [blame^] | 188 | &request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding, |
| 189 | &maybeRequestInShared, &relocation)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 190 | |
| 191 | const auto hidlRequest = NN_TRY(convert(requestInShared)); |
Slava Shklyaev | 49817a0 | 2020-10-27 18:44:01 +0000 | [diff] [blame] | 192 | const auto hidlWaitFor = NN_TRY(hal::utils::convertSyncFences(waitFor)); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 193 | const auto hidlMeasure = NN_TRY(convert(measure)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 194 | const auto hidlDeadline = NN_TRY(convert(deadline)); |
| 195 | const auto hidlLoopTimeoutDuration = NN_TRY(convert(loopTimeoutDuration)); |
| 196 | const auto hidlTimeoutDurationAfterFence = NN_TRY(convert(timeoutDurationAfterFence)); |
| 197 | |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 198 | return executeFencedInternal(hidlRequest, hidlWaitFor, hidlMeasure, hidlDeadline, |
| 199 | hidlLoopTimeoutDuration, hidlTimeoutDurationAfterFence, |
| 200 | relocation); |
| 201 | } |
| 202 | |
| 203 | nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> |
| 204 | PreparedModel::executeFencedInternal(const Request& request, const hidl_vec<hidl_handle>& waitFor, |
| 205 | V1_2::MeasureTiming measure, const OptionalTimePoint& deadline, |
| 206 | const OptionalTimeoutDuration& loopTimeoutDuration, |
| 207 | const OptionalTimeoutDuration& timeoutDurationAfterFence, |
| 208 | const hal::utils::RequestRelocation& relocation) const { |
| 209 | if (relocation.input) { |
| 210 | relocation.input->flush(); |
| 211 | } |
| 212 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 213 | auto cb = hal::utils::CallbackValue(fencedExecutionCallback); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 214 | |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 215 | const auto ret = |
| 216 | kPreparedModel->executeFenced(request, waitFor, measure, deadline, loopTimeoutDuration, |
| 217 | timeoutDurationAfterFence, cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 218 | HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 219 | auto [syncFence, callback] = NN_TRY(cb.take()); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 220 | |
| 221 | // If executeFenced required the request memory to be moved into shared memory, block here until |
| 222 | // the fenced execution has completed and flush the memory back. |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 223 | if (relocation.output) { |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 224 | const auto state = syncFence.syncWait({}); |
| 225 | if (state != nn::SyncFence::FenceState::SIGNALED) { |
| 226 | return NN_ERROR() << "syncWait failed with " << state; |
| 227 | } |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 228 | relocation.output->flush(); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | return std::make_pair(std::move(syncFence), std::move(callback)); |
| 232 | } |
| 233 | |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 234 | nn::GeneralResult<nn::SharedExecution> PreparedModel::createReusableExecution( |
| 235 | const nn::Request& request, nn::MeasureTiming measure, |
| 236 | const nn::OptionalDuration& loopTimeoutDuration) const { |
| 237 | // Ensure that request is ready for IPC. |
| 238 | std::optional<nn::Request> maybeRequestInShared; |
| 239 | hal::utils::RequestRelocation relocation; |
| 240 | const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared( |
Xusong Wang | 8bfa243 | 2021-05-07 14:13:22 -0700 | [diff] [blame^] | 241 | &request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding, |
| 242 | &maybeRequestInShared, &relocation)); |
Xusong Wang | 727a7b2 | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 243 | |
| 244 | auto hidlRequest = NN_TRY(convert(requestInShared)); |
| 245 | auto hidlMeasure = NN_TRY(convert(measure)); |
| 246 | auto hidlLoopTimeoutDuration = NN_TRY(convert(loopTimeoutDuration)); |
| 247 | return Execution::create(shared_from_this(), std::move(hidlRequest), std::move(relocation), |
| 248 | hidlMeasure, std::move(hidlLoopTimeoutDuration)); |
| 249 | } |
| 250 | |
Michael Butler | 2a8b679 | 2020-12-18 20:31:14 -0800 | [diff] [blame] | 251 | nn::GeneralResult<nn::SharedBurst> PreparedModel::configureExecutionBurst() const { |
Michael Butler | 76e491f | 2020-12-19 01:55:32 -0800 | [diff] [blame] | 252 | auto self = shared_from_this(); |
Michael Butler | 8414a6e | 2021-03-10 18:41:05 -0800 | [diff] [blame] | 253 | auto fallback = [preparedModel = std::move(self)]( |
| 254 | const nn::Request& request, nn::MeasureTiming measure, |
| 255 | const nn::OptionalTimePoint& deadline, |
| 256 | const nn::OptionalDuration& loopTimeoutDuration) |
Michael Butler | 76e491f | 2020-12-19 01:55:32 -0800 | [diff] [blame] | 257 | -> nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> { |
Michael Butler | 8414a6e | 2021-03-10 18:41:05 -0800 | [diff] [blame] | 258 | return preparedModel->execute(request, measure, deadline, loopTimeoutDuration); |
Michael Butler | 76e491f | 2020-12-19 01:55:32 -0800 | [diff] [blame] | 259 | }; |
| 260 | const auto pollingTimeWindow = V1_2::utils::getBurstControllerPollingTimeWindow(); |
Xusong Wang | ead6d37 | 2021-03-23 15:07:10 -0700 | [diff] [blame] | 261 | return V1_2::utils::ExecutionBurstController::create(shared_from_this(), kPreparedModel, |
Michael Butler | 76e491f | 2020-12-19 01:55:32 -0800 | [diff] [blame] | 262 | pollingTimeWindow); |
Michael Butler | 2a8b679 | 2020-12-18 20:31:14 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 265 | std::any PreparedModel::getUnderlyingResource() const { |
| 266 | sp<V1_3::IPreparedModel> resource = kPreparedModel; |
| 267 | return resource; |
| 268 | } |
| 269 | |
| 270 | } // namespace android::hardware::neuralnetworks::V1_3::utils |