• 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 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_PREPARED_MODEL_H
18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_PREPARED_MODEL_H
19 
20 #include <BufferTracker.h>
21 #include <CpuExecutor.h>
22 #include <nnapi/IExecution.h>
23 #include <nnapi/IPreparedModel.h>
24 #include <nnapi/Result.h>
25 #include <nnapi/Types.h>
26 
27 #include <memory>
28 #include <tuple>
29 #include <utility>
30 #include <vector>
31 
32 namespace android::nn::sample {
33 
34 class PreparedModel final : public IPreparedModel,
35                             public std::enable_shared_from_this<PreparedModel> {
36    public:
37     PreparedModel(Model model, ExecutionPreference preference, Priority priority,
38                   const IOperationResolver* operationResolver,
39                   std::shared_ptr<BufferTracker> bufferTracker,
40                   std::vector<RunTimePoolInfo> poolInfos);
41 
42     ExecutionResult<std::pair<std::vector<OutputShape>, Timing>> execute(
43             const Request& request, MeasureTiming measure, const OptionalTimePoint& deadline,
44             const OptionalDuration& loopTimeoutDuration) const override;
45 
46     GeneralResult<std::pair<SyncFence, ExecuteFencedInfoCallback>> executeFenced(
47             const Request& request, const std::vector<SyncFence>& waitFor, MeasureTiming measure,
48             const OptionalTimePoint& deadline, const OptionalDuration& loopTimeoutDuration,
49             const OptionalDuration& timeoutDurationAfterFence) const override;
50 
51     GeneralResult<nn::SharedExecution> createReusableExecution(
52             const Request& request, MeasureTiming measure,
53             const OptionalDuration& loopTimeoutDuration) const override;
54 
55     GeneralResult<SharedBurst> configureExecutionBurst() const override;
56 
57     std::any getUnderlyingResource() const override;
58 
59    private:
60     const Model kModel;
61     [[maybe_unused]] const ExecutionPreference kExecutionPreference;
62     [[maybe_unused]] const Priority kExecutionPriority;
63     const IOperationResolver& kOperationResolver;
64     const std::shared_ptr<BufferTracker> kBufferTracker;
65     const std::vector<RunTimePoolInfo> kPoolInfos;
66 };
67 
68 }  // namespace android::nn::sample
69 
70 #endif  // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_PREPARED_MODEL_H
71