• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "CanonicalBurst.h"
18 
19 #include <DefaultExecution.h>
20 #include <android-base/logging.h>
21 #include <nnapi/IBurst.h>
22 #include <nnapi/IPreparedModel.h>
23 #include <nnapi/Result.h>
24 #include <nnapi/Types.h>
25 
26 #include <memory>
27 #include <optional>
28 #include <utility>
29 #include <vector>
30 
31 namespace android::nn::sample {
32 
Burst(std::shared_ptr<const PreparedModel> preparedModel)33 Burst::Burst(std::shared_ptr<const PreparedModel> preparedModel)
34     : kPreparedModel(std::move(preparedModel)) {
35     CHECK(kPreparedModel != nullptr);
36 }
37 
cacheMemory(const SharedMemory &) const38 Burst::OptionalCacheHold Burst::cacheMemory(const SharedMemory& /*memory*/) const {
39     return nullptr;
40 }
41 
execute(const Request & request,MeasureTiming measure,const nn::OptionalTimePoint & deadline,const nn::OptionalDuration & loopTimeoutDuration) const42 ExecutionResult<std::pair<std::vector<OutputShape>, Timing>> Burst::execute(
43         const Request& request, MeasureTiming measure, const nn::OptionalTimePoint& deadline,
44         const nn::OptionalDuration& loopTimeoutDuration) const {
45     return kPreparedModel->execute(request, measure, deadline, loopTimeoutDuration);
46 }
47 
createReusableExecution(const Request & request,MeasureTiming measure,const nn::OptionalDuration & loopTimeoutDuration) const48 GeneralResult<SharedExecution> Burst::createReusableExecution(
49         const Request& request, MeasureTiming measure,
50         const nn::OptionalDuration& loopTimeoutDuration) const {
51     return std::make_shared<DefaultExecution>(kPreparedModel, request, measure,
52                                               loopTimeoutDuration);
53 }
54 
55 }  // namespace android::nn::sample
56