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 | 5f6bedb | 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> |
Michael Butler | 49d95e0 | 2021-10-15 18:52:52 -0700 | [diff] [blame] | 33 | #include <nnapi/hal/1.0/HandleError.h> |
Michael Butler | e8645c3 | 2021-10-15 18:42:32 -0700 | [diff] [blame] | 34 | #include <nnapi/hal/1.0/ProtectCallback.h> |
Michael Butler | 137ee99 | 2021-11-01 16:40:31 -0700 | [diff] [blame] | 35 | #include <nnapi/hal/1.2/Burst.h> |
| 36 | #include <nnapi/hal/1.2/BurstUtils.h> |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 37 | #include <nnapi/hal/1.2/Conversions.h> |
| 38 | #include <nnapi/hal/CommonUtils.h> |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 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) { |
Michael Butler | 49d95e0 | 2021-10-15 18:52:52 -0700 | [diff] [blame] | 53 | HANDLE_STATUS_HIDL(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) { |
Michael Butler | 49d95e0 | 2021-10-15 18:52:52 -0700 | [diff] [blame] | 60 | HANDLE_STATUS_HIDL(status) << "fenced execution failed with " << toString(status); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 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 | ff9a5a5 | 2021-10-15 16:23:20 -0700 | [diff] [blame] | 65 | resultSyncFence = NN_TRY(nn::SyncFence::create(std::move(sharedHandle))); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | if (callback == nullptr) { |
| 69 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) << "callback is null"; |
| 70 | } |
| 71 | |
| 72 | // Create callback which can be used to retrieve the execution error status and timings. |
| 73 | nn::ExecuteFencedInfoCallback resultCallback = |
| 74 | [callback]() -> nn::GeneralResult<std::pair<nn::Timing, nn::Timing>> { |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 75 | auto cb = hal::utils::CallbackValue(convertFencedExecutionCallbackResults); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 76 | |
| 77 | const auto ret = callback->getExecutionInfo(cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 78 | HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 79 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 80 | return cb.take(); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | return std::make_pair(std::move(resultSyncFence), std::move(resultCallback)); |
| 84 | } |
| 85 | |
| 86 | } // namespace |
| 87 | |
| 88 | nn::GeneralResult<std::shared_ptr<const PreparedModel>> PreparedModel::create( |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 89 | sp<V1_3::IPreparedModel> preparedModel, bool executeSynchronously) { |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 90 | if (preparedModel == nullptr) { |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 91 | 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] | 92 | } |
| 93 | |
| 94 | auto deathHandler = NN_TRY(hal::utils::DeathHandler::create(preparedModel)); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 95 | return std::make_shared<const PreparedModel>(PrivateConstructorTag{}, executeSynchronously, |
| 96 | std::move(preparedModel), std::move(deathHandler)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 99 | PreparedModel::PreparedModel(PrivateConstructorTag /*tag*/, bool executeSynchronously, |
| 100 | sp<V1_3::IPreparedModel> preparedModel, |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 101 | hal::utils::DeathHandler deathHandler) |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 102 | : kExecuteSynchronously(executeSynchronously), |
| 103 | kPreparedModel(std::move(preparedModel)), |
| 104 | kDeathHandler(std::move(deathHandler)) {} |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 105 | |
| 106 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> |
| 107 | PreparedModel::executeSynchronously(const Request& request, V1_2::MeasureTiming measure, |
| 108 | const OptionalTimePoint& deadline, |
| 109 | const OptionalTimeoutDuration& loopTimeoutDuration) const { |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 110 | auto cb = hal::utils::CallbackValue(executionCallback); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 111 | |
| 112 | const auto ret = kPreparedModel->executeSynchronously_1_3(request, measure, deadline, |
| 113 | loopTimeoutDuration, cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 114 | HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 115 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 116 | return cb.take(); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> |
| 120 | PreparedModel::executeAsynchronously(const Request& request, V1_2::MeasureTiming measure, |
| 121 | const OptionalTimePoint& deadline, |
| 122 | const OptionalTimeoutDuration& loopTimeoutDuration) const { |
| 123 | const auto cb = sp<ExecutionCallback>::make(); |
| 124 | const auto scoped = kDeathHandler.protectCallback(cb.get()); |
| 125 | |
| 126 | const auto ret = |
| 127 | kPreparedModel->execute_1_3(request, measure, deadline, loopTimeoutDuration, cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 128 | const auto status = HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 129 | if (status != ErrorStatus::OUTPUT_INSUFFICIENT_SIZE) { |
Michael Butler | 49d95e0 | 2021-10-15 18:52:52 -0700 | [diff] [blame] | 130 | HANDLE_STATUS_HIDL(status) << "execution failed with " << toString(status); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | return cb->get(); |
| 134 | } |
| 135 | |
| 136 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> PreparedModel::execute( |
| 137 | const nn::Request& request, nn::MeasureTiming measure, |
Miao Wang | b5c8a82 | 2021-10-26 20:03:05 +0000 | [diff] [blame^] | 138 | const nn::OptionalTimePoint& deadline, const nn::OptionalDuration& loopTimeoutDuration, |
| 139 | const std::vector<nn::TokenValuePair>& /*hints*/, |
| 140 | const std::vector<nn::ExtensionNameAndPrefix>& /*extensionNameToPrefix*/) 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 | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 143 | hal::utils::RequestRelocation relocation; |
Michael Butler | ff9a5a5 | 2021-10-15 16:23:20 -0700 | [diff] [blame] | 144 | const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared( |
| 145 | &request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding, |
| 146 | &maybeRequestInShared, &relocation)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 147 | |
Michael Butler | ff9a5a5 | 2021-10-15 16:23:20 -0700 | [diff] [blame] | 148 | const auto hidlRequest = NN_TRY(convert(requestInShared)); |
| 149 | const auto hidlMeasure = NN_TRY(convert(measure)); |
| 150 | const auto hidlDeadline = NN_TRY(convert(deadline)); |
| 151 | const auto hidlLoopTimeoutDuration = NN_TRY(convert(loopTimeoutDuration)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 152 | |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 153 | return executeInternal(hidlRequest, hidlMeasure, hidlDeadline, hidlLoopTimeoutDuration, |
| 154 | relocation); |
| 155 | } |
| 156 | |
| 157 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> |
| 158 | PreparedModel::executeInternal(const Request& request, V1_2::MeasureTiming measure, |
| 159 | const OptionalTimePoint& deadline, |
| 160 | const OptionalTimeoutDuration& loopTimeoutDuration, |
| 161 | const hal::utils::RequestRelocation& relocation) const { |
| 162 | if (relocation.input) { |
| 163 | relocation.input->flush(); |
| 164 | } |
| 165 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 166 | auto result = kExecuteSynchronously |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 167 | ? executeSynchronously(request, measure, deadline, loopTimeoutDuration) |
| 168 | : executeAsynchronously(request, measure, deadline, loopTimeoutDuration); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 169 | auto [outputShapes, timing] = NN_TRY(std::move(result)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 170 | |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 171 | if (relocation.output) { |
| 172 | relocation.output->flush(); |
| 173 | } |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 174 | return std::make_pair(std::move(outputShapes), timing); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> |
Miao Wang | b5c8a82 | 2021-10-26 20:03:05 +0000 | [diff] [blame^] | 178 | PreparedModel::executeFenced( |
| 179 | const nn::Request& request, const std::vector<nn::SyncFence>& waitFor, |
| 180 | nn::MeasureTiming measure, const nn::OptionalTimePoint& deadline, |
| 181 | const nn::OptionalDuration& loopTimeoutDuration, |
| 182 | const nn::OptionalDuration& timeoutDurationAfterFence, |
| 183 | const std::vector<nn::TokenValuePair>& /*hints*/, |
| 184 | const std::vector<nn::ExtensionNameAndPrefix>& /*extensionNameToPrefix*/) const { |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 185 | // Ensure that request is ready for IPC. |
| 186 | std::optional<nn::Request> maybeRequestInShared; |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 187 | hal::utils::RequestRelocation relocation; |
| 188 | const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared( |
Xusong Wang | e3d0dad | 2021-05-07 14:13:22 -0700 | [diff] [blame] | 189 | &request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding, |
| 190 | &maybeRequestInShared, &relocation)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 191 | |
| 192 | const auto hidlRequest = NN_TRY(convert(requestInShared)); |
Michael Butler | 1596582 | 2021-10-14 23:45:11 -0700 | [diff] [blame] | 193 | const auto hidlWaitFor = NN_TRY(convertSyncFences(waitFor)); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 194 | const auto hidlMeasure = NN_TRY(convert(measure)); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 195 | const auto hidlDeadline = NN_TRY(convert(deadline)); |
| 196 | const auto hidlLoopTimeoutDuration = NN_TRY(convert(loopTimeoutDuration)); |
| 197 | const auto hidlTimeoutDurationAfterFence = NN_TRY(convert(timeoutDurationAfterFence)); |
| 198 | |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 199 | return executeFencedInternal(hidlRequest, hidlWaitFor, hidlMeasure, hidlDeadline, |
| 200 | hidlLoopTimeoutDuration, hidlTimeoutDurationAfterFence, |
| 201 | relocation); |
| 202 | } |
| 203 | |
| 204 | nn::GeneralResult<std::pair<nn::SyncFence, nn::ExecuteFencedInfoCallback>> |
| 205 | PreparedModel::executeFencedInternal(const Request& request, const hidl_vec<hidl_handle>& waitFor, |
| 206 | V1_2::MeasureTiming measure, const OptionalTimePoint& deadline, |
| 207 | const OptionalTimeoutDuration& loopTimeoutDuration, |
| 208 | const OptionalTimeoutDuration& timeoutDurationAfterFence, |
| 209 | const hal::utils::RequestRelocation& relocation) const { |
| 210 | if (relocation.input) { |
| 211 | relocation.input->flush(); |
| 212 | } |
| 213 | |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 214 | auto cb = hal::utils::CallbackValue(fencedExecutionCallback); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 215 | |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 216 | const auto ret = |
| 217 | kPreparedModel->executeFenced(request, waitFor, measure, deadline, loopTimeoutDuration, |
| 218 | timeoutDurationAfterFence, cb); |
Michael Butler | cca3e20 | 2020-11-22 20:25:34 -0800 | [diff] [blame] | 219 | HANDLE_TRANSPORT_FAILURE(ret); |
Michael Butler | 7fd03c2 | 2020-12-06 21:50:59 -0800 | [diff] [blame] | 220 | auto [syncFence, callback] = NN_TRY(cb.take()); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 221 | |
| 222 | // If executeFenced required the request memory to be moved into shared memory, block here until |
| 223 | // the fenced execution has completed and flush the memory back. |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 224 | if (relocation.output) { |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 225 | const auto state = syncFence.syncWait({}); |
| 226 | if (state != nn::SyncFence::FenceState::SIGNALED) { |
| 227 | return NN_ERROR() << "syncWait failed with " << state; |
| 228 | } |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 229 | relocation.output->flush(); |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | return std::make_pair(std::move(syncFence), std::move(callback)); |
| 233 | } |
| 234 | |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 235 | nn::GeneralResult<nn::SharedExecution> PreparedModel::createReusableExecution( |
| 236 | const nn::Request& request, nn::MeasureTiming measure, |
Miao Wang | b5c8a82 | 2021-10-26 20:03:05 +0000 | [diff] [blame^] | 237 | const nn::OptionalDuration& loopTimeoutDuration, |
| 238 | const std::vector<nn::TokenValuePair>& /*hints*/, |
| 239 | const std::vector<nn::ExtensionNameAndPrefix>& /*extensionNameToPrefix*/) const { |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 240 | // Ensure that request is ready for IPC. |
| 241 | std::optional<nn::Request> maybeRequestInShared; |
| 242 | hal::utils::RequestRelocation relocation; |
| 243 | const nn::Request& requestInShared = NN_TRY(hal::utils::convertRequestFromPointerToShared( |
Xusong Wang | e3d0dad | 2021-05-07 14:13:22 -0700 | [diff] [blame] | 244 | &request, nn::kDefaultRequestMemoryAlignment, nn::kMinMemoryPadding, |
| 245 | &maybeRequestInShared, &relocation)); |
Xusong Wang | 5f6bedb | 2021-03-03 16:20:37 -0800 | [diff] [blame] | 246 | |
| 247 | auto hidlRequest = NN_TRY(convert(requestInShared)); |
| 248 | auto hidlMeasure = NN_TRY(convert(measure)); |
| 249 | auto hidlLoopTimeoutDuration = NN_TRY(convert(loopTimeoutDuration)); |
| 250 | return Execution::create(shared_from_this(), std::move(hidlRequest), std::move(relocation), |
| 251 | hidlMeasure, std::move(hidlLoopTimeoutDuration)); |
| 252 | } |
| 253 | |
Michael Butler | 2a8b679 | 2020-12-18 20:31:14 -0800 | [diff] [blame] | 254 | nn::GeneralResult<nn::SharedBurst> PreparedModel::configureExecutionBurst() const { |
Michael Butler | 76e491f | 2020-12-19 01:55:32 -0800 | [diff] [blame] | 255 | const auto pollingTimeWindow = V1_2::utils::getBurstControllerPollingTimeWindow(); |
Michael Butler | 137ee99 | 2021-11-01 16:40:31 -0700 | [diff] [blame] | 256 | return V1_2::utils::Burst::create(shared_from_this(), kPreparedModel, pollingTimeWindow); |
Michael Butler | 2a8b679 | 2020-12-18 20:31:14 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Michael Butler | 4b276a7 | 2020-08-06 23:22:35 -0700 | [diff] [blame] | 259 | std::any PreparedModel::getUnderlyingResource() const { |
| 260 | sp<V1_3::IPreparedModel> resource = kPreparedModel; |
| 261 | return resource; |
| 262 | } |
| 263 | |
| 264 | } // namespace android::hardware::neuralnetworks::V1_3::utils |