blob: 128472110d002434a63237381b45a17f40240542 [file] [log] [blame]
Michael Butler95331512020-12-18 20:53:55 -08001/*
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 Butler8414a6e2021-03-10 18:41:05 -080023#include <nnapi/TypeUtils.h>
Michael Butler95331512020-12-18 20:53:55 -080024#include <nnapi/Types.h>
25
26#include <memory>
27#include <optional>
28#include <utility>
29
30namespace android::hardware::neuralnetworks::V1_0::utils {
31
32nn::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
42Burst::Burst(PrivateConstructorTag /*tag*/, nn::SharedPreparedModel preparedModel)
43 : kPreparedModel(std::move(preparedModel)) {
44 CHECK(kPreparedModel != nullptr);
45}
46
Michael Butlerfadeb8a2021-02-07 00:11:13 -080047Burst::OptionalCacheHold Burst::cacheMemory(const nn::SharedMemory& /*memory*/) const {
Michael Butler95331512020-12-18 20:53:55 -080048 return nullptr;
49}
50
51nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Burst::execute(
Michael Butler8414a6e2021-03-10 18:41:05 -080052 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 Butler95331512020-12-18 20:53:55 -080056}
57
Xusong Wangb2e80852021-03-23 15:07:10 -070058nn::GeneralResult<nn::SharedExecution> Burst::createReusableExecution(
59 const nn::Request& request, nn::MeasureTiming measure,
60 const nn::OptionalDuration& loopTimeoutDuration) const {
61 return kPreparedModel->createReusableExecution(request, measure, loopTimeoutDuration);
62}
63
Michael Butler95331512020-12-18 20:53:55 -080064} // namespace android::hardware::neuralnetworks::V1_0::utils