blob: 384bd9b699a27256cc05d71108a75f21fdbea7a7 [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>
23#include <nnapi/Types.h>
24
25#include <memory>
26#include <optional>
27#include <utility>
28
29namespace android::hardware::neuralnetworks::V1_0::utils {
30
31nn::GeneralResult<std::shared_ptr<const Burst>> Burst::create(
32 nn::SharedPreparedModel preparedModel) {
33 if (preparedModel == nullptr) {
34 return NN_ERROR(nn::ErrorStatus::GENERAL_FAILURE)
35 << "V1_0::utils::Burst::create must have non-null preparedModel";
36 }
37
38 return std::make_shared<const Burst>(PrivateConstructorTag{}, std::move(preparedModel));
39}
40
41Burst::Burst(PrivateConstructorTag /*tag*/, nn::SharedPreparedModel preparedModel)
42 : kPreparedModel(std::move(preparedModel)) {
43 CHECK(kPreparedModel != nullptr);
44}
45
46Burst::OptionalCacheHold Burst::cacheMemory(const nn::Memory& /*memory*/) const {
47 return nullptr;
48}
49
50nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> Burst::execute(
51 const nn::Request& request, nn::MeasureTiming measure) const {
52 return kPreparedModel->execute(request, measure, {}, {});
53}
54
55} // namespace android::hardware::neuralnetworks::V1_0::utils