Michael Butler | 9533151 | 2020-12-18 20:53:55 -0800 | [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 "Burst.h" |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <nnapi/IBurst.h> |
| 21 | #include <nnapi/IPreparedModel.h> |
| 22 | #include <nnapi/Result.h> |
Michael Butler | 8414a6e | 2021-03-10 18:41:05 -0800 | [diff] [blame] | 23 | #include <nnapi/TypeUtils.h> |
Michael Butler | 9533151 | 2020-12-18 20:53:55 -0800 | [diff] [blame] | 24 | #include <nnapi/Types.h> |
| 25 | |
| 26 | #include <memory> |
| 27 | #include <optional> |
| 28 | #include <utility> |
| 29 | |
| 30 | namespace android::hardware::neuralnetworks::V1_0::utils { |
| 31 | |
| 32 | nn::GeneralResult<std::shared_ptr<const Burst>> Burst::create( |
| 33 | nn::SharedPreparedModel preparedModel) { |
| 34 | if (preparedModel == nullptr) { |
| 35 | return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE) |
| 36 | << "V1_0::utils::Burst::create must have non-null preparedModel"; |
| 37 | } |
| 38 | |
| 39 | return std::make_shared<const Burst>(PrivateConstructorTag{}, std::move(preparedModel)); |
| 40 | } |
| 41 | |
| 42 | Burst::Burst(PrivateConstructorTag /*tag*/, nn::SharedPreparedModel preparedModel) |
| 43 | : kPreparedModel(std::move(preparedModel)) { |
| 44 | CHECK(kPreparedModel != nullptr); |
| 45 | } |
| 46 | |
Michael Butler | fadeb8a | 2021-02-07 00:11:13 -0800 | [diff] [blame] | 47 | Burst::OptionalCacheHold Burst::cacheMemory(const nn::SharedMemory& /*memory*/) const { |
Michael Butler | 9533151 | 2020-12-18 20:53:55 -0800 | [diff] [blame] | 48 | return nullptr; |
| 49 | } |
| 50 | |
| 51 | nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Burst::execute( |
Michael Butler | 8414a6e | 2021-03-10 18:41:05 -0800 | [diff] [blame] | 52 | const nn::Request& request, nn::MeasureTiming measure, |
| 53 | const nn::OptionalTimePoint& deadline, |
| 54 | const nn::OptionalDuration& loopTimeoutDuration) const { |
| 55 | return kPreparedModel->execute(request, measure, deadline, loopTimeoutDuration); |
Michael Butler | 9533151 | 2020-12-18 20:53:55 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } // namespace android::hardware::neuralnetworks::V1_0::utils |